-
-
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
Unexpected behavior when distutils is invoked before Setuptools #2230
Comments
Thanks for the report. Setuptools 49.1 is out, should address the issue for early adopters while I triage and correct the issue. |
I'm able to replicate the failure:
Note the warning "Setuptools is replacing distutils". That was meant to be a hard failure, except that PyPy somehow ends up with distutils unconditionally imported during interpreter startup. |
I'm able to work around the issue by ensuring that
|
Also using PEP 517:
|
It also works with this diff on ansible: diff --git a/setup.py b/setup.py
index 0398473d5e..7c86075495 100644
--- a/setup.py
+++ b/setup.py
@@ -9,8 +9,6 @@ import sys
import warnings
from collections import defaultdict
-from distutils.command.build_scripts import build_scripts as BuildScripts
-from distutils.command.sdist import sdist as SDist
try:
from setuptools import setup, find_packages
@@ -23,6 +21,9 @@ except ImportError:
" install setuptools).", file=sys.stderr)
sys.exit(1)
+from distutils.command.build_scripts import build_scripts as BuildScripts
+from distutils.command.sdist import sdist as SDist
+
sys.path.insert(0, os.path.abspath('lib'))
from ansible.release import __version__, __author__ The underlying issue is that with setuptools 48, you cannot import distutils before setuptools. My recommendation is to (a) move the imports so distutils imports come after setuptools (quick, painless, compatible), then (b) adopt PEP 517 and use pep517 to build your sdists. I'll update the changelog to make this change more clear. |
In the referenced commit, I've updated the changelog to clarify the weaknesses identified from this bug report and guide users to the best practices. Can you confirm that this guidance and applying the recommended changes in Ansible addresses the concern? |
This change addresses the deprecation of the use of stdlib `distutils`. It's a short-term hotfix for the problem and we'll need to consider dropping the use of `distutils` from our `setup.py`. Refs: * ansible#70456 * pypa/setuptools#2230 * pypa/setuptools@bd110264
This change addresses the deprecation of the use of stdlib `distutils`. It's a short-term hotfix for the problem and we'll need to consider dropping the use of `distutils` from our `setup.py`. Refs: * ansible#70456 * pypa/setuptools#2230 * pypa/setuptools@bd110264 Co-Authored-By: Jason R. Coombs <jaraco@jaraco.com>
I've submitted the patch that you suggested and it'll probably get us going short-term. But we cannot use pyproject.toml atm, nor we ship wheels. The reason is that we have a bunch of symlinks that need to be preserved and it's done by distutils but not setuptools. |
This change addresses the deprecation of the use of stdlib `distutils`. It's a short-term hotfix for the problem and we'll need to consider dropping the use of `distutils` from our `setup.py`. Refs: * ansible#70456 * pypa/setuptools#2230 * pypa/setuptools@bd110264 Co-Authored-By: Jason R. Coombs <jaraco@jaraco.com>
Great. Thanks for enacting that. I'm wondering if there's something that Setuptools should do here to help other projects with similar usages from encountering the same issue as we bring the adopted distutils back. For example, the project could:
I think I'll enact (1) now and give it some time to percolate over the weekend and maybe longer. Do please consider filing something with Ansible to investigate a long-term solution for what Ansible will do when distutils is sunset and all that's left is Setuptools (as that's the plan). |
setuptools>=48
breaks Ansible's sdist build process…direct users to the recommended usage. Closes #2230.
…direct users to the recommended usage. Closes #2230.
This seems a bit heavy handed. Requiring specific import order is a bad practice that makes for fragile code. Is it possible to have a more refined detection of the problem you are trying to avoid? |
The problem we're trying to avoid is that Setuptools wishes to ensure that anything the user has imported is imported after Setuptools has ensured that Ideally, most users should be able to simply import everything from Setuptools. I did consider another approach, where Setuptools could add a I elected for the current approach as it's more surgical. |
Can you explain what the actual problem is that requires controlling the import order? specifically in my case I am using distutils.cmd.Command. I noticed that there is a Command in setuptools but it seems different. |
|
We also run into this warning in pandas, where we use |
That worked, next in line is a distutils.log usage I have :
and I am not seeing those constants in setuptools. Are they already ported? |
* Fix building Ansible dist w/ setuptools>=48,<49.1 This change addresses the deprecation of the use of stdlib `distutils`. It's a short-term hotfix for the problem and we'll need to consider dropping the use of `distutils` from our `setup.py`. Refs: * #70456 * pypa/setuptools#2230 * pypa/setuptools@bd110264 Co-Authored-By: Jason R. Coombs <jaraco@jaraco.com> * Add a change note for PR #70525 Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
* Fix building Ansible dist w/ setuptools>=48,<49.1 This change addresses the deprecation of the use of stdlib `distutils`. It's a short-term hotfix for the problem and we'll need to consider dropping the use of `distutils` from our `setup.py`. Refs: * ansible#70456 * pypa/setuptools#2230 * pypa/setuptools@bd110264 Co-Authored-By: Jason R. Coombs <jaraco@jaraco.com> * Add a change note for PR ansible#70525 Co-authored-by: Jason R. Coombs <jaraco@jaraco.com> (cherry picked from commit 918388b)
…#70529) (#70760) * Fix building Ansible dist w/ setuptools>=48,<49.1 (#70525) * Fix building Ansible dist w/ setuptools>=48,<49.1 This change addresses the deprecation of the use of stdlib `distutils`. It's a short-term hotfix for the problem and we'll need to consider dropping the use of `distutils` from our `setup.py`. Refs: * #70456 * pypa/setuptools#2230 * pypa/setuptools@bd110264 Co-Authored-By: Jason R. Coombs <jaraco@jaraco.com> * Add a change note for PR #70525 Co-authored-by: Jason R. Coombs <jaraco@jaraco.com> (cherry picked from commit 918388b) * Guard against allowing ansible to ansible-base upgrades (#70529) * Guard against allowing ansible to ansible-base upgrades * newline * use alias * Add an explicit line detailing this is a 1 time thing * period * Read __version__ and __author__ rather than import, update working, and add ability to skip conflict checks * Remove commented code * Re introduce removed changes from rebase * Just use open * Nuke unused import (cherry picked from commit 54b002e) Co-authored-by: Sviatoslav Sydorenko <webknjaz@redhat.com>
Hi, I am also facing this issue with latest version of setup tools v50.0.0. After downgrading the version worked for me. |
@vklohiya this behavior has been re-introduced. You may temporarily revert back to the old one by setting |
TL;DR We are forced to use distutils because setuptools has broken symlink processing and this causes
distutils.errors.DistutilsClassError: command class <class '__main__.SDistCommand'> must subclass Command
.It works with
setuptools<48
and the changelog doesn't document any breaking behaviors for this version.Repro:
(tried under Python 3.8)
Ref: ansible/ansible#70456
The text was updated successfully, but these errors were encountered: