Skip to content

Commit 652a293

Browse files
committed
Add setup.py, leaving it ignored by flit
1 parent c3e1576 commit 652a293

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ __pycache__/
99
/build/
1010
/dist/
1111
/*.egg-info/
12-
/setup.py
1312

1413
# Tests and coverage
1514
/.pytest_cache/

pyproject.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ test = [
7676
]
7777

7878
[tool.flit.sdist]
79-
exclude = ['anndata/tests']
79+
exclude = [
80+
'anndata/tests',
81+
'setup.py',
82+
]
8083

8184
[tool.coverage.run]
8285
source = ['anndata']

setup.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""Temporary setuptools bridge
2+
Don't use this except if you have a deadline or you encounter a bug.
3+
"""
4+
import re
5+
import sys
6+
from warnings import warn
7+
8+
import setuptools
9+
from pathlib import Path
10+
11+
from flit_core import common, config
12+
from setuptools_scm.integration import find_files
13+
14+
15+
field_map = dict(
16+
description="summary",
17+
long_description="description",
18+
long_description_content_type="description_content_type",
19+
python_requires="requires_python",
20+
url="home_page",
21+
**{
22+
n: n
23+
for n in ["name", "version", "author", "author_email", "license", "classifiers"]
24+
},
25+
)
26+
27+
28+
def setup_args(config_path=Path("pyproject.toml")):
29+
cfg = config.read_flit_config(config_path)
30+
module = common.Module(cfg.module, config_path.parent)
31+
metadata = common.make_metadata(module, cfg)
32+
kwargs = {}
33+
for st_field, metadata_field in field_map.items():
34+
val = getattr(metadata, metadata_field, None)
35+
if val is not None:
36+
kwargs[st_field] = val
37+
else:
38+
msg = f"{metadata_field} not found in {dir(metadata)}"
39+
assert metadata_field in {"license"}, msg
40+
kwargs["packages"] = setuptools.find_packages(include=[metadata.name + "*"])
41+
if metadata.requires_dist:
42+
kwargs["install_requires"] = [
43+
req for req in metadata.requires_dist if "extra ==" not in req
44+
]
45+
if cfg.reqs_by_extra:
46+
kwargs["extras_require"] = cfg.reqs_by_extra
47+
scripts = cfg.entrypoints.get("console_scripts")
48+
if scripts is not None:
49+
kwargs["entry_points"] = dict(
50+
console_scipts=[" = ".join(ep) for ep in scripts.items()]
51+
)
52+
kwargs["include_package_data"] = True
53+
kwargs["package_data"] = {
54+
module.name: [
55+
re.escape(f[len(module.name) + 1 :]) for f in find_files(module.path)
56+
]
57+
}
58+
return kwargs
59+
60+
61+
if __name__ == "__main__":
62+
if "develop" in sys.argv:
63+
msg = (
64+
"Please use `flit install -s` or `flit install --pth-file` "
65+
"instead of `pip install -e`/`python setup.py develop` "
66+
"once https://github.com/pypa/pip/issues/9670 is fixed."
67+
)
68+
elif "install" in sys.argv:
69+
msg = 'Please use `pip install "$d"` instead of `python "$d/setup.py" install`'
70+
else:
71+
msg = "Please use `pip ...` or `flit ...` instead of `python setup.py ...`"
72+
warn(msg, FutureWarning)
73+
setuptools.setup(**setup_args())

0 commit comments

Comments
 (0)