summaryrefslogtreecommitdiffstats
path: root/packaging/pep517_backend/_backend.py
diff options
context:
space:
mode:
authorSviatoslav Sydorenko <webknjaz@redhat.com>2023-03-20 19:26:53 +0100
committerGitHub <noreply@github.com>2023-03-20 19:26:53 +0100
commit888abf5d6e13880ba82d02c5f8a57ca1f90a992f (patch)
tree539da32060efcadaa5637e0670f45fe30c35693a /packaging/pep517_backend/_backend.py
parentUpdate special_variables.rst (#80210) (diff)
downloadansible-888abf5d6e13880ba82d02c5f8a57ca1f90a992f.tar.xz
ansible-888abf5d6e13880ba82d02c5f8a57ca1f90a992f.zip
Make isolated source changes @ PEP 517 backend (#80253)
Diffstat (limited to '')
-rw-r--r--packaging/pep517_backend/_backend.py61
1 files changed, 45 insertions, 16 deletions
diff --git a/packaging/pep517_backend/_backend.py b/packaging/pep517_backend/_backend.py
index d4451ac14e..0f1dc647e5 100644
--- a/packaging/pep517_backend/_backend.py
+++ b/packaging/pep517_backend/_backend.py
@@ -7,10 +7,24 @@ import subprocess
import sys
import typing as t
from configparser import ConfigParser
-from contextlib import suppress
+from contextlib import contextmanager, suppress
from importlib.metadata import import_module
from io import StringIO
from pathlib import Path
+from shutil import copytree
+from tempfile import TemporaryDirectory
+
+try:
+ from contextlib import chdir as _chdir_cm
+except ImportError:
+ @contextmanager
+ def _chdir_cm(path: os.PathLike) -> t.Iterator[None]:
+ original_wd = Path.cwd()
+ os.chdir(path)
+ try:
+ yield
+ finally:
+ os.chdir(original_wd)
from setuptools.build_meta import (
build_sdist as _setuptools_build_sdist,
@@ -33,6 +47,13 @@ BUILD_MANPAGES_CONFIG_SETTING = '--build-manpages'
"""Config setting name toggle that is used to request manpage in sdists."""
+@contextmanager
+def _run_in_temporary_directory() -> t.Iterator[Path]:
+ with TemporaryDirectory(prefix='.tmp-ansible-pep517-') as tmp_dir:
+ with _chdir_cm(tmp_dir):
+ yield Path(tmp_dir)
+
+
def _make_in_tree_ansible_importable() -> None:
"""Add the library directory to module lookup paths."""
lib_path = str(Path.cwd() / 'lib/')
@@ -93,21 +114,29 @@ def build_sdist( # noqa: WPS210, WPS430
build_manpages_requested = BUILD_MANPAGES_CONFIG_SETTING in (
config_settings or {}
)
- if build_manpages_requested:
- Path('docs/man/man1/').mkdir(exist_ok=True, parents=True)
- version_number = _get_package_distribution_version()
- for rst_in in _generate_rst_in_templates():
- _convert_rst_in_template_to_manpage(
- rst_doc_template=rst_in.read_text(),
- destination_path=rst_in.with_suffix('').with_suffix(''),
- version_number=version_number,
- )
- rst_in.unlink()
-
- return _setuptools_build_sdist(
- sdist_directory=sdist_directory,
- config_settings=config_settings,
- )
+ original_src_dir = Path.cwd().resolve()
+ with _run_in_temporary_directory() as tmp_dir:
+ tmp_src_dir = Path(tmp_dir) / 'src'
+ copytree(original_src_dir, tmp_src_dir)
+ os.chdir(tmp_src_dir)
+
+ if build_manpages_requested:
+ Path('docs/man/man1/').mkdir(exist_ok=True, parents=True)
+ version_number = _get_package_distribution_version()
+ for rst_in in _generate_rst_in_templates():
+ _convert_rst_in_template_to_manpage(
+ rst_doc_template=rst_in.read_text(),
+ destination_path=rst_in.with_suffix('').with_suffix(''),
+ version_number=version_number,
+ )
+ rst_in.unlink()
+
+ built_sdist_basename = _setuptools_build_sdist(
+ sdist_directory=sdist_directory,
+ config_settings=config_settings,
+ )
+
+ return built_sdist_basename
def get_requires_for_build_sdist(