Closed lpsinger closed 1 year ago
Hmm. I never used the template thingy in my projects, so I am not sure what is the correct solution here. Looks like astropy core is using this too. Maybe @astrofrog or @Cadair can comment.
Thanks for bringing this to our attention!
This was added because people wanted the version to be updated correctly without re-running pip
when using an editable install, but I agree that we don't really want that for installed stable versions. Maybe we can do something simple like check if a git repository is present one level up before trying to import setuptools_scm
?
Yes, that would do it.
Sorry if I'm missing something here, but once setuptools_scm
sets the __version__
value, during install, would it still be imported? That is, in a production environment, with fixed package versions, do we need to worry about this? Or is the concern production/test environments where packages are reinstalled every time?
@astrofrog, why not check to see whether __version__
is already set? Or does that create a circular situation?
I can open a PR here introducing the same system as the astropy main package now uses, we copied this to our projects as well and it works great but is a bit of a pain to setup.
It would thus be great to have it in the template.
You can see a stripped-down example here: https://github.com/cta-observatory/project-template-python-pure/tree/main/src/project_template_python_pure
Note the version.py
and _dev_version/__init__.py
files and the corresponding settings in setup.cfg and MANIFEST.in
The version.py template (the
VERSION_TEMPLATE
string constant in setup.py) unconditionally attempts to importsetuptools_scm
:setuptools_scm
is an expensive import because it importspkg_resources
, which enumerates all installed packages (see pypa/setuptools#926). On my MacBook with an SSD, this is the main cost of importing any Astropy affiliated package, adding 0.3 seconds of overhead. I have seenimport pkg_resources
orimport setuptools_scm
take seconds or more on NFS filesystems on computing clusters. It should be avoided where possible.