Skip to content

Commit 7a48db5

Browse files
authored
Fixes a potential bug on pip install (#7256)
* Fix install bug * Better fix * Fix * Fix * Remove unused import * Update docs conf.py * Updates
1 parent 075de93 commit 7a48db5

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

docs/source/conf.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
import shutil
1919
import sys
20+
from importlib.util import module_from_spec, spec_from_file_location
2021

2122
import pt_lightning_sphinx_theme
2223

@@ -27,12 +28,12 @@
2728
FOLDER_GENERATED = 'generated'
2829
SPHINX_MOCK_REQUIREMENTS = int(os.environ.get('SPHINX_MOCK_REQUIREMENTS', True))
2930

30-
try:
31-
from pytorch_lightning import __about__ as info
32-
except ImportError:
33-
# alternative https://stackoverflow.com/a/67692/4521646
34-
sys.path.append(os.path.join(PATH_ROOT, "pytorch_lightning"))
35-
import __about__ as info
31+
spec = spec_from_file_location(
32+
"pytorch_lightning/__about__.py",
33+
os.path.join(PATH_ROOT, "pytorch_lightning", "__about__.py"),
34+
)
35+
about = module_from_spec(spec)
36+
spec.loader.exec_module(about)
3637

3738
# -- Project documents -------------------------------------------------------
3839

@@ -81,13 +82,13 @@ def _transform_changelog(path_in: str, path_out: str) -> None:
8182
# -- Project information -----------------------------------------------------
8283

8384
project = 'PyTorch Lightning'
84-
copyright = info.__copyright__
85-
author = info.__author__
85+
copyright = about.__copyright__
86+
author = about.__author__
8687

8788
# The short X.Y version
88-
version = info.__version__
89+
version = about.__version__
8990
# The full version, including alpha/beta/rc tags
90-
release = info.__version__
91+
release = about.__version__
9192

9293
# -- General configuration ---------------------------------------------------
9394

@@ -179,7 +180,7 @@ def _transform_changelog(path_in: str, path_out: str) -> None:
179180

180181
html_theme_options = {
181182
'pytorch_project': 'https://pytorchlightning.ai',
182-
'canonical_url': info.__docs_url__,
183+
'canonical_url': about.__docs_url__,
183184
'collapse_navigation': False,
184185
'display_version': True,
185186
'logo_only': False,

setup.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@
1414
# limitations under the License.
1515

1616
import os
17-
18-
# Always prefer setuptools over distutils
19-
import sys
17+
from importlib.util import module_from_spec, spec_from_file_location
2018

2119
from setuptools import find_packages, setup
2220

23-
try:
24-
from pytorch_lightning import __about__ as info
25-
from pytorch_lightning import setup_tools
26-
except ImportError:
27-
# alternative https://stackoverflow.com/a/67692/4521646
28-
sys.path.append("pytorch_lightning")
29-
import __about__ as info
30-
import setup_tools
31-
3221
# https://packaging.python.org/guides/single-sourcing-package-version/
3322
# http://blog.ionelmc.ro/2014/05/25/python-packaging/
3423
_PATH_ROOT = os.path.dirname(__file__)
3524
_PATH_REQUIRE = os.path.join(_PATH_ROOT, 'requirements')
3625

26+
27+
def _load_py_module(fname, pkg="pytorch_lightning"):
28+
spec = spec_from_file_location(os.path.join(pkg, fname), os.path.join(_PATH_ROOT, pkg, fname))
29+
py = module_from_spec(spec)
30+
spec.loader.exec_module(py)
31+
return py
32+
33+
34+
about = _load_py_module('__about__.py')
35+
setup_tools = _load_py_module('setup_tools.py')
36+
3737
# https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras
3838
# Define package extras. These are only installed if you specify them.
3939
# From remote, use like `pip install pytorch-lightning[dev, docs]`
@@ -58,8 +58,8 @@
5858

5959
long_description = setup_tools._load_readme_description(
6060
_PATH_ROOT,
61-
homepage=info.__homepage__,
62-
version=info.__version__,
61+
homepage=about.__homepage__,
62+
version=about.__version__,
6363
)
6464

6565
# https://packaging.python.org/discussions/install-requires-vs-requirements /
@@ -69,13 +69,13 @@
6969
# engineer specific practices
7070
setup(
7171
name="pytorch-lightning",
72-
version=info.__version__,
73-
description=info.__docs__,
74-
author=info.__author__,
75-
author_email=info.__author_email__,
76-
url=info.__homepage__,
72+
version=about.__version__,
73+
description=about.__docs__,
74+
author=about.__author__,
75+
author_email=about.__author_email__,
76+
url=about.__homepage__,
7777
download_url='https://github.com/PyTorchLightning/pytorch-lightning',
78-
license=info.__license__,
78+
license=about.__license__,
7979
packages=find_packages(exclude=['tests', 'tests/*', 'benchmarks', 'legacy', 'legacy/*']),
8080
long_description=long_description,
8181
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)