Skip to content
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

Avoid using SETUPTOOLS_EDITABLE env var in test #3479

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions setuptools/tests/test_editable_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
from setuptools.dist import Distribution


@pytest.fixture(params=["strict", "lax"])
def editable_mode(request, monkeypatch):
@pytest.fixture(params=["strict", "lenient"])
def editable_opts(request):
if request.param == "strict":
monkeypatch.setenv("SETUPTOOLS_EDITABLE", "strict")
yield
return ["--config-settings", "editable-mode=strict"]
return []


EXAMPLE = {
Expand Down Expand Up @@ -114,14 +114,14 @@ def editable_mode(request, monkeypatch):
EXAMPLE, # No setup.py script
]
)
def test_editable_with_pyproject(tmp_path, venv, files, editable_mode):
def test_editable_with_pyproject(tmp_path, venv, files, editable_opts):
project = tmp_path / "mypkg"
project.mkdir()
jaraco.path.build(files, prefix=project)

cmd = [venv.exe(), "-m", "pip", "install",
"--no-build-isolation", # required to force current version of setuptools
"-e", str(project)]
"-e", str(project), *editable_opts]
print(str(subprocess.check_output(cmd), "utf-8"))

cmd = [venv.exe(), "-m", "mypkg"]
Expand All @@ -132,7 +132,7 @@ def test_editable_with_pyproject(tmp_path, venv, files, editable_mode):
assert subprocess.check_output(cmd).strip() == b"3.14159.post0 foobar 42"


def test_editable_with_flat_layout(tmp_path, venv, editable_mode):
def test_editable_with_flat_layout(tmp_path, venv, editable_opts):
files = {
"mypkg": {
"pyproject.toml": dedent("""\
Expand All @@ -157,7 +157,7 @@ def test_editable_with_flat_layout(tmp_path, venv, editable_mode):

cmd = [venv.exe(), "-m", "pip", "install",
"--no-build-isolation", # required to force current version of setuptools
"-e", str(project)]
"-e", str(project), *editable_opts]
print(str(subprocess.check_output(cmd), "utf-8"))
cmd = [venv.exe(), "-c", "import pkg, mod; print(pkg.a, mod.b)"]
assert subprocess.check_output(cmd).strip() == b"4 2"
Expand All @@ -166,7 +166,7 @@ def test_editable_with_flat_layout(tmp_path, venv, editable_mode):
class TestLegacyNamespaces:
"""Ported from test_develop"""

def test_namespace_package_importable(self, venv, tmp_path, editable_mode):
def test_namespace_package_importable(self, venv, tmp_path, editable_opts):
"""
Installing two packages sharing the same namespace, one installed
naturally using pip or `--single-version-externally-managed`
Expand All @@ -176,7 +176,8 @@ def test_namespace_package_importable(self, venv, tmp_path, editable_mode):
pkg_A = namespaces.build_namespace_package(tmp_path, 'myns.pkgA')
pkg_B = namespaces.build_namespace_package(tmp_path, 'myns.pkgB')
# use pip to install to the target directory
opts = ["--no-build-isolation"] # force current version of setuptools
opts = editable_opts[:]
opts.append("--no-build-isolation") # force current version of setuptools
venv.run(["python", "-m", "pip", "install", str(pkg_A), *opts])
venv.run(["python", "-m", "pip", "install", "-e", str(pkg_B), *opts])
venv.run(["python", "-c", "import myns.pkgA; import myns.pkgB"])
Expand All @@ -185,7 +186,7 @@ def test_namespace_package_importable(self, venv, tmp_path, editable_mode):


class TestPep420Namespaces:
def test_namespace_package_importable(self, venv, tmp_path, editable_mode):
def test_namespace_package_importable(self, venv, tmp_path, editable_opts):
"""
Installing two packages sharing the same namespace, one installed
normally using pip and the other installed in editable mode
Expand All @@ -194,12 +195,13 @@ def test_namespace_package_importable(self, venv, tmp_path, editable_mode):
pkg_A = namespaces.build_pep420_namespace_package(tmp_path, 'myns.n.pkgA')
pkg_B = namespaces.build_pep420_namespace_package(tmp_path, 'myns.n.pkgB')
# use pip to install to the target directory
opts = ["--no-build-isolation"] # force current version of setuptools
opts = editable_opts[:]
opts.append("--no-build-isolation") # force current version of setuptools
venv.run(["python", "-m", "pip", "install", str(pkg_A), *opts])
venv.run(["python", "-m", "pip", "install", "-e", str(pkg_B), *opts])
venv.run(["python", "-c", "import myns.n.pkgA; import myns.n.pkgB"])

def test_namespace_created_via_package_dir(self, venv, tmp_path, editable_mode):
def test_namespace_created_via_package_dir(self, venv, tmp_path, editable_opts):
"""Currently users can create a namespace by tweaking `package_dir`"""
files = {
"pkgA": {
Expand All @@ -224,7 +226,8 @@ def test_namespace_created_via_package_dir(self, venv, tmp_path, editable_mode):
pkg_C = namespaces.build_pep420_namespace_package(tmp_path, 'myns.n.pkgC')

# use pip to install to the target directory
opts = ["--no-build-isolation"] # force current version of setuptools
opts = editable_opts[:]
opts.append("--no-build-isolation") # force current version of setuptools
venv.run(["python", "-m", "pip", "install", str(pkg_A), *opts])
venv.run(["python", "-m", "pip", "install", "-e", str(pkg_B), *opts])
venv.run(["python", "-m", "pip", "install", "-e", str(pkg_C), *opts])
Expand All @@ -236,8 +239,7 @@ def test_namespace_created_via_package_dir(self, venv, tmp_path, editable_mode):
platform.python_implementation() == 'PyPy',
reason="Workaround fails on PyPy (why?)",
)
@pytest.mark.parametrize("mode", ("strict", "lax"))
def test_editable_with_prefix(tmp_path, sample_project, mode):
def test_editable_with_prefix(tmp_path, sample_project, editable_opts):
"""
Editable install to a prefix should be discoverable.
"""
Expand All @@ -254,7 +256,7 @@ def test_editable_with_prefix(tmp_path, sample_project, mode):
# install workaround
pip_run.launch.inject_sitecustomize(str(site_packages))

env = dict(os.environ, PYTHONPATH=str(site_packages), SETUPTOOLS_EDITABLE=mode)
env = dict(os.environ, PYTHONPATH=str(site_packages))
cmd = [
sys.executable,
'-m',
Expand All @@ -265,6 +267,7 @@ def test_editable_with_prefix(tmp_path, sample_project, mode):
'--prefix',
str(prefix),
'--no-build-isolation',
*editable_opts,
]
subprocess.check_call(cmd, env=env)

Expand Down Expand Up @@ -518,8 +521,9 @@ class TestOverallBehaviour:
}

@pytest.mark.parametrize("layout", EXAMPLES.keys())
def test_editable_install(self, tmp_path, venv, layout, editable_mode):
project = install_project("mypkg", venv, tmp_path, self.EXAMPLES[layout])
def test_editable_install(self, tmp_path, venv, layout, editable_opts):
opts = editable_opts
project = install_project("mypkg", venv, tmp_path, self.EXAMPLES[layout], *opts)

# Ensure stray files are not importable
cmd_import_error = """\
Expand Down Expand Up @@ -616,9 +620,9 @@ def test_generated_tree(self, tmp_path):

assert next(aux.glob("**/resource.not_in_manifest"), None) is None

def test_strict_install(self, tmp_path, venv, monkeypatch):
monkeypatch.setenv("SETUPTOOLS_EDITABLE", "strict")
install_project("mypkg", venv, tmp_path, self.FILES)
def test_strict_install(self, tmp_path, venv):
opts = ["--config-settings", "editable-mode=strict"]
install_project("mypkg", venv, tmp_path, self.FILES, *opts)

out = venv.run(["python", "-c", "import mypkg.mod1; print(mypkg.mod1.var)"])
assert b"42" in out
Expand Down Expand Up @@ -648,11 +652,11 @@ def test_strict_install(self, tmp_path, venv, monkeypatch):
assert b"resource.not_in_manifest" in out


def install_project(name, venv, tmp_path, files):
def install_project(name, venv, tmp_path, files, *opts):
project = tmp_path / name
project.mkdir()
jaraco.path.build(files, prefix=project)
opts = ["--no-build-isolation"] # force current version of setuptools
opts = [*opts, "--no-build-isolation"] # force current version of setuptools
venv.run(["python", "-m", "pip", "install", "-e", str(project), *opts])
return project

Expand Down