summaryrefslogtreecommitdiff
path: root/setuptools/command
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2022-06-25 20:04:49 +0100
committerGitHub <noreply@github.com>2022-06-25 20:04:49 +0100
commit2ee94e7e40379d348cdadbb747fbbcf5a6f228c6 (patch)
tree9df2f7a96c125520c4fbc8478019aebbd5a4782e /setuptools/command
parent700237e252e45cb465c1013fe41ad43092fccf1a (diff)
parent54795137d0c3febaf553df15d0b0e2e8c894150a (diff)
downloadpython-setuptools-git-2ee94e7e40379d348cdadbb747fbbcf5a6f228c6.tar.gz
sdist: Add files from build subcommands - get_source_files (#3412)
Diffstat (limited to 'setuptools/command')
-rw-r--r--setuptools/command/build.py16
-rw-r--r--setuptools/command/sdist.py14
2 files changed, 30 insertions, 0 deletions
diff --git a/setuptools/command/build.py b/setuptools/command/build.py
index bf4f71a7..c35dc3fc 100644
--- a/setuptools/command/build.py
+++ b/setuptools/command/build.py
@@ -65,6 +65,11 @@ class SubCommand(Protocol):
of ``get_output_mapping()``. Alternatively, ``setuptools`` **MAY** attempt to use
:doc:`import hooks <python:reference/import>` to redirect any attempt to import
to the directory with the original source code and other files built in place.
+
+ Please note that custom sub-commands **SHOULD NOT** rely on ``run()`` being
+ executed (or not) to provide correct return values for ``get_outputs()``,
+ ``get_output_mapping()`` or ``get_source_files()``. The ``get_*`` methods should
+ work independently of ``run()``.
"""
editable_mode: bool = False
@@ -106,6 +111,17 @@ class SubCommand(Protocol):
def run(self):
"""(Required by the original :class:`setuptools.Command` interface)"""
+ def get_source_files(self) -> List[str]:
+ """
+ Return a list of all files that are used by the command to create the expected
+ outputs.
+ For example, if your build command transpiles Java files into Python, you should
+ list here all the Java files.
+ The primary purpose of this function is to help populating the ``sdist``
+ with all the files necessary to build the distribution.
+ All files should be strings relative to the project root directory.
+ """
+
def get_outputs(self) -> List[str]:
"""
Return a list of files intended for distribution as they would have been
diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py
index 0ffeacf3..4a8cde7e 100644
--- a/setuptools/command/sdist.py
+++ b/setuptools/command/sdist.py
@@ -4,10 +4,12 @@ import os
import sys
import io
import contextlib
+from itertools import chain
from .py36compat import sdist_add_defaults
from .._importlib import metadata
+from .build import _ORIGINAL_SUBCOMMANDS
_default_revctrl = list
@@ -100,6 +102,10 @@ class sdist(sdist_add_defaults, orig.sdist):
if orig_val is not NoValue:
setattr(os, 'link', orig_val)
+ def add_defaults(self):
+ super().add_defaults()
+ self._add_defaults_build_sub_commands()
+
def _add_defaults_optional(self):
super()._add_defaults_optional()
if os.path.isfile('pyproject.toml'):
@@ -112,6 +118,14 @@ class sdist(sdist_add_defaults, orig.sdist):
self.filelist.extend(build_py.get_source_files())
self._add_data_files(self._safe_data_files(build_py))
+ def _add_defaults_build_sub_commands(self):
+ build = self.get_finalized_command("build")
+ missing_cmds = set(build.get_sub_commands()) - _ORIGINAL_SUBCOMMANDS
+ # ^-- the original built-in sub-commands are already handled by default.
+ cmds = (self.get_finalized_command(c) for c in missing_cmds)
+ files = (c.get_source_files() for c in cmds if hasattr(c, "get_source_files"))
+ self.filelist.extend(chain.from_iterable(files))
+
def _safe_data_files(self, build_py):
"""
Since the ``sdist`` class is also used to compute the MANIFEST