Logging #49

Merged
connorskees merged 4 commits from logging into master 5 years ago
connorskees commented 5 years ago (Migrated from github.com)
Owner

This is kinda what I was imagining as far as having a logging system.

Also, I was unable to run it on Windows 10 and WSL Ubuntu when the imports were prepended with '.' (from .tools.login import login). Not sure if this is an error on my part, though.

This is kinda what I was imagining as far as having a logging system. Also, I was unable to run it on Windows 10 and WSL Ubuntu when the imports were prepended with '.' (`from .tools.login import login`). Not sure if this is an error on my part, though.
weskerfoot commented 5 years ago (Migrated from github.com)
Owner

Thanks for figuring this out. The reason I used relative imports is so that calling the script directly (with python -m deletefb.deletefb) doesn't break, because Python thinks you're not in a package. I would be ok with not supporting calling the .py file directly if it makes it easier to support Windows though. I don't think there's any reason to not just use pip install --user to run the program.

I am curious why it didn't work for you on WSL. Is there something different about how Python resolves packages/modules on there?

Thanks for figuring this out. The reason I used relative imports is so that calling the script directly (with `python -m deletefb.deletefb`) doesn't break, because Python thinks you're not in a package. I would be ok with not supporting calling the .py file directly if it makes it easier to support Windows though. I don't think there's any reason to not just use `pip install --user` to run the program. I am curious why it didn't work for you on WSL. Is there something different about how Python resolves packages/modules on there?
weskerfoot commented 5 years ago (Migrated from github.com)
Owner

Could you just update the README to remove the bit here about python -m? https://github.com/weskerfoot/DeleteFB/blob/master/README.md#installation

I think if I'm going to support running it directly I'd rather have that in a separate section or something, or even a different README

Could you just update the README to remove the bit here about `python -m`? https://github.com/weskerfoot/DeleteFB/blob/master/README.md#installation I think if I'm going to support running it directly I'd rather have that in a separate section or something, or even a different README
connorskees commented 5 years ago (Migrated from github.com)
Poster
Owner

I was running it from the cloned directory just as >>> deletefb.py

Through Windows 10 prompt:

(base) C:\DeleteFB\deletefb>python -m deletefb.py
Traceback (most recent call last):
  File "C:\Users\Connor\Anaconda3\lib\runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "C:\Users\Connor\Anaconda3\lib\runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "C:\DeleteFB\deletefb\deletefb.py", line 9, in <module>
    from .tools.common import logger
ImportError: attempted relative import with no known parent package

And when not run with the -m flag:

(base) C:\DeleteFB\deletefb>python deletefb.py
Traceback (most recent call last):
  File "deletefb.py", line 9, in <module>
    from .tools.common import logger
ModuleNotFoundError: No module named '__main__.tools'; '__main__' is not a package

I'm not sure why (Python directory structures are so confusing to me), but on WSL:

connorskees /mnt/c/DeleteFB/deletefb > python -m deletefb.py
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 174, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.5/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/mnt/c/DeleteFB/deletefb/deletefb.py", line 9, in <module>
    from .tools.common import logger
SystemError: Parent module '' not loaded, cannot perform relative import
I was running it from the cloned directory just as `>>> deletefb.py` Through Windows 10 prompt: ``` (base) C:\DeleteFB\deletefb>python -m deletefb.py Traceback (most recent call last): File "C:\Users\Connor\Anaconda3\lib\runpy.py", line 183, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "C:\Users\Connor\Anaconda3\lib\runpy.py", line 109, in _get_module_details __import__(pkg_name) File "C:\DeleteFB\deletefb\deletefb.py", line 9, in <module> from .tools.common import logger ImportError: attempted relative import with no known parent package ``` And when not run with the -m flag: ``` (base) C:\DeleteFB\deletefb>python deletefb.py Traceback (most recent call last): File "deletefb.py", line 9, in <module> from .tools.common import logger ModuleNotFoundError: No module named '__main__.tools'; '__main__' is not a package ``` I'm not sure why (Python directory structures are so confusing to me), but on WSL: ``` connorskees /mnt/c/DeleteFB/deletefb > python -m deletefb.py Traceback (most recent call last): File "/usr/lib/python3.5/runpy.py", line 174, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "/usr/lib/python3.5/runpy.py", line 109, in _get_module_details __import__(pkg_name) File "/mnt/c/DeleteFB/deletefb/deletefb.py", line 9, in <module> from .tools.common import logger SystemError: Parent module '' not loaded, cannot perform relative import ```
weskerfoot commented 5 years ago (Migrated from github.com)
Owner

Oh, I think it was because python -m deletefb.py runs it as a module (which is fine), but the "package" is the directory deletefb, so it needs to somehow be running that inside a package, but it doesn't have a directory structure (which is how Python organizes packages obviously).

So you would get ImportError: attempted relative import with no known parent package when you just did python -m deletefb.py because it only knows about the module, but if you did python -m deletefb.deletefb it would have worked because it gets resolved to deletefb/deletefb.py (where the first part is the package and the second is the module).

That is probably just too confusing for people to understand, so I think it does make better sense your way. I just tested running python deletefb/deletefb.py directly and it seems to work, so let's keep it this way and update the docs I think.

Oh, I think it was because `python -m deletefb.py` runs it as a module (which is fine), but the "package" is the directory `deletefb`, so it needs to somehow be running that inside a package, but it doesn't have a directory structure (which is how Python organizes packages obviously). So you would get `ImportError: attempted relative import with no known parent package` when you just did `python -m deletefb.py` because it only knows about the module, but if you did `python -m deletefb.deletefb` it would have worked because it gets resolved to `deletefb/deletefb.py` (where the first part is the package and the second is the module). That is probably just too confusing for people to understand, so I think it does make better sense your way. I just tested running `python deletefb/deletefb.py` directly and it seems to work, so let's keep it this way and update the docs I think.
weskerfoot commented 5 years ago (Migrated from github.com)
Owner

Looks good, thanks!

Looks good, thanks!
weskerfoot commented 5 years ago (Migrated from github.com)
Owner

@ConnorSkees I switched it back to the relative imports because I was having issues getting it to work with the pip install --user . flow. I think it works fine if you do python -m deletefb.deletefb in the virtualenv and I'd rather use that as the method there than try to work around not having relative imports.

@ConnorSkees I switched it back to the relative imports because I was having issues getting it to work with the `pip install --user .` flow. I think it works fine if you do `python -m deletefb.deletefb` in the virtualenv and I'd rather use that as the method there than try to work around not having relative imports.
connorskees commented 5 years ago (Migrated from github.com)
Poster
Owner

@weskerfoot Yeah that sounds good to me. Something I hadn't considered, though, is using

try:
    from .tools.common import logger
    from .tools.login import login
    from .tools.wall import delete_posts
    from .tools.likes import unlike_pages
except ImportError:
    from tools.common import logger
    from tools.login import login
    from tools.wall import delete_posts
    from tools.likes import unlike_pages

in deletefb.py

and

try:
    from .deletefb import run_delete
except ImportError:
    from deletefb import run_delete

in __main__.py

which actually allows it to be run from the DeleteFB directory using all of python deletefb, python -m deletefb, and python -m deletefb.deletefb as well as deletefb.py from the deletefb directory

@weskerfoot Yeah that sounds good to me. Something I hadn't considered, though, is using ``` try: from .tools.common import logger from .tools.login import login from .tools.wall import delete_posts from .tools.likes import unlike_pages except ImportError: from tools.common import logger from tools.login import login from tools.wall import delete_posts from tools.likes import unlike_pages ``` in deletefb.py and ``` try: from .deletefb import run_delete except ImportError: from deletefb import run_delete ``` in \_\_main__.py which actually allows it to be run from the DeleteFB directory using all of `python deletefb`, `python -m deletefb`, and `python -m deletefb.deletefb` as well as `deletefb.py` from the deletefb directory
The pull request has been merged as 8befcfd3be.
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This pull request currently doesn't have any dependencies.

Loading…
There is no content yet.