Skip to content

Commit

Permalink
update setup with PL (#514)
Browse files Browse the repository at this point in the history
* update setup with PL

* pl

* extras

* pl

* flake8
  • Loading branch information
Borda authored Jan 15, 2021
1 parent c43622e commit 25bfadc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@

# -- Project documents -------------------------------------------------------
# export the READme
# with open(os.path.join(PATH_ROOT, 'README.md'), 'r') as fp:
# with open(os.path.join(_PATH_ROOT, 'README.md'), 'r') as fp:
# readme = fp.read()
# # TODO: temp fix removing SVG badges and GIF, because PDF cannot show them
# readme = re.sub(r'(\[!\[.*\))', '', readme)
# readme = re.sub(r'(!\[.*.gif\))', '', readme)
# for dir_name in (os.path.basename(p) for p in glob.glob(os.path.join(PATH_ROOT, '*')) if os.path.isdir(p)):
# readme = readme.replace('](%s/' % dir_name, '](%s/%s/' % (PATH_ROOT, dir_name))
# for dir_name in (os.path.basename(p) for p in glob.glob(os.path.join(_PATH_ROOT, '*')) if os.path.isdir(p)):
# readme = readme.replace('](%s/' % dir_name, '](%s/%s/' % (_PATH_ROOT, dir_name))
# with open('readme.md', 'w') as fp:
# fp.write(readme)

Expand Down
63 changes: 30 additions & 33 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,44 @@
except ImportError:
import __builtin__ as builtins

try:
import pytorch_lightning # noqa: F401
except ImportError:
try:
import pip
except ImportError:
raise ImportError('Missing `pip` to install custom dependencies.')
pip.main(['install', 'pytorch-lightning>=1.1.0'])

# https://packaging.python.org/guides/single-sourcing-package-version/
# http://blog.ionelmc.ro/2014/05/25/python-packaging/

PATH_ROOT = os.path.dirname(__file__)
_PATH_ROOT = os.path.dirname(__file__)
builtins.__LIGHTNING_BOLT_SETUP__: bool = True

import pl_bolts # noqa: E402


def load_requirements(path_dir=PATH_ROOT, file_name='requirements.txt', comment_char='#'):
with open(os.path.join(path_dir, file_name), 'r') as file:
lines = [ln.strip() for ln in file.readlines()]
reqs = []
for ln in lines:
if comment_char in ln: # filer all comments
ln = ln[:ln.index(comment_char)].strip()
if ln.startswith('http'): # skip directly installed dependencies
continue
if ln: # if requirement is not empty
reqs.append(ln)
return reqs
def _load_requirements(path_dir=_PATH_ROOT, file_name='requirements.txt', comment_char='#'):
from pytorch_lightning.setup_tools import _load_requirements as _lreq
return _lreq(path_dir=path_dir, file_name=file_name, comment_char=comment_char)


def _load_long_description():
from pytorch_lightning.setup_tools import _load_long_description as _lld
return _lld(_PATH_ROOT)

def load_long_describtion():
# https://github.com/PyTorchLightning/pytorch-lightning/raw/master/docs/source/_images/lightning_module/pt_to_pl.png
url = os.path.join(pl_bolts.__homepage__, 'raw', pl_bolts.__version__, 'docs')
text = open('README.md', encoding='utf-8').read()
# replace relative repository path to absolute link to the release
text = text.replace('](docs', f']({url}')
# SVG images are not readable on PyPI, so replace them with PNG
text = text.replace('.svg', '.png')
return text

def _prepare_extras():
extras = {
'loggers': _load_requirements(path_dir=os.path.join(_PATH_ROOT, 'requirements'), file_name='loggers.txt'),
'models': _load_requirements(path_dir=os.path.join(_PATH_ROOT, 'requirements'), file_name='models.txt'),
'test': _load_requirements(path_dir=os.path.join(_PATH_ROOT, 'requirements'), file_name='test.txt'),
}
extras['extra'] = extras['models'] + extras['loggers']
extras['dev'] = extras['extra'] + extras['test']
return extras

extras = {
'loggers': load_requirements(path_dir=os.path.join(PATH_ROOT, 'requirements'), file_name='loggers.txt'),
'models': load_requirements(path_dir=os.path.join(PATH_ROOT, 'requirements'), file_name='models.txt'),
'test': load_requirements(path_dir=os.path.join(PATH_ROOT, 'requirements'), file_name='test.txt'),
}
extras['extra'] = extras['models'] + extras['loggers']
extras['dev'] = extras['extra'] + extras['test']

# https://packaging.python.org/discussions/install-requires-vs-requirements /
# keep the meta-data here for simplicity in reading this file... it's not obvious
Expand All @@ -67,15 +64,15 @@ def load_long_describtion():
download_url='https://github.com/PyTorchLightning/pytorch-lightning-bolts',
license=pl_bolts.__license__,
packages=find_packages(exclude=['tests', 'docs']),
long_description=load_long_describtion(),
long_description=_load_long_description(),
long_description_content_type='text/markdown',
include_package_data=True,
zip_safe=False,
keywords=['deep learning', 'pytorch', 'AI'],
python_requires='>=3.6',
setup_requires=[],
install_requires=load_requirements(),
extras_require=extras,
setup_requires=['pytorch-lightning>=1.1.0'],
install_requires=_load_requirements(),
extras_require=_prepare_extras(),
project_urls={
"Bug Tracker": "https://github.com/PyTorchLightning/pytorch-lightning-bolts/issues",
"Documentation": "https://pytorch-lightning-bolts.rtfd.io/en/latest/",
Expand Down

0 comments on commit 25bfadc

Please sign in to comment.