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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lit extras #15793

Merged
merged 10 commits into from
Nov 24, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docs-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
# This is needed as App docs is heavily using/referring to lightning package
if: ${{ matrix.pkg-name == 'app' }}
run: |
pip install -e . -U -f https://download.pytorch.org/whl/cpu/torch_stable.html -f pypi
pip install -e . -U -v -f https://download.pytorch.org/whl/cpu/torch_stable.html -f pypi
git checkout -- .

- name: Adjust docs refs
Expand Down
2 changes: 1 addition & 1 deletion requirements/pytorch/strategies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ fairscale>=0.4.5, <=0.4.6
deepspeed>=0.6.0, <=0.7.0
# no need to install with [pytorch] as pytorch is already installed
horovod>=0.21.2, !=0.24.0, <=0.26.1
hivemind>=1.0.1, <=1.0.1; sys_platform == 'linux'
hivemind==1.0.1; sys_platform == 'linux'
30 changes: 28 additions & 2 deletions src/lightning/__setup__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import glob
import os.path
from importlib.util import module_from_spec, spec_from_file_location
from pathlib import Path
from types import ModuleType
from typing import Any, Dict

Expand All @@ -8,7 +10,7 @@
_PROJECT_ROOT = "."
_SOURCE_ROOT = os.path.join(_PROJECT_ROOT, "src")
_PACKAGE_ROOT = os.path.join(_SOURCE_ROOT, "lightning")
_PATH_REQUIREMENTS = os.path.join("requirements")
_PATH_REQUIREMENTS = os.path.join(_PROJECT_ROOT, "requirements")
_FREEZE_REQUIREMENTS = bool(int(os.environ.get("FREEZE_REQUIREMENTS", 0)))


Expand All @@ -24,6 +26,30 @@ def _load_py_module(name: str, location: str) -> ModuleType:
_SETUP_TOOLS = _load_py_module("setup_tools", os.path.join(_PROJECT_ROOT, ".actions", "setup_tools.py"))


def _prepare_extras() -> Dict[str, Any]:
# https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras
# Define package extras. These are only installed if you specify them.
# From remote, use like `pip install pytorch-lightning[dev, docs]`
# From local copy of repo, use like `pip install ".[dev, docs]"`
req_files = [Path(p) for p in glob.glob(os.path.join(_PATH_REQUIREMENTS, "*", "*.txt"))]
common_args = dict(unfreeze="major" if _FREEZE_REQUIREMENTS else "all")
extras = {
f"{p.parent.name}-{p.stem}": _SETUP_TOOLS.load_requirements(file_name=p.name, path_dir=p.parent, **common_args)
for p in req_files
if p.name not in ("docs.txt", "devel.txt", "base.txt")
}
for extra in list(extras):
name = "-".join(extra.split("-")[1:])
extras[name] = extras.get(name, []) + extras[extra]
# todo
# extras["extra"] = extras["cloud"] + extras["ui"]
# extras["dev"] = extras["extra"] + extras["test"] # + extras['docs']
# extras["all"] = extras["dev"]
extras = {name: list(set(reqs)) for name, reqs in extras.items()}
print("The extras are", extras)
return extras


def _adjust_manifest(**kwargs: Any) -> None:
# todo: consider rather aggregation of particular manifest adjustments
manifest_path = os.path.join(_PROJECT_ROOT, "MANIFEST.in")
Expand Down Expand Up @@ -83,7 +109,7 @@ def _setup_args(**kwargs: Any) -> Dict[str, Any]:
},
setup_requires=[],
install_requires=_SETUP_TOOLS.load_requirements(_PATH_REQUIREMENTS, unfreeze="all"),
extras_require={}, # todo: consider porting all other packages extras with prefix
extras_require=_prepare_extras(),
project_urls={
"Bug Tracker": "https://github.com/Lightning-AI/lightning/issues",
"Documentation": "https://lightning.ai/lightning-docs",
Expand Down