Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor setup #601

Merged
merged 7 commits into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci_test-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
- name: Test Package [only]
run: |
# NOTE: run coverage on tests does not propagare faler status for Win, https://github.com/nedbat/coveragepy/issues/1003
coverage run --source pl_bolts -m pytest pl_bolts -v --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml --ignore=pl_bolts/datamodules --ignore=pl_bolts/datasets --ignore=pl_bolts/models/self_supervised/amdim/transforms.py --ignore=pl_bolts/models/rl
python -m pytest pl_bolts -v --cov=pl_bolts --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.requires }}.xml --ignore=pl_bolts/datamodules --ignore=pl_bolts/datasets --ignore=pl_bolts/models/self_supervised/amdim/transforms.py --ignore=pl_bolts/models/rl

- name: Upload pytest test results
uses: actions/upload-artifact@master
Expand Down
56 changes: 29 additions & 27 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,38 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.

# import m2r
import builtins
import glob
import inspect
import os
import shutil
import sys
from importlib.util import module_from_spec, spec_from_file_location

import pt_lightning_sphinx_theme
from sphinx.ext import apidoc

PATH_HERE = os.path.abspath(os.path.dirname(__file__))
PATH_ROOT = os.path.join(PATH_HERE, '..', '..')
sys.path.insert(0, os.path.abspath(PATH_ROOT))

builtins.__LIGHTNING_BOLT_SETUP__: bool = True
_PATH_HERE = os.path.abspath(os.path.dirname(__file__))
_PATH_ROOT = os.path.join(_PATH_HERE, '..', '..')
sys.path.insert(0, os.path.abspath(_PATH_ROOT))

SPHINX_MOCK_REQUIREMENTS = int(os.environ.get('SPHINX_MOCK_REQUIREMENTS', True))

import pl_bolts # noqa: E402
# alternative https://stackoverflow.com/a/67692/4521646
spec = spec_from_file_location("pl_bolts", os.path.join(_PATH_ROOT, "pl_bolts", "info.py"))
info = module_from_spec(spec)
spec.loader.exec_module(info)

# -- Project information -----------------------------------------------------

# this name shall match the project name in Github as it is used for linking to code
project = 'Lightning-Bolts'
copyright = pl_bolts.__copyright__
author = pl_bolts.__author__
copyright = info.__copyright__
author = info.__author__

# The short X.Y version
version = pl_bolts.__version__
version = info.__version__
# The full version, including alpha/beta/rc tags
release = pl_bolts.__version__
release = info.__version__

# Options for the linkcode extension
# ----------------------------------
Expand All @@ -63,11 +64,11 @@
# fp.write(readme)

# copy all documents from GH templates like contribution guide
for md in glob.glob(os.path.join(PATH_ROOT, '.github', '*.md')):
shutil.copy(md, os.path.join(PATH_HERE, os.path.basename(md)))
for md in glob.glob(os.path.join(_PATH_ROOT, '.github', '*.md')):
shutil.copy(md, os.path.join(_PATH_HERE, os.path.basename(md)))

# export the changelog
with open(os.path.join(PATH_ROOT, 'CHANGELOG.md'), 'r') as fp:
with open(os.path.join(_PATH_ROOT, 'CHANGELOG.md'), 'r') as fp:
chlog_lines = fp.readlines()
# enrich short subsub-titles to be unique
chlog_ver = ''
Expand All @@ -77,7 +78,7 @@
elif ln.startswith('### '):
ln = ln.replace('###', f'### {chlog_ver} -')
chlog_lines[i] = ln
with open(os.path.join(PATH_HERE, 'CHANGELOG.md'), 'w') as fp:
with open(os.path.join(_PATH_HERE, 'CHANGELOG.md'), 'w') as fp:
fp.writelines(chlog_lines)

# -- General configuration ---------------------------------------------------
Expand Down Expand Up @@ -149,7 +150,8 @@
'api/modules.rst',
'api/pl_bolts.submit.rst',
'api/pl_bolts.utils.*',
'api/pl_bolts.setup_tools.*',
'api/pl_bolts.info.rst',
'api/pl_bolts.setup_tools.rst',
'PULL_REQUEST_TEMPLATE.md',
]

Expand All @@ -169,8 +171,8 @@
# documentation.

html_theme_options = {
'pytorch_project': pl_bolts.__homepage__,
'canonical_url': pl_bolts.__homepage__,
'pytorch_project': info.__homepage__,
'canonical_url': info.__homepage__,
'collapse_navigation': False,
'display_version': True,
'logo_only': False,
Expand Down Expand Up @@ -288,10 +290,10 @@

# packages for which sphinx-apidoc should generate the docs (.rst files)
PACKAGES = [
pl_bolts.__name__,
info.__name__,
]

apidoc_output_folder = os.path.join(PATH_HERE, 'api')
apidoc_output_folder = os.path.join(_PATH_HERE, 'api')


def run_apidoc(_):
Expand All @@ -306,7 +308,7 @@ def run_apidoc(_):
'-e',
'-o',
apidoc_output_folder,
os.path.join(PATH_ROOT, pkg),
os.path.join(_PATH_ROOT, pkg),
'**/test_*',
'--force',
'--private',
Expand All @@ -319,15 +321,15 @@ def run_apidoc(_):
def setup(app):
# this is for hiding doctest decoration,
# see: http://z4r.github.io/python/2011/12/02/hides-the-prompts-and-output/
app.add_javascript('copybutton.js')
app.add_js_file('copybutton.js')
app.connect('builder-inited', run_apidoc)


# copy all notebooks to local folder
path_nbs = os.path.join(PATH_HERE, 'notebooks')
path_nbs = os.path.join(_PATH_HERE, 'notebooks')
if not os.path.isdir(path_nbs):
os.mkdir(path_nbs)
for path_ipynb in glob.glob(os.path.join(PATH_ROOT, 'notebooks', '*.ipynb')):
for path_ipynb in glob.glob(os.path.join(_PATH_ROOT, 'notebooks', '*.ipynb')):
path_ipynb2 = os.path.join(path_nbs, os.path.basename(path_ipynb))
shutil.copy(path_ipynb, path_ipynb2)

Expand Down Expand Up @@ -355,9 +357,9 @@ def package_list_from_file(file):
MOCK_PACKAGES = []
if SPHINX_MOCK_REQUIREMENTS:
# mock also base packages when we are on RTD since we don't install them there
MOCK_PACKAGES += package_list_from_file(os.path.join(PATH_ROOT, 'requirements.txt'))
MOCK_PACKAGES += package_list_from_file(os.path.join(PATH_ROOT, 'requirements', 'models.txt'))
MOCK_PACKAGES += package_list_from_file(os.path.join(PATH_ROOT, 'requirements', 'loggers.txt'))
MOCK_PACKAGES += package_list_from_file(os.path.join(_PATH_ROOT, 'requirements.txt'))
MOCK_PACKAGES += package_list_from_file(os.path.join(_PATH_ROOT, 'requirements', 'models.txt'))
MOCK_PACKAGES += package_list_from_file(os.path.join(_PATH_ROOT, 'requirements', 'loggers.txt'))
# replace PyPI packages by importing ones
MOCK_PACKAGES = [PACKAGE_MAPPING.get(pkg, pkg) for pkg in MOCK_PACKAGES]

Expand Down
85 changes: 33 additions & 52 deletions pl_bolts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,41 @@
"""Root package info."""
"""Root package crossroad."""

import os

__version__ = '0.3.2rc1'
__author__ = 'PyTorchLightning et al.'
__author_email__ = 'name@pytorchlightning.ai'
__license__ = 'Apache-2.0'
__copyright__ = f'Copyright (c) 2020-2021, {__author__}'
__homepage__ = 'https://github.com/PyTorchLightning/lightning-bolts'
__docs__ = "PyTorch Lightning Bolts is a community contribution for ML researchers."
__long_doc__ = """
What is it?
-----------
Bolts is a collection of useful models and templates to bootstrap your DL research even faster.
It's designed to work with PyTorch Lightning

Subclass Example
----------------
Use `pl_bolts` models to remove boilerplate for common approaches and architectures.
Because it uses LightningModules under the hood, you just need to overwrite
the relevant parts to your research.

How to add a model
------------------
This repository is meant for model contributions from the community.
To add a model, you can start with the MNIST template (or any other model in the repo).
Please organize the functions of your lightning module.
"""
from pl_bolts.info import ( # noqa: F401
__author__,
__author_email__,
__copyright__,
__docs__,
__homepage__,
__license__,
__version__,
)

_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:
# This variable is injected in the __builtins__ by the build process.
# It used to enable importing subpackages when the binaries are not built.
_ = None if __LIGHTNING_BOLT_SETUP__ else None
except NameError:
__LIGHTNING_BOLT_SETUP__: bool = False

if __LIGHTNING_BOLT_SETUP__: # pragma: no cover
import sys

sys.stdout.write(f'Partial import of `{__name__}` during the build process.\n')
# We are not importing the rest of the lightning during the build process, as it may not be compiled yet
else:
from pl_bolts import callbacks, datamodules, datasets, losses, metrics, models, optimizers, transforms, utils

__all__ = [
'callbacks',
'datamodules',
'datasets',
'losses',
'metrics',
'models',
'optimizers',
'transforms',
'utils',
]
from pl_bolts import ( # noqa: E402
callbacks,
datamodules,
datasets,
losses,
metrics,
models,
optimizers,
transforms,
utils,
)

__all__ = [
'callbacks',
'datamodules',
'datasets',
'losses',
'metrics',
'models',
'optimizers',
'transforms',
'utils',
]
25 changes: 25 additions & 0 deletions pl_bolts/info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
__version__ = '0.3.2rc1'
__author__ = 'PyTorchLightning et al.'
__author_email__ = 'name@pytorchlightning.ai'
__license__ = 'Apache-2.0'
__copyright__ = f'Copyright (c) 2020-2021, {__author__}'
__homepage__ = 'https://github.com/PyTorchLightning/lightning-bolts'
__docs__ = "PyTorch Lightning Bolts is a community contribution for ML researchers."
__long_doc__ = """
What is it?
-----------
Bolts is a collection of useful models and templates to bootstrap your DL research even faster.
It's designed to work with PyTorch Lightning

Subclass Example
----------------
Use `pl_bolts` models to remove boilerplate for common approaches and architectures.
Because it uses LightningModules under the hood, you just need to overwrite
the relevant parts to your research.

How to add a model
------------------
This repository is meant for model contributions from the community.
To add a model, you can start with the MNIST template (or any other model in the repo).
Please organize the functions of your lightning module.
"""
18 changes: 3 additions & 15 deletions pl_bolts/setup_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@
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',
)
_PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))


def _load_requirements(path_dir: str, file_name: str = 'requirements.txt', comment_char: str = '#') -> List[str]:
Expand All @@ -52,10 +40,10 @@ def _load_requirements(path_dir: str, file_name: str = 'requirements.txt', comme
return reqs


def _load_readme_description(path_dir: str, homepage: str = __homepage__, ver: str = __version__) -> str:
def _load_readme_description(path_dir: str, homepage: str, ver: str) -> str:
"""Load readme as decribtion

>>> _load_readme_description(_PROJECT_ROOT) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
>>> _load_readme_description(_PROJECT_ROOT, "", "") # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
'<div align="center">...'
"""
path_readme = os.path.join(path_dir, "README.md")
Expand Down
5 changes: 2 additions & 3 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
codecov>=2.1
pytest>=6.0
pytest-cov>2.10
pytest-flake8
flake8>=3.6
# flake8-black
# pytest-flake8
flake8
check-manifest
twine>=3.2
isort>=5.6.4
Expand Down