-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setuptools.command.build (#3256)
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
Added setuptools.command.build command to match distutils.command.build -- by :user:`isuruf` |
This file contains 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 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,24 @@ | ||
from distutils.command.build import build as _build | ||
import warnings | ||
|
||
from setuptools import SetuptoolsDeprecationWarning | ||
|
||
|
||
_ORIGINAL_SUBCOMMANDS = {"build_py", "build_clib", "build_ext", "build_scripts"} | ||
|
||
|
||
class build(_build): | ||
# copy to avoid sharing the object with parent class | ||
sub_commands = _build.sub_commands[:] | ||
|
||
def run(self): | ||
subcommands = {cmd[0] for cmd in _build.sub_commands} | ||
if subcommands - _ORIGINAL_SUBCOMMANDS: | ||
msg = """ | ||
It seems that you are using `distutils.command.build.build` to add | ||
new subcommands. Using `distutils` directly is considered deprecated, | ||
please use `setuptools.command.build`. | ||
""" | ||
warnings.warn(msg, SetuptoolsDeprecationWarning) | ||
self.sub_commands = _build.sub_commands | ||
super().run() |
This file contains 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,63 @@ | ||
from contextlib import contextmanager | ||
from setuptools import Command, SetuptoolsDeprecationWarning | ||
from setuptools.dist import Distribution | ||
from setuptools.command.build import build | ||
from distutils.command.build import build as distutils_build | ||
|
||
import pytest | ||
|
||
|
||
def test_distribution_gives_setuptools_build_obj(tmpdir_cwd): | ||
""" | ||
Check that the setuptools Distribution uses the | ||
setuptools specific build object. | ||
""" | ||
|
||
dist = Distribution(dict( | ||
script_name='setup.py', | ||
script_args=['build'], | ||
packages=[], | ||
package_data={'': ['path/*']}, | ||
)) | ||
assert isinstance(dist.get_command_obj("build"), build) | ||
|
||
|
||
@contextmanager | ||
def _restore_sub_commands(): | ||
orig = distutils_build.sub_commands[:] | ||
try: | ||
yield | ||
finally: | ||
distutils_build.sub_commands = orig | ||
|
||
|
||
class Subcommand(Command): | ||
"""Dummy command to be used in tests""" | ||
|
||
def initialize_options(self): | ||
pass | ||
|
||
def finalize_options(self): | ||
pass | ||
|
||
def run(self): | ||
raise NotImplementedError("just to check if the command runs") | ||
|
||
|
||
@_restore_sub_commands() | ||
def test_subcommand_in_distutils(tmpdir_cwd): | ||
""" | ||
Ensure that sub commands registered in ``distutils`` run, | ||
after instructing the users to migrate to ``setuptools``. | ||
""" | ||
dist = Distribution(dict( | ||
packages=[], | ||
cmdclass={'subcommand': Subcommand}, | ||
)) | ||
distutils_build.sub_commands.append(('subcommand', None)) | ||
|
||
warning_msg = "please use .setuptools.command.build." | ||
with pytest.warns(SetuptoolsDeprecationWarning, match=warning_msg): | ||
# For backward compatibility, the subcommand should run anyway: | ||
with pytest.raises(NotImplementedError, match="the command runs"): | ||
dist.run_command("build") |