summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-02-20 12:31:39 -0500
committerJason R. Coombs <jaraco@jaraco.com>2021-02-20 12:31:39 -0500
commit5c57b5cc1e1d247fec64858d8cc4e93b5ffb11a3 (patch)
treee16493b2760299358227f348ee9bde25984ccabc
parente1ffc2abbae4f2aa78dd09ee9827d754b7702b7b (diff)
downloadpython-setuptools-git-5c57b5cc1e1d247fec64858d8cc4e93b5ffb11a3.tar.gz
Switch to jaraco.path for building files
-rw-r--r--setup.cfg1
-rw-r--r--setuptools/tests/files.py38
-rw-r--r--setuptools/tests/test_build_ext.py5
-rw-r--r--setuptools/tests/test_build_meta.py26
-rw-r--r--setuptools/tests/test_easy_install.py4
-rw-r--r--setuptools/tests/test_egg_info.py26
-rw-r--r--setuptools/tests/test_glob.py5
-rw-r--r--setuptools/tests/test_wheel.py4
8 files changed, 36 insertions, 73 deletions
diff --git a/setup.cfg b/setup.cfg
index e0c4edc2..2158905b 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -58,6 +58,7 @@ testing =
pip>=19.1 # For proper file:// URLs support.
jaraco.envs
pytest-xdist
+ jaraco.path
docs =
# Keep these in sync with docs/requirements.txt
diff --git a/setuptools/tests/files.py b/setuptools/tests/files.py
deleted file mode 100644
index 71194b9d..00000000
--- a/setuptools/tests/files.py
+++ /dev/null
@@ -1,38 +0,0 @@
-import os
-
-
-def build_files(file_defs, prefix=""):
- """
- Build a set of files/directories, as described by the
- file_defs dictionary.
-
- Each key/value pair in the dictionary is interpreted as
- a filename/contents
- pair. If the contents value is a dictionary, a directory
- is created, and the
- dictionary interpreted as the files within it, recursively.
-
- For example:
-
- {"README.txt": "A README file",
- "foo": {
- "__init__.py": "",
- "bar": {
- "__init__.py": "",
- },
- "baz.py": "# Some code",
- }
- }
- """
- for name, contents in file_defs.items():
- full_name = os.path.join(prefix, name)
- if isinstance(contents, dict):
- os.makedirs(full_name, exist_ok=True)
- build_files(contents, prefix=full_name)
- else:
- if isinstance(contents, bytes):
- with open(full_name, 'wb') as f:
- f.write(contents)
- else:
- with open(full_name, 'w') as f:
- f.write(contents)
diff --git a/setuptools/tests/test_build_ext.py b/setuptools/tests/test_build_ext.py
index 838fdb42..be03893a 100644
--- a/setuptools/tests/test_build_ext.py
+++ b/setuptools/tests/test_build_ext.py
@@ -2,12 +2,13 @@ import sys
import distutils.command.build_ext as orig
from distutils.sysconfig import get_config_var
+from jaraco import path
+
from setuptools.command.build_ext import build_ext, get_abi3_suffix
from setuptools.dist import Distribution
from setuptools.extension import Extension
from . import environment
-from .files import build_files
from .textwrap import DALS
@@ -106,7 +107,7 @@ def test_build_ext_config_handling(tmpdir_cwd):
build-base = foo_build
"""),
}
- build_files(files)
+ path.build(files)
code, output = environment.run_setup_py(
cmd=['build'], data_stream=(0, 2),
)
diff --git a/setuptools/tests/test_build_meta.py b/setuptools/tests/test_build_meta.py
index e117d8e6..f33a6968 100644
--- a/setuptools/tests/test_build_meta.py
+++ b/setuptools/tests/test_build_meta.py
@@ -5,8 +5,8 @@ import importlib
from concurrent import futures
import pytest
+from jaraco import path
-from .files import build_files
from .textwrap import DALS
@@ -130,7 +130,7 @@ class TestBuildMetaBackend:
@pytest.fixture(params=defns)
def build_backend(self, tmpdir, request):
- build_files(request.param, prefix=str(tmpdir))
+ path.build(request.param, prefix=str(tmpdir))
with tmpdir.as_cwd():
yield self.get_build_backend()
@@ -170,7 +170,7 @@ class TestBuildMetaBackend:
"""),
}
- build_files(files)
+ path.build(files)
dist_dir = os.path.abspath('preexisting-' + build_type)
@@ -262,7 +262,7 @@ class TestBuildMetaBackend:
build-backend = "setuptools.build_meta
"""),
}
- build_files(files)
+ path.build(files)
build_backend = self.get_build_backend()
targz_path = build_backend.build_sdist("temp")
with tarfile.open(os.path.join("temp", targz_path)) as tar:
@@ -271,7 +271,7 @@ class TestBuildMetaBackend:
def test_build_sdist_setup_py_exists(self, tmpdir_cwd):
# If build_sdist is called from a script other than setup.py,
# ensure setup.py is included
- build_files(defns[0])
+ path.build(defns[0])
build_backend = self.get_build_backend()
targz_path = build_backend.build_sdist("temp")
@@ -293,7 +293,7 @@ class TestBuildMetaBackend:
""")
}
- build_files(files)
+ path.build(files)
build_backend = self.get_build_backend()
targz_path = build_backend.build_sdist("temp")
@@ -315,7 +315,7 @@ class TestBuildMetaBackend:
""")
}
- build_files(files)
+ path.build(files)
build_backend = self.get_build_backend()
build_backend.build_sdist("temp")
@@ -335,7 +335,7 @@ class TestBuildMetaBackend:
}
def test_build_sdist_relative_path_import(self, tmpdir_cwd):
- build_files(self._relative_path_import_files)
+ path.build(self._relative_path_import_files)
build_backend = self.get_build_backend()
with pytest.raises(ImportError, match="^No module named 'hello'$"):
build_backend.build_sdist("temp")
@@ -374,7 +374,7 @@ class TestBuildMetaBackend:
"""),
}
- build_files(files)
+ path.build(files)
build_backend = self.get_build_backend()
@@ -409,7 +409,7 @@ class TestBuildMetaBackend:
"""),
}
- build_files(files)
+ path.build(files)
build_backend = self.get_build_backend()
@@ -437,7 +437,7 @@ class TestBuildMetaBackend:
}
def test_sys_argv_passthrough(self, tmpdir_cwd):
- build_files(self._sys_argv_0_passthrough)
+ path.build(self._sys_argv_0_passthrough)
build_backend = self.get_build_backend()
with pytest.raises(AssertionError):
build_backend.build_sdist("temp")
@@ -449,13 +449,13 @@ class TestBuildMetaLegacyBackend(TestBuildMetaBackend):
# build_meta_legacy-specific tests
def test_build_sdist_relative_path_import(self, tmpdir_cwd):
# This must fail in build_meta, but must pass in build_meta_legacy
- build_files(self._relative_path_import_files)
+ path.build(self._relative_path_import_files)
build_backend = self.get_build_backend()
build_backend.build_sdist("temp")
def test_sys_argv_passthrough(self, tmpdir_cwd):
- build_files(self._sys_argv_0_passthrough)
+ path.build(self._sys_argv_0_passthrough)
build_backend = self.get_build_backend()
build_backend.build_sdist("temp")
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index 66598066..a3b2d6e6 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -18,6 +18,7 @@ import re
import subprocess
import pytest
+from jaraco import path
from setuptools import sandbox
from setuptools.sandbox import run_setup
@@ -34,7 +35,6 @@ from setuptools.tests import fail_on_ascii
import pkg_resources
from . import contexts
-from .files import build_files
from .textwrap import DALS
@@ -794,7 +794,7 @@ class TestSetupRequires:
# Create source tree for `dep`.
dep_pkg = os.path.join(temp_dir, 'dep')
os.mkdir(dep_pkg)
- build_files({
+ path.build({
'setup.py':
DALS("""
import setuptools
diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py
index 1047468b..5dfad7e2 100644
--- a/setuptools/tests/test_egg_info.py
+++ b/setuptools/tests/test_egg_info.py
@@ -6,15 +6,15 @@ import re
import stat
import time
+import pytest
+from jaraco import path
+
from setuptools.command.egg_info import (
egg_info, manifest_maker, EggInfoDeprecationWarning, get_pkg_info_revision,
)
from setuptools.dist import Distribution
-import pytest
-
from . import environment
-from .files import build_files
from .textwrap import DALS
from . import contexts
@@ -37,7 +37,7 @@ class TestEggInfo:
""")
def _create_project(self):
- build_files({
+ path.build({
'setup.py': self.setup_script,
'hello.py': DALS("""
def run():
@@ -56,7 +56,7 @@ class TestEggInfo:
for dirname in subs
)
list(map(os.mkdir, env.paths.values()))
- build_files({
+ path.build({
env.paths['home']: {
'.pydistutils.cfg': DALS("""
[egg_info]
@@ -106,7 +106,7 @@ class TestEggInfo:
the file should remain unchanged.
"""
setup_cfg = os.path.join(env.paths['home'], 'setup.cfg')
- build_files({
+ path.build({
setup_cfg: DALS("""
[egg_info]
tag_build =
@@ -159,7 +159,7 @@ class TestEggInfo:
setup()
""")
- build_files({'setup.py': setup_script,
+ path.build({'setup.py': setup_script,
'setup.cfg': setup_config})
# This command should fail with a ValueError, but because it's
@@ -193,7 +193,7 @@ class TestEggInfo:
def test_manifest_template_is_read(self, tmpdir_cwd, env):
self._create_project()
- build_files({
+ path.build({
'MANIFEST.in': DALS("""
recursive-include docs *.rst
"""),
@@ -216,7 +216,7 @@ class TestEggInfo:
'''
) % ('' if use_setup_cfg else requires)
setup_config = requires if use_setup_cfg else ''
- build_files({'setup.py': setup_script,
+ path.build({'setup.py': setup_script,
'setup.cfg': setup_config})
mismatch_marker = "python_version<'{this_ver}'".format(
@@ -546,7 +546,7 @@ class TestEggInfo:
def test_setup_cfg_license_file(
self, tmpdir_cwd, env, files, license_in_sources):
self._create_project()
- build_files(files)
+ path.build(files)
environment.run_setup_py(
cmd=['egg_info'],
@@ -645,7 +645,7 @@ class TestEggInfo:
def test_setup_cfg_license_files(
self, tmpdir_cwd, env, files, incl_licenses, excl_licenses):
self._create_project()
- build_files(files)
+ path.build(files)
environment.run_setup_py(
cmd=['egg_info'],
@@ -750,7 +750,7 @@ class TestEggInfo:
def test_setup_cfg_license_file_license_files(
self, tmpdir_cwd, env, files, incl_licenses, excl_licenses):
self._create_project()
- build_files(files)
+ path.build(files)
environment.run_setup_py(
cmd=['egg_info'],
@@ -886,7 +886,7 @@ class TestEggInfo:
def test_egg_info_tag_only_once(self, tmpdir_cwd, env):
self._create_project()
- build_files({
+ path.build({
'setup.cfg': DALS("""
[egg_info]
tag_build = dev
diff --git a/setuptools/tests/test_glob.py b/setuptools/tests/test_glob.py
index a0728c5d..e99587f5 100644
--- a/setuptools/tests/test_glob.py
+++ b/setuptools/tests/test_glob.py
@@ -1,9 +1,8 @@
import pytest
+from jaraco import path
from setuptools.glob import glob
-from .files import build_files
-
@pytest.mark.parametrize('tree, pattern, matches', (
('', b'', []),
@@ -31,5 +30,5 @@ from .files import build_files
))
def test_glob(monkeypatch, tmpdir, tree, pattern, matches):
monkeypatch.chdir(tmpdir)
- build_files({name: '' for name in tree.split()})
+ path.build({name: '' for name in tree.split()})
assert list(sorted(glob(pattern))) == list(sorted(matches))
diff --git a/setuptools/tests/test_wheel.py b/setuptools/tests/test_wheel.py
index e56eac14..7345b135 100644
--- a/setuptools/tests/test_wheel.py
+++ b/setuptools/tests/test_wheel.py
@@ -15,6 +15,7 @@ import sys
import zipfile
import pytest
+from jaraco import path
from pkg_resources import Distribution, PathMetadata, PY_MAJOR
from setuptools.extern.packaging.utils import canonicalize_name
@@ -22,7 +23,6 @@ from setuptools.extern.packaging.tags import parse_tag
from setuptools.wheel import Wheel
from .contexts import tempdir
-from .files import build_files
from .textwrap import DALS
@@ -91,7 +91,7 @@ def build_wheel(extra_file_defs=None, **kwargs):
if extra_file_defs:
file_defs.update(extra_file_defs)
with tempdir() as source_dir:
- build_files(file_defs, source_dir)
+ path.build(file_defs, source_dir)
subprocess.check_call((sys.executable, 'setup.py',
'-q', 'bdist_wheel'), cwd=source_dir)
yield glob.glob(os.path.join(source_dir, 'dist', '*.whl'))[0]