-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
python setup.py develop fails with version = attr: pkg.__version__
in setup.cfg
#1724
Comments
@kohr-h First of all, thank you for the thorough and easy-to-reproduce bug report, and sorry for the delay in responding. Unfortunately, I do not think that it can be fixed at all, much less elegantly. By pulling the version attribute from the package, you need to be able to import the package itself as part of the build, which means you now have as a build-time dependency all the runtime dependencies that are imported when importing your package. I do not think there's anything we can do without actually changing import semantics, and it's not a workflow we're particularly keen to support anyway. I have verified that this still breaks with I think your best options are to either try a different method of single-sourcing your versions, there are several listed here (though I can't say I recommend many of them, the first one in particular sounds horrible). One common option is to store the version in source control (e.g. git tags, see setuptools_scm) and generate a You could also add all your relevant runtime dependencies as build-time dependencies in your I hope that this has been helpful! |
@pganssle Thanks a lot for your detailed reply. I understand that the issue sits too deep and would require too far-reaching changes to be resolved.
in I'll close the issue. |
I have accidentally stumbled upon a workaround for this issue:
The reason this works is because the install process parses Given that the workaround relies on this specific implementation detail, I can't say I would necessarily recommend this approach. |
Confused here, since setuptools docs read:
Does that not apply to
Where |
Yeah, I'm confused by that also. As far as I can tell, it's not limited to editable installs: I think this is the relevant PR: #1753 |
After looking into that code a little bit, I think what does work is just assigning The AST parsing only looks for assignments at the module top-level, and falls back on loading the module. |
As far as I know, the Working example from @pganssle 's own: But perhaps that's because |
#1753 looks to have been incorporated in release 46.4.0 https://setuptools.readthedocs.io/en/latest/history.html#v46-4-0, which specifically mentions
So, yeah, confused all around 😦 |
Note that in It seems that as long as you either 1. have no third party imports or 2. point the |
Yes, though one small correction - those two conditions need a boolean-AND, not or :). I'm going to venture that 90% of packages that declare a simple one-liner in a module outside of Example: mkdir pypa-1724
cd pypa-1724
mkdir -p src/package_a
touch README.md
echo '__version__ = "1.0.0"' > src/package_a/_version.py
echo 'import setuptools; setuptools.setup()' > setup.py
cat << EOF > src/package_a/__init__.py
from flask import Flask
from ._version import __version__
EOF
cat << EOF > setup.cfg
[metadata]
name = package-a
version = attr:package_a._version.__version__
description = foo
long_description = file: README.md
long_description_content_type = text/markdown
license = Apache-2.0
[options]
packages = find:
install_requires =
flask
importlib_resources;python_version<"3.7"
include_package_data = True
package_dir =
=src
[options.packages.find]
where = src
EOF Then: python3 -m venv venv
. ./venv/bin/activate
python3 -m pip install -e . Breaks with:
whereas removing the |
The problem here appears to be that Moving it to mkdir pypa-1724
cd pypa-1724
mkdir -p src/package_a
touch README.md
echo 'import setuptools; setuptools.setup()' > setup.py
cat << EOF > src/package_a/__init__.py
from flask import Flask
__version__ = "1.0.0"
EOF
cat << EOF > setup.cfg
[metadata]
name = package-a
version = attr:package_a.__version__
description = foo
long_description = file: README.md
long_description_content_type = text/markdown
license = Apache-2.0
[options]
packages = find:
install_requires =
flask
importlib_resources;python_version<"3.7"
include_package_data = True
package_dir =
=src
[options.packages.find]
where = src
EOF
|
Right - I am probably glossing over some details from #1753, but that changelog entries reads as if this was the exact situation that is avoided by the ast-based finder. |
Very nice feature, but causes problems with fresh installs. Essentially causes the package to be imported, which trickles down to a numpy and/or scipy import. These are listed in the install requires section, but the version search is done first. Placing the explicit version in the setup.cfg means this has to be updated at releases, but makes a completely fresh install possible. Related GH issues / workarounds: pypa/setuptools#1724 pypa/pip#6350
setuptools >= 46.4.0 has rudimentary AST analysis for attr: balsam.__version to work without importing balsam (and hence possibly failing due to missing external dependencies imported in __init__.py) But __version__ must be in __init__.py and must be a hardcoded string pypa/setuptools#1724
Fix for __version__: see pypa/setuptools#1724 (comment)
Fix for __version__: see pypa/setuptools#1724 (comment)
Addressing problem caused by pypa/setuptools#1724 Accessing the version attribute could cause odd dependencies on import statement ordering as to whether importing succeeded or failed
This works if I edit @kohr-h's minimal example to add the full path to
I guess AST requires this full path to import It doesn't, however, work for importing classes, such as for cmd_class. |
For future reference, I managed to work around this error by using |
This doesn't appear to work with namespace packages. I tried @ThomasTNO's workaround but no luck. |
…all -e . This is because setuptools tries to import the msticpy package before dependencies are fully installed. See pypa/setuptools#1724
* Moving most setup config to setup.cfg Extras couldn't be moved there since we have multiple overlapping extra groups. Updated import_analyzer.py to avoid creating copy of setup.py * Add Pipfile creation to create_reqs_all.py * Trying to get the version in setup.cfg causes a failure with pip install -e . This is because setuptools tries to import the msticpy package before dependencies are fully installed. See pypa/setuptools#1724 Co-authored-by: Pete Bryan <[email protected]>
With setuptools==46.1.3, I got this to work. In setup.cfg:
In my init.py:
|
* Moving most setup config to setup.cfg Extras couldn't be moved there since we have multiple overlapping extra groups. Updated import_analyzer.py to avoid creating copy of setup.py * Add Pipfile creation to create_reqs_all.py * Trying to get the version in setup.cfg causes a failure with pip install -e . This is because setuptools tries to import the msticpy package before dependencies are fully installed. See pypa/setuptools#1724 Co-authored-by: Pete Bryan <[email protected]>
* using attr: can cause issues when other dependencies are not installed in the environment. If all of the dependencies are installed, then installation is successful (but that requires manual installation of all of the dependencies prior to installing ichor). Thus, for now put in the version manually instead of importing from __init__ file. See pypa/setuptools#1724
* Migrate setup.py completely to pyproject.toml * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove zipsafe from pyproject.toml * Update pyproject.toml * Try changing attr path pypa/setuptools#1724 * Pin setuptools for PEP660 editable installs Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Fix for __version__: see pypa/setuptools#1724 (comment)
See also pypa/pip#6350
When a package has
version = attr: pkg.__version__
in itssetup.cfg
file,python setup.py develop
can fail with aModuleNotFoundError
if not all runtime dependencies have been installed yet.I've created a minimal repo to reproduce the error: https://github.com/kohr-h/minimal
Reproducing the error:
python
inside, but withoutnumpy
(our example dependency)python setup.py develop
in the repo rootWorkaround:
numpy
as wellpython setup.py develop
succeedsTraceback
I wonder whether this can be fixed elegantly and does not sit too deep.
The text was updated successfully, but these errors were encountered: