diff --git a/README.md b/README.md
index 68411ebe56..71e81c0910 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-![Logo](https://raw.githubusercontent.com/PyTorchLightning/pytorch-lightning-bolts/master/docs/source/_images/logos/bolts_logo.png)
+![Logo](docs/source/_images/logos/bolts_logo.png)
# PyTorch Lightning Bolts
diff --git a/docs/source/conf.py b/docs/source/conf.py
index 8a2330fae1..488d52d44e 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -149,6 +149,7 @@
'api/modules.rst',
'api/pl_bolts.submit.rst',
'api/pl_bolts.utils.*',
+ 'api/pl_bolts.setup_tools.*',
'PULL_REQUEST_TEMPLATE.md',
]
diff --git a/pl_bolts/__init__.py b/pl_bolts/__init__.py
index 4e3f15be7b..1ad094277c 100644
--- a/pl_bolts/__init__.py
+++ b/pl_bolts/__init__.py
@@ -29,6 +29,7 @@
"""
_PACKAGE_ROOT = os.path.dirname(__file__)
+_PROJECT_ROOT = os.path.dirname(_PACKAGE_ROOT)
_HTTPS_AWS_HUB = "https://pl-bolts-weights.s3.us-east-2.amazonaws.com"
try:
diff --git a/pl_bolts/setup_tools.py b/pl_bolts/setup_tools.py
new file mode 100644
index 0000000000..25eb98cf76
--- /dev/null
+++ b/pl_bolts/setup_tools.py
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+# Copyright The PyTorch Lightning team.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import os
+import re
+from typing import List
+
+from pl_bolts import __homepage__, __version__, _PROJECT_ROOT
+
+_PATH_BADGES = os.path.join('.', 'docs', 'source', '_images', 'badges')
+# badge to download
+_DEFAULT_BADGES = (
+ 'Conda',
+ 'DockerHub',
+ 'codecov',
+ 'ReadTheDocs',
+ 'Slack',
+ 'Discourse status',
+ 'license',
+)
+
+
+def _load_requirements(path_dir: str, file_name: str = 'requirements.txt', comment_char: str = '#') -> List[str]:
+ """Load requirements from a file
+
+ >>> _load_requirements(_PROJECT_ROOT) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
+ ['torch...', 'pytorch-lightning...'...]
+ """
+ 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:
+ # filer all comments
+ if comment_char in ln:
+ ln = ln[:ln.index(comment_char)].strip()
+ # skip directly installed dependencies
+ if ln.startswith('http'):
+ continue
+ if ln: # if requirement is not empty
+ reqs.append(ln)
+ return reqs
+
+
+def _load_readme_description(path_dir: str, homepage: str = __homepage__, ver: str = __version__) -> str:
+ """Load readme as decribtion
+
+ >>> _load_readme_description(_PROJECT_ROOT) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
+ '
...'
+ """
+ path_readme = os.path.join(path_dir, "README.md")
+ text = open(path_readme, encoding="utf-8").read()
+
+ # drop images from readme
+ text = text.replace('![PT to PL](docs/source/_images/general/pl_quick_start_full_compressed.gif)', '')
+
+ # https://github.com/PyTorchLightning/pytorch-lightning/raw/master/docs/source/_images/lightning_module/pt_to_pl.png
+ github_source_url = os.path.join(homepage, "raw", ver)
+ # replace relative repository path to absolute link to the release
+ # do not replace all "docs" as in the readme we reger some other sources with particular path to docs
+ text = text.replace("docs/source/_images/", f"{os.path.join(github_source_url, 'docs/source/_images/')}")
+
+ # readthedocs badge
+ text = text.replace('badge/?version=stable', f'badge/?version={ver}')
+ text = text.replace('pytorch-lightning.readthedocs.io/en/stable/', f'pytorch-lightning.readthedocs.io/en/{ver}')
+ # codecov badge
+ text = text.replace('/branch/master/graph/badge.svg', f'/release/{ver}/graph/badge.svg')
+ # replace github badges for release ones
+ text = text.replace('badge.svg?branch=master&event=push', f'badge.svg?tag={ver}')
+
+ skip_begin = r''
+ skip_end = r''
+ # todo: wrap content as commented description
+ text = re.sub(rf"{skip_begin}.+?{skip_end}", '', text, flags=re.IGNORECASE + re.DOTALL)
+
+ # # https://github.com/Borda/pytorch-lightning/releases/download/1.1.0a6/codecov_badge.png
+ # github_release_url = os.path.join(homepage, "releases", "download", ver)
+ # # download badge and replace url with local file
+ # text = _parse_for_badge(text, github_release_url)
+ return text
diff --git a/setup.py b/setup.py
index 552060790f..1b1b2ca5bd 100755
--- a/setup.py
+++ b/setup.py
@@ -10,14 +10,7 @@
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'])
+from pl_bolts.setup_tools import _load_requirements, _load_readme_description
# https://packaging.python.org/guides/single-sourcing-package-version/
# http://blog.ionelmc.ro/2014/05/25/python-packaging/
@@ -28,16 +21,6 @@
import pl_bolts # noqa: E402
-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 _prepare_extras():
extras = {
'loggers': _load_requirements(path_dir=os.path.join(_PATH_ROOT, 'requirements'), file_name='loggers.txt'),
@@ -64,14 +47,14 @@ def _prepare_extras():
download_url='https://github.com/PyTorchLightning/pytorch-lightning-bolts',
license=pl_bolts.__license__,
packages=find_packages(exclude=['tests', 'docs']),
- long_description=_load_long_description(),
+ long_description=_load_readme_description(_PATH_ROOT),
long_description_content_type='text/markdown',
include_package_data=True,
zip_safe=False,
keywords=['deep learning', 'pytorch', 'AI'],
python_requires='>=3.6',
setup_requires=['pytorch-lightning>=1.1.0'],
- install_requires=_load_requirements(),
+ install_requires=_load_requirements(_PATH_ROOT),
extras_require=_prepare_extras(),
project_urls={
"Bug Tracker": "https://github.com/PyTorchLightning/pytorch-lightning-bolts/issues",