-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expose a subset of distutils C-compiler interface as public API #3445
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0aaaa8b
Expose a subset of distutils C-compiler interface as public API
neutrinoceros 5f3a097
add changelog fragment file
neutrinoceros 13108ed
Apply suggestions from code review
neutrinoceros d0c49cf
Apply suggestions from code review
neutrinoceros a929a2a
fix F401 lint errors
neutrinoceros File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Re-exposed a subset of ``distutils.ccompiler`` and ``distutils.sysconfig`` | ||
modules as ``setuptools.ccompiler``. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Expose a subset of distutils as public API | ||
# to help with migration to Python 3.12 | ||
|
||
from distutils.ccompiler import CCompiler | ||
from distutils.ccompiler import new_compiler | ||
|
||
|
||
__all__ = [ | ||
"CCompiler", | ||
"new_compiler", | ||
"customize_compiler", | ||
] | ||
|
||
|
||
def customize_compiler(compiler: CCompiler): | ||
"""Do any platform-specific customization of a CCompiler instance. | ||
|
||
Mainly needed on Unix, so we can plug in the information that | ||
varies across Unices and is stored in Python's Makefile. | ||
""" | ||
# Importing `distutils.sysconfig` directly may change the global state. | ||
# We adopt a lazy approach instead. | ||
from distutils.sysconfig import customize_compiler as _customize | ||
|
||
return _customize(compiler) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from setuptools.ccompiler import CCompiler | ||
from setuptools.ccompiler import customize_compiler | ||
from setuptools.ccompiler import new_compiler | ||
|
||
import pytest | ||
|
||
|
||
def test_ccompiler_namespace(_avoid_permanent_changes_in_sysconfig): | ||
ccompiler = new_compiler() | ||
customize_compiler(ccompiler) | ||
assert hasattr(ccompiler, "compile") | ||
neutrinoceros marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert CCompiler.compiler_type is None | ||
|
||
|
||
@pytest.fixture | ||
def _avoid_permanent_changes_in_sysconfig(monkeypatch): | ||
import importlib | ||
import sys | ||
|
||
# Avoid caching `distutils.sysconfig` and force it to be re-imported later. | ||
# This should "cancel out" any permanent changes that comes as a side-effect of | ||
# import thing `distutils.sysconfig`. | ||
monkeypatch.setattr(sys, "modules", sys.modules.copy()) | ||
yield | ||
importlib.invalidate_caches() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.