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
Changes from 1 commit
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
40 changes: 37 additions & 3 deletions src/lightning/__setup__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import glob
import os.path
from importlib.util import module_from_spec, spec_from_file_location
from types import ModuleType
from typing import Any, Dict

from setuptools import find_packages

_PROJECT_ROOT = "."
_PROJECT_ROOT = "../.." # FIXME
_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 +25,39 @@ 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 = glob.glob(os.path.join(_PATH_REQUIREMENTS, "*", "*.txt"))
reqs = [dict(dir=os.path.dirname(p), fname=os.path.basename(p)) for p in req_files]
carmocca marked this conversation as resolved.
Show resolved Hide resolved
common_args = dict(unfreeze="major" if _FREEZE_REQUIREMENTS else "all")
reqs = [
dict(
dir=r["dir"],
fname=r["fname"],
extra=os.path.splitext(r["fname"])[0],
group=os.path.basename(r["dir"]),
req=_SETUP_TOOLS.load_requirements(file_name=r["fname"], path_dir=r["dir"], **common_args),
)
for r in reqs
if r["fname"] not in ("docs.txt", "devel.txt", "base.txt")
]

extras = {f"{r['group']}_{r['extra']}": r["req"] for r in reqs}
extra_names = list(extras.keys())
for extra in extra_names:
carmocca marked this conversation as resolved.
Show resolved Hide resolved
name = "_".join(extra.split("_")[1:])
Borda marked this conversation as resolved.
Show resolved Hide resolved
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()}
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 +117,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