Skip to content

Commit

Permalink
own setup tools
Browse files Browse the repository at this point in the history
fix logo path
  • Loading branch information
Borda committed Jan 22, 2021
1 parent 59d06c2 commit 41d0aab
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">

![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

Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]

Expand Down
1 change: 1 addition & 0 deletions pl_bolts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
90 changes: 90 additions & 0 deletions pl_bolts/setup_tools.py
Original file line number Diff line number Diff line change
@@ -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
'<div align="center">...'
"""
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'<!-- following section will be skipped from PyPI description -->'
skip_end = r'<!-- end skipping PyPI description -->'
# 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
23 changes: 3 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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'),
Expand All @@ -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",
Expand Down

0 comments on commit 41d0aab

Please sign in to comment.