Skip to content

Commit 32e319a

Browse files
authored
Revert "Do not modify MANIFEST.in on install (#15549)" (#15644)
This reverts commit 4ea44dd.
1 parent 18288eb commit 32e319a

File tree

12 files changed

+96
-81
lines changed

12 files changed

+96
-81
lines changed

.github/actions/pkg-check/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ runs:
3333

3434
- name: Check package
3535
run: |
36-
git diff --exit-code || exit $? # make sure there are no local unstaged changes
3736
ls -l dist/
3837
twine check dist/*
38+
# python setup.py clean
3939
shell: bash
4040

4141
- name: Unzip packages

.github/workflows/docs-checks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ jobs:
7575
if: ${{ matrix.pkg-name == 'app' }}
7676
run: |
7777
pip install -e . -U -f https://download.pytorch.org/whl/cpu/torch_stable.html -f pypi
78+
git checkout -- .
7879
7980
- name: Adjust docs refs
8081
if: ${{ matrix.pkg-name == 'app' }}

MANIFEST.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
exclude *.toml # project config
2+
exclude requirements.txt
3+
exclude __pycache__
4+
include .actions/setup_tools.py
5+
include .actions/assistant.py
6+
include *.cff # citation info

setup.py

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,11 @@
3939
b) with a parameterization build desired packages in to standard `dist/` folder
4040
c) validate packages and publish to PyPI
4141
"""
42-
import contextlib
4342
import os
44-
import tempfile
4543
from importlib.util import module_from_spec, spec_from_file_location
4644
from types import ModuleType
47-
from typing import Generator, Optional
4845

49-
import setuptools
50-
import setuptools.command.egg_info
46+
from setuptools import setup
5147

5248
_PACKAGE_NAME = os.environ.get("PACKAGE_NAME")
5349
_PACKAGE_MAPPING = {
@@ -73,43 +69,6 @@ def _load_py_module(name: str, location: str) -> ModuleType:
7369
return py
7470

7571

76-
def _named_temporary_file(directory: Optional[str] = None) -> str:
77-
# `tempfile.NamedTemporaryFile` has issues in Windows
78-
# https://github.com/deepchem/deepchem/issues/707#issuecomment-556002823
79-
if directory is None:
80-
directory = tempfile.gettempdir()
81-
return os.path.join(directory, os.urandom(24).hex())
82-
83-
84-
@contextlib.contextmanager
85-
def _set_manifest_path(manifest_dir: str, aggregate: bool = False) -> Generator:
86-
if aggregate:
87-
# aggregate all MANIFEST.in contents into a single temporary file
88-
manifest_path = _named_temporary_file(manifest_dir)
89-
mapping = _PACKAGE_MAPPING.copy()
90-
del mapping["lightning"]
91-
lines = []
92-
for pkg in mapping.values():
93-
with open(os.path.join(_PATH_SRC, pkg, "MANIFEST.in")) as fh:
94-
lines.extend(fh.readlines())
95-
# convert lightning_foo to lightning/foo
96-
for new, old in mapping.items():
97-
lines = [line.replace(old, f"lightning/{new}") for line in lines]
98-
with open(manifest_path, mode="w") as fp:
99-
fp.writelines(lines)
100-
else:
101-
manifest_path = os.path.join(manifest_dir, "MANIFEST.in")
102-
assert os.path.exists(manifest_path)
103-
# avoid error: setup script specifies an absolute path
104-
manifest_path = os.path.relpath(manifest_path, _PATH_ROOT)
105-
setuptools.command.egg_info.manifest_maker.template = manifest_path
106-
yield
107-
# cleanup
108-
setuptools.command.egg_info.manifest_maker.template = "MANIFEST.in"
109-
if aggregate:
110-
os.remove(manifest_path)
111-
112-
11372
if __name__ == "__main__":
11473
setup_tools = _load_py_module(name="setup_tools", location=os.path.join(_PATH_ROOT, ".actions", "setup_tools.py"))
11574
assistant = _load_py_module(name="assistant", location=os.path.join(_PATH_ROOT, ".actions", "assistant.py"))
@@ -129,19 +88,13 @@ def _set_manifest_path(manifest_dir: str, aggregate: bool = False) -> Generator:
12988
# should have included only the relevant files of the package to install
13089
possible_packages = _PACKAGE_MAPPING.values() if _PACKAGE_NAME is None else [_PACKAGE_MAPPING[_PACKAGE_NAME]]
13190
for pkg in possible_packages:
132-
pkg_path = os.path.join(_PATH_SRC, pkg)
133-
pkg_setup = os.path.join(pkg_path, "__setup__.py")
91+
pkg_setup = os.path.join(_PATH_SRC, pkg, "__setup__.py")
13492
if os.path.exists(pkg_setup):
13593
print(f"{pkg_setup} exists. Running `setuptools.setup`")
13694
setup_module = _load_py_module(name=f"{pkg}_setup", location=pkg_setup)
137-
setup_args = setup_module._setup_args()
138-
if _PACKAGE_NAME is None:
139-
# we are installing a wheel, no need for MANIFEST.in things
140-
setuptools.setup(**setup_args)
141-
else:
142-
# we are installing from source, set the correct manifest path
143-
with _set_manifest_path(pkg_path, aggregate=pkg == "lightning"):
144-
setuptools.setup(**setup_args)
95+
setup_module._adjust_manifest(pkg_name=pkg)
96+
setup_args = setup_module._setup_args(pkg_name=pkg)
97+
setup(**setup_args)
14598
break
14699
else:
147100
raise RuntimeError(f"Something's wrong, no package was installed. Package name: {_PACKAGE_NAME}")

src/lightning/MANIFEST.in

Whitespace-only changes.

src/lightning/__setup__.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,28 @@ def _load_py_module(name: str, location: str) -> ModuleType:
2424
_SETUP_TOOLS = _load_py_module("setup_tools", os.path.join(_PROJECT_ROOT, ".actions", "setup_tools.py"))
2525

2626

27-
def _setup_args() -> Dict[str, Any]:
27+
def _adjust_manifest(**kwargs: Any) -> None:
28+
# todo: consider rather aggregation of particular manifest adjustments
29+
manifest_path = os.path.join(_PROJECT_ROOT, "MANIFEST.in")
30+
assert os.path.isfile(manifest_path)
31+
with open(manifest_path) as fp:
32+
lines = [ln.rstrip() for ln in fp.readlines()]
33+
lines += [
34+
"recursive-include src/lightning *.md",
35+
"recursive-include requirements *.txt",
36+
"recursive-include src/lightning/app/ui *",
37+
"recursive-include src/lightning/cli/*-template *", # Add templates as build-in
38+
"include src/lightning/app/components/serve/catimage.png" + os.linesep,
39+
# fixme: this is strange, this shall work with setup find package - include
40+
"prune src/lightning_app",
41+
"prune src/lightning_lite",
42+
"prune src/pytorch_lightning",
43+
]
44+
with open(manifest_path, "w") as fp:
45+
fp.writelines([ln + os.linesep for ln in lines])
46+
47+
48+
def _setup_args(**kwargs: Any) -> Dict[str, Any]:
2849
_about = _load_py_module("about", os.path.join(_PACKAGE_ROOT, "__about__.py"))
2950
_version = _load_py_module("version", os.path.join(_PACKAGE_ROOT, "__version__.py"))
3051
_long_description = _SETUP_TOOLS.load_readme_description(

src/lightning_app/MANIFEST.in

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/lightning_app/__setup__.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,28 @@ def _prepare_extras() -> Dict[str, Any]:
4141
return extras
4242

4343

44-
def _setup_args() -> Dict[str, Any]:
44+
def _adjust_manifest(**__: Any) -> None:
45+
manifest_path = os.path.join(_PROJECT_ROOT, "MANIFEST.in")
46+
assert os.path.isfile(manifest_path)
47+
with open(manifest_path) as fp:
48+
lines = fp.readlines()
49+
lines += [
50+
"recursive-exclude src *.md" + os.linesep,
51+
"recursive-exclude requirements *.txt" + os.linesep,
52+
"recursive-include src/lightning_app *.md" + os.linesep,
53+
"include src/lightning_app/components/serve/catimage.png" + os.linesep,
54+
"recursive-include requirements/app *.txt" + os.linesep,
55+
"recursive-include src/lightning_app/cli/*-template *" + os.linesep, # Add templates
56+
]
57+
58+
# TODO: remove this once lightning-ui package is ready as a dependency
59+
lines += ["recursive-include src/lightning_app/ui *" + os.linesep]
60+
61+
with open(manifest_path, "w") as fp:
62+
fp.writelines(lines)
63+
64+
65+
def _setup_args(**__: Any) -> Dict[str, Any]:
4566
_path_setup_tools = os.path.join(_PROJECT_ROOT, ".actions", "setup_tools.py")
4667
_setup_tools = _load_py_module("setup_tools", _path_setup_tools)
4768
_about = _load_py_module("about", os.path.join(_PACKAGE_ROOT, "__about__.py"))

src/lightning_lite/MANIFEST.in

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/lightning_lite/__setup__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,26 @@ def _prepare_extras() -> Dict[str, Any]:
4242
return extras
4343

4444

45-
def _setup_args() -> Dict[str, Any]:
45+
def _adjust_manifest(**__: Any) -> None:
46+
manifest_path = os.path.join(_PROJECT_ROOT, "MANIFEST.in")
47+
assert os.path.isfile(manifest_path)
48+
with open(manifest_path) as fp:
49+
lines = fp.readlines()
50+
lines += [
51+
"recursive-exclude src *.md" + os.linesep,
52+
"recursive-exclude requirements *.txt" + os.linesep,
53+
"recursive-include requirements/lite *.txt" + os.linesep,
54+
"recursive-include src/lightning_lite *.md" + os.linesep,
55+
]
56+
57+
# TODO: remove this once lightning-ui package is ready as a dependency
58+
lines += ["recursive-include src/lightning_app/ui *" + os.linesep]
59+
60+
with open(manifest_path, "w") as fp:
61+
fp.writelines(lines)
62+
63+
64+
def _setup_args(**__: Any) -> Dict[str, Any]:
4665
_path_setup_tools = os.path.join(_PROJECT_ROOT, ".actions", "setup_tools.py")
4766
_setup_tools = _load_py_module("setup_tools", _path_setup_tools)
4867
_about = _load_py_module("about", os.path.join(_PACKAGE_ROOT, "__about__.py"))

0 commit comments

Comments
 (0)