Skip to content

Commit 810c6c6

Browse files
authored
test windows msgpack (#3022)
1 parent 00de69c commit 810c6c6

File tree

8 files changed

+38
-31
lines changed

8 files changed

+38
-31
lines changed

news/3011.feature.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

news/3022.bugfix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a mistake in build env setup that will cause the `PATH` env var length to grow.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pdm = "pdm.core:main"
7676

7777
[tool.pdm.version]
7878
source = "scm"
79-
write_to = "pdm/VERSION"
79+
write_to = "pdm/models/VERSION"
8080

8181
[tool.pdm.build]
8282
excludes = ["./**/.git"]

src/pdm/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/pdm/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def read_version() -> str:
55
try:
66
return importlib_metadata.version(__package__ or "pdm")
77
except importlib_metadata.PackageNotFoundError:
8-
return resources_read_text("pdm", "VERSION").strip()
8+
return resources_read_text("pdm.models", "VERSION").strip()
99

1010

1111
__version__ = read_version()

src/pdm/builders/base.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def __init__(self, executable: str, shared: str, overlay: str) -> None:
137137
for path in (overlay, shared):
138138
paths = get_sys_config_paths(executable, vars={"base": path, "platbase": path}, kind="prefix")
139139
self.bin_dirs.append(paths["scripts"])
140-
self.lib_dirs.extend([paths["platlib"], paths["purelib"]])
140+
self.lib_dirs.extend({paths["platlib"], paths["purelib"]})
141141
self.site_dir = os.path.join(overlay, "site")
142142
if os.path.isdir(self.site_dir):
143143
# Clear existing site dir as .pyc may be cached.
@@ -181,7 +181,7 @@ class EnvBuilder:
181181
if TYPE_CHECKING:
182182
_hook: BuildBackendHookCaller
183183
_requires: list[str]
184-
_prefix: _Prefix
184+
_prefix: _Prefix | None
185185

186186
def get_shared_env(self, key: int) -> str:
187187
if key in self._shared_envs:
@@ -234,21 +234,24 @@ def init_build_system(self, build_system: dict[str, Any]) -> None:
234234
python_executable=self.executable,
235235
)
236236
self._requires = build_system["requires"]
237-
self._prefix = _Prefix(
238-
self.executable,
239-
# Build backends with the same requires list share the cached base env.
240-
shared=self.get_shared_env(hash(frozenset(self._requires))),
241-
# Overlay envs are unique for each source to be built.
242-
overlay=self.get_overlay_env(os.path.normcase(self.src_dir).rstrip("\\/")),
237+
self._prefix = (
238+
_Prefix(
239+
self.executable,
240+
# Build backends with the same requires list share the cached base env.
241+
shared=self.get_shared_env(hash(frozenset(self._requires))),
242+
# Overlay envs are unique for each source to be built.
243+
overlay=self.get_overlay_env(os.path.normcase(self.src_dir).rstrip("\\/")),
244+
)
245+
if self.isolated
246+
else None
243247
)
244248

245249
@property
246250
def _env_vars(self) -> dict[str, str]:
247-
paths = self._prefix.bin_dirs
248-
if "PATH" in os.environ:
249-
paths.append(os.getenv("PATH", ""))
250251
env: dict[str, str] = {}
251252
if self.isolated:
253+
assert self._prefix is not None
254+
paths = self._prefix.bin_dirs[:]
252255
env.update(
253256
{
254257
"PYTHONPATH": self._prefix.site_dir,
@@ -257,14 +260,15 @@ def _env_vars(self) -> dict[str, str]:
257260
)
258261
else:
259262
env_paths = self._env.get_paths()
260-
project_libs = env_paths["purelib"]
261-
pythonpath = [*self._prefix.lib_dirs, project_libs]
263+
pythonpath = list({env_paths["purelib"], env_paths["platlib"]})
262264
if "PYTHONPATH" in os.environ:
263265
pythonpath.append(os.getenv("PYTHONPATH", ""))
264266
env.update(
265267
PYTHONPATH=os.pathsep.join(pythonpath),
266268
)
267-
paths.append(env_paths["scripts"])
269+
paths = [env_paths["scripts"]]
270+
if "PATH" in os.environ:
271+
paths.append(os.getenv("PATH", ""))
268272
env["PATH"] = os.pathsep.join(paths)
269273
return env
270274

@@ -279,8 +283,12 @@ def subprocess_runner(
279283
def check_requirements(self, reqs: Iterable[str]) -> Iterable[Requirement]:
280284
missing = set()
281285
conflicting = set()
282-
project_lib = self._env.get_paths()["purelib"]
283-
libs = self._prefix.lib_dirs + ([project_lib] if not self.isolated else [])
286+
env_paths = self._env.get_paths()
287+
libs = (
288+
list({env_paths["purelib"], env_paths["platlib"]})
289+
if not self.isolated
290+
else cast(_Prefix, self._prefix).lib_dirs
291+
)
284292
if reqs:
285293
ws = WorkingSet(libs)
286294
for req in reqs:
@@ -308,6 +316,7 @@ def install(self, requirements: Iterable[str], shared: bool = False) -> None:
308316
missing = list(self.check_requirements(requirements))
309317
if not missing:
310318
return
319+
assert self._prefix is not None
311320
path = self._prefix.shared if shared else self._prefix.overlay
312321
env = PythonEnvironment(self._env.project, python=str(self._env.interpreter.path), prefix=path)
313322
install_requirements(missing, env)

src/pdm/builders/sdist.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44

55
from pdm.builders.base import EnvBuilder, wrap_error
6+
from pdm.termui import logger
67

78

89
class SdistBuilder(EnvBuilder):
@@ -14,5 +15,8 @@ def build(self, out_dir: str, metadata_directory: str | None = None) -> str:
1415
self.install(self._requires, shared=True)
1516
requires = self._hook.get_requires_for_build_sdist(self.config_settings)
1617
self.install(requires)
18+
lib = self._env.get_paths()["purelib"]
19+
logger.info("Libs(%s): %s", lib, os.listdir(lib))
20+
logger.info("PYTHONPATH: %s", self._env_vars["PYTHONPATH"])
1721
filename = self._hook.build_sdist(out_dir, self.config_settings)
1822
return os.path.join(out_dir, filename)

tests/cli/test_build.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,12 @@ def test_cli_build_with_config_settings(fixture_project, pdm):
159159

160160

161161
@pytest.mark.usefixtures("local_finder")
162-
@pytest.mark.parametrize("isolated", (True, False))
163-
def test_build_with_no_isolation(fixture_project, pdm, isolated):
164-
project = fixture_project("demo-failure")
165-
project.pyproject.set_data({"project": {"name": "demo", "version": "0.1.0"}})
166-
project.pyproject.write()
167-
pdm(["add", "first"], obj=project)
168-
args = ["build"]
169-
if not isolated:
170-
args.append("--no-isolation")
171-
result = pdm(args, obj=project)
172-
assert result.exit_code == int(isolated)
162+
def test_build_with_no_isolation(pdm, project):
163+
result = pdm(["build", "--no-isolation"], obj=project)
164+
assert result.exit_code == 1
165+
pdm(["add", "pdm-backend", "--no-self"], obj=project, strict=True)
166+
result = pdm(["build", "--no-isolation"], obj=project)
167+
assert result.exit_code == 0
173168

174169

175170
def test_build_ignoring_pip_environment(fixture_project, monkeypatch):

0 commit comments

Comments
 (0)