From 89d3fa21f284f5e86a6bd2e26dfc315c60837f96 Mon Sep 17 00:00:00 2001 From: Luis Perez Date: Wed, 17 Mar 2021 11:22:04 -0700 Subject: [PATCH 1/3] unconditional import during type checking --- pytorch_lightning/__init__.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pytorch_lightning/__init__.py b/pytorch_lightning/__init__.py index 569078c994ba4..53ad369122c49 100644 --- a/pytorch_lightning/__init__.py +++ b/pytorch_lightning/__init__.py @@ -4,6 +4,7 @@ import os import sys import time +import typing _this_year = time.strftime("%Y") __version__ = '1.3.0dev' @@ -50,6 +51,7 @@ _PACKAGE_ROOT = os.path.dirname(__file__) _PROJECT_ROOT = os.path.dirname(_PACKAGE_ROOT) + try: # This variable is injected in the __builtins__ by the build # process. It used to enable importing subpackages of skimage when @@ -58,10 +60,16 @@ except NameError: __LIGHTNING_SETUP__: bool = False -if __LIGHTNING_SETUP__: # pragma: no-cover - sys.stdout.write(f'Partial import of `{__name__}` during the build process.\n') # pragma: no-cover - # We are not importing the rest of the lightning during the build process, as it may not be compiled yet -else: + +if typing.TYPE_CHECKING: + # Simplify the imports for the static type checker. + from pytorch_lightning import metrics + from pytorch_lightning.callbacks import Callback + from pytorch_lightning.core import LightningDataModule, LightningModule + from pytorch_lightning.trainer import Trainer + from pytorch_lightning.utilities.seed import seed_everything + +elif not __LIGHTNING_SETUP__: # pragma: no-cover from pytorch_lightning import metrics from pytorch_lightning.callbacks import Callback from pytorch_lightning.core import LightningDataModule, LightningModule @@ -76,6 +84,10 @@ 'seed_everything', 'metrics', ] +else: + sys.stdout.write(f'Partial import of `{__name__}` during the build process.\n') # pragma: no-cover + # We are not importing the rest of the lightning during the build process, as it may not be compiled yet + # for compatibility with namespace packages __import__('pkg_resources').declare_namespace(__name__) From b0d57b592c91523cc5f4a3a363a24f1827f74614 Mon Sep 17 00:00:00 2001 From: Luis Perez Date: Wed, 17 Mar 2021 11:29:08 -0700 Subject: [PATCH 2/3] fix pep8 --- pytorch_lightning/__init__.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/pytorch_lightning/__init__.py b/pytorch_lightning/__init__.py index 53ad369122c49..4c87873d8defb 100644 --- a/pytorch_lightning/__init__.py +++ b/pytorch_lightning/__init__.py @@ -7,12 +7,12 @@ import typing _this_year = time.strftime("%Y") -__version__ = '1.3.0dev' -__author__ = 'William Falcon et al.' -__author_email__ = 'waf2107@columbia.edu' -__license__ = 'Apache-2.0' -__copyright__ = f'Copyright (c) 2018-{_this_year}, {__author__}.' -__homepage__ = 'https://github.com/PyTorchLightning/pytorch-lightning' +__version__ = "1.3.0dev" +__author__ = "William Falcon et al." +__author_email__ = "waf2107@columbia.edu" +__license__ = "Apache-2.0" +__copyright__ = f"Copyright (c) 2018-{_this_year}, {__author__}." +__homepage__ = "https://github.com/PyTorchLightning/pytorch-lightning" # this has to be simple string, see: https://github.com/pypa/twine/issues/522 __docs__ = ( "PyTorch Lightning is the lightweight PyTorch wrapper for ML researchers." @@ -77,17 +77,19 @@ from pytorch_lightning.utilities.seed import seed_everything __all__ = [ - 'Trainer', - 'LightningDataModule', - 'LightningModule', - 'Callback', - 'seed_everything', - 'metrics', + "Trainer", + "LightningDataModule", + "LightningModule", + "Callback", + "seed_everything", + "metrics", ] else: - sys.stdout.write(f'Partial import of `{__name__}` during the build process.\n') # pragma: no-cover + sys.stdout.write( + f"Partial import of `{__name__}` during the build process.\n" + ) # pragma: no-cover # We are not importing the rest of the lightning during the build process, as it may not be compiled yet - + # for compatibility with namespace packages -__import__('pkg_resources').declare_namespace(__name__) +__import__("pkg_resources").declare_namespace(__name__) From a862e322dea8c93692260511d6f0092918acc4c6 Mon Sep 17 00:00:00 2001 From: Luis Perez Date: Wed, 17 Mar 2021 11:30:39 -0700 Subject: [PATCH 3/3] Single vs double quotes to reduce noise --- pytorch_lightning/__init__.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pytorch_lightning/__init__.py b/pytorch_lightning/__init__.py index 4c87873d8defb..d14a094b72b00 100644 --- a/pytorch_lightning/__init__.py +++ b/pytorch_lightning/__init__.py @@ -7,12 +7,12 @@ import typing _this_year = time.strftime("%Y") -__version__ = "1.3.0dev" -__author__ = "William Falcon et al." -__author_email__ = "waf2107@columbia.edu" -__license__ = "Apache-2.0" -__copyright__ = f"Copyright (c) 2018-{_this_year}, {__author__}." -__homepage__ = "https://github.com/PyTorchLightning/pytorch-lightning" +__version__ = '1.3.0dev' +__author__ = 'William Falcon et al.' +__author_email__ = 'waf2107@columbia.edu' +__license__ = 'Apache-2.0' +__copyright__ = f'Copyright (c) 2018-{_this_year}, {__author__}.' +__homepage__ = 'https://github.com/PyTorchLightning/pytorch-lightning' # this has to be simple string, see: https://github.com/pypa/twine/issues/522 __docs__ = ( "PyTorch Lightning is the lightweight PyTorch wrapper for ML researchers." @@ -77,19 +77,19 @@ from pytorch_lightning.utilities.seed import seed_everything __all__ = [ - "Trainer", - "LightningDataModule", - "LightningModule", - "Callback", - "seed_everything", - "metrics", + 'Trainer', + 'LightningDataModule', + 'LightningModule', + 'Callback', + 'seed_everything', + 'metrics', ] else: sys.stdout.write( - f"Partial import of `{__name__}` during the build process.\n" + f'Partial import of `{__name__}` during the build process.\n' ) # pragma: no-cover # We are not importing the rest of the lightning during the build process, as it may not be compiled yet # for compatibility with namespace packages -__import__("pkg_resources").declare_namespace(__name__) +__import__('pkg_resources').declare_namespace(__name__)