Skip to content

Instantly share code, notes, and snippets.

@flying-sheep
Created December 2, 2020 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flying-sheep/9e7776f4cbe967397702e1c581e3a40a to your computer and use it in GitHub Desktop.
Save flying-sheep/9e7776f4cbe967397702e1c581e3a40a to your computer and use it in GitHub Desktop.
Use flit metadata from setup.py
"""Temporary setuptools bridge
Don't use this except if you have a deadline or you encounter a bug.
"""
import re
import setuptools
from pathlib import Path
from flit_core import common, config
from setuptools_scm.integration import find_files
field_names = dict(
{n: n for n in "name version author author_email license classifiers".split()},
description="summary",
long_description="description",
long_description_content_type="description_content_type",
python_requires="requires_python",
url="home_page",
)
def setup_args(config_path=Path("pyproject.toml")):
cfg = config.read_flit_config(config_path)
module = common.Module(cfg.module, config_path.parent)
metadata = common.make_metadata(module, cfg)
kwargs = {}
for st_field, metadata_field in field_names.items():
val = getattr(metadata, metadata_field, None)
if val is not None:
kwargs[st_field] = val
elif metadata_field not in {'license'}:
print(f'{metadata_field} not found in {dir(metadata)}')
kwargs["packages"] = setuptools.find_packages(include=[metadata.name + "*"])
if metadata.requires_dist:
kwargs["install_requires"] = [
req for req in metadata.requires_dist if "extra ==" not in req
]
if cfg.reqs_by_extra:
kwargs["extras_require"] = cfg.reqs_by_extra
scripts = cfg.entrypoints.get("console_scripts")
if scripts is not None:
kwargs["entry_points"] = dict(
console_scipts=[" = ".join(ep) for ep in scripts.items()]
)
kwargs["include_package_data"] = True
kwargs["package_data"] = {
module.name: [
re.escape(f[len(module.name) + 1:]) for f in find_files(module.path)
]
}
return kwargs
# print(*[f'{p}={v!r}' for p, v in setup_args().items()], sep='\n')
setuptools.setup(**setup_args())
@ivirshup
Copy link

I ran

conda create -n scanpy-flit python=3.8 flit
conda activate scanpy-flit
pip install -e .

And got:

From pip install -e .

Obtaining file:///Users/isaac/github/scanpy
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
    Preparing wheel metadata ... done
Installing collected packages: scanpy
  Running setup.py develop for scanpy
Successfully installed scanpy

from python -c "import scanpy"

Traceback (most recent call last):
  File "/Users/isaac/github/scanpy/scanpy/_metadata.py", line 7, in <module>
    from setuptools_scm import get_version
ModuleNotFoundError: No module named 'setuptools_scm'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/isaac/github/scanpy/scanpy/__init__.py", line 3, in <module>
    from ._metadata import __version__, __author__, __email__, within_flit
  File "/Users/isaac/github/scanpy/scanpy/_metadata.py", line 17, in <module>
    from ._compat import pkg_metadata
  File "/Users/isaac/github/scanpy/scanpy/_compat.py", line 1, in <module>
    from packaging import version
ModuleNotFoundError: No module named 'packaging'

From conda list

# packages in environment at /Users/isaac/miniconda3/envs/scanpy-flit:
#
# Name                    Version                   Build  Channel
brotlipy                  0.7.0           py38h9ed2024_1003  
ca-certificates           2020.12.8            hecd8cb5_0  
certifi                   2020.12.5        py38hecd8cb5_0  
cffi                      1.14.4           py38h2125817_0  
chardet                   4.0.0           py38hecd8cb5_1003  
cryptography              3.3.1            py38hbcfaee0_0  
docutils                  0.16                     py38_1  
flit                      3.0.0                      py_0  
flit-core                 3.0.0                      py_0  
idna                      2.10                       py_0  
libcxx                    10.0.0                        1  
libedit                   3.1.20191231         h1de35cc_1  
libffi                    3.3                  hb1e8313_2  
ncurses                   6.2                  h0a44026_1  
openssl                   1.1.1i               h9ed2024_0  
pip                       20.3.3           py38hecd8cb5_0  
pycparser                 2.20                       py_2  
pyopenssl                 20.0.1             pyhd3eb1b0_1  
pysocks                   1.7.1                    py38_1  
python                    3.8.5                h26836e1_1  
pytoml                    0.1.21                     py_0  
readline                  8.0                  h1de35cc_0  
requests                  2.25.1             pyhd3eb1b0_0  
requests_download         0.1.2                      py_1  
scanpy                    1.7.0rc2.dev5+g1a51e659           dev_0    <develop>
setuptools                51.1.2           py38hecd8cb5_4  
six                       1.15.0           py38hecd8cb5_0  
sqlite                    3.33.0               hffcf06c_0  
tk                        8.6.10               hb0a8c7a_0  
urllib3                   1.26.2             pyhd3eb1b0_0  
wheel                     0.36.2             pyhd3eb1b0_0  
xz                        5.2.5                h1de35cc_0  
zlib                      1.2.11               h1de35cc_3  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment