Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [discussion] Re-raise logger import warnings when not installed #1489

Closed
wants to merge 4 commits into from
Closed

[WIP] [discussion] Re-raise logger import warnings when not installed #1489

wants to merge 4 commits into from

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented Apr 14, 2020

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

What does this PR do?

When importing a logger this way
from pytorch_lightning.loggers.wandb import WandbLogger
an error message will be printed if the package is not installed.
However, if we import from the top level module, i.e.,
from pytorch_lightning.loggers import WandbLogger
the error message is discarded.
This PR fixes that.

Probably what is happening in #1487.

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@mergify mergify bot requested a review from a team April 14, 2020 17:12
Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we do not force a user to install all loggers, that is also the reason why we have extras not all loggers in requirements...

@Borda Borda added the won't fix This will not be worked on label Apr 14, 2020
@Borda Borda requested a review from a team April 14, 2020 17:32
@stale stale bot removed the won't fix This will not be worked on label Apr 14, 2020
@codecov
Copy link

codecov bot commented Apr 14, 2020

Codecov Report

Merging #1489 into master will decrease coverage by 0%.
The diff coverage is 0%.

@@          Coverage Diff           @@
##           master   #1489   +/-   ##
======================================
- Coverage      91%     91%   -0%     
======================================
  Files          67      67           
  Lines        3745    3747    +2     
======================================
  Hits         3403    3403           
- Misses        342     344    +2     

@awaelchli
Copy link
Contributor Author

ok I see, I thought these errors are only raised when the user imports it.
So is it not possible to tell the user that there is a missing package?

@awaelchli
Copy link
Contributor Author

awaelchli commented Apr 14, 2020

ok I understand now that my fix won't work, but my intention was simply to allow the custom error message to pass to the top level in case the user imports
from pytorch_lightning.loggers import WandbLogger
instead of
from pytorch_lightning.loggers.wandb import WandbLogger
I'm sure questions like this #1487 will be asked more.

@Borda
Copy link
Member

Borda commented Apr 14, 2020

I see your point and agree that we shall raise import error even when user explicitly imports logger from pytorch_lightning.loggers.__init__ just not sure how to avoids raising errors from other loggers which are not requested...

@awaelchli awaelchli marked this pull request as draft April 14, 2020 21:52
@awaelchli awaelchli changed the title Re-raise logger import warnings when not installed [WIP] [discussion] Re-raise logger import warnings when not installed Apr 14, 2020
@Borda Borda added discussion In a discussion stage feature Is an improvement or enhancement help wanted Open to be worked on labels Apr 14, 2020
@Borda Borda added this to the 0.7.4 milestone Apr 14, 2020
@Borda
Copy link
Member

Borda commented Apr 15, 2020

the actual error message is:

>>> from pytorch_lightning.loggers import NeptuneLogger
/usr/lib/python3/dist-packages/apport/report.py:13: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import fnmatch, glob, traceback, errno, sys, atexit, locale, imp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'NeptuneLogger' from 'pytorch_lightning.loggers' (/home/jb/.local/lib/python3.7/site-packages/pytorch_lightning/loggers/__init__.py)
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'NeptuneLogger' from 'pytorch_lightning.loggers' (/home/jb/.local/lib/python3.7/site-packages/pytorch_lightning/loggers/__init__.py)

@awaelchli
Copy link
Contributor Author

I think it is not possible. The only thing we could do is add a note to the documentation that the user needs to manually install the logger. Should I do this? Can directly add it to this PR #1484 . What do you think?

@Borda
Copy link
Member

Borda commented Apr 15, 2020

ok, pls add a note to the docs-logger PR and let's also keep this open for a while if we find another way to using loggers...

@Borda Borda modified the milestones: 0.7.4, 0.7.5 Apr 24, 2020
@Borda Borda modified the milestones: 0.7.6, 0.8.0, 0.7.7 May 12, 2020
@awaelchli
Copy link
Contributor Author

this is probably an unsolvable problem, let's close it @Borda ?

@justusschock
Copy link
Member

I think, what we could do here: have all imports to these packages locally inside the logger classes. This way we can normally import them and don't have to catch ImportErrors and the User still gets errors during instantiation (which would be fine I guess).

@justusschock
Copy link
Member

@awaelchli If you enable edit from contributors for your PR I can do it. Should be a rather quick fix :)

@awaelchli
Copy link
Contributor Author

It's already turned on but I think it won't work because here I was still using my own fork when I submitted the PR. Feel free to submit a fresh PR since I have not really changed anything here :)

@justusschock justusschock mentioned this pull request May 25, 2020
5 tasks
@awaelchli awaelchli closed this May 25, 2020
@awaelchli awaelchli deleted the bugfix/logger-install-warnings branch May 25, 2020 09:21
@Borda Borda modified the milestones: 0.7.7, 0.8.0 May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion In a discussion stage feature Is an improvement or enhancement help wanted Open to be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants