Skip to content

Commit

Permalink
fix: only quote string when the requirement is a URL
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming committed Dec 13, 2022
1 parent e5841ae commit 0a9b213
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/pdm/backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def clean(self, context: Context) -> None:
shutil.rmtree(context.build_dir)

def initialize(self, context: Context) -> None:
"""Initialize the build context."""
self.call_hook("pdm_build_initialize", context)

def get_files(self, context: Context) -> Iterable[tuple[str, Path]]:
Expand Down
9 changes: 7 additions & 2 deletions src/pdm/backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,18 @@ def expand_vars(line: str, root: str) -> str:
"""Expand environment variables in a string."""
if "$" not in line:
return line
line = line.replace("${PROJECT_ROOT}", root.lstrip("/"))

if "://" in line:
quote: Callable[[str], str] = urllib.parse.quote
else:
quote = str
line = line.replace("${PROJECT_ROOT}", quote(root).lstrip("/"))

def replace_func(match: Match[str]) -> str:
rv = os.getenv(match.group(1))
if rv is None:
return match.group(0)
return urllib.parse.quote(rv)
return quote(rv)

return re.sub(r"\$\{(.+?)\}", replace_func, line)

Expand Down
20 changes: 10 additions & 10 deletions src/pdm/backend/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,6 @@ def _get_platform_tags(self) -> tuple[str | None, str | None, str | None]:
plat_name = self.config_settings["--plat-name"]
return python_tag, py_limited_api, plat_name

def prepare_metadata(self, metadata_directory: str) -> Path:
"""Write the dist-info files under the given directory"""
context = self.build_context(Path(metadata_directory))
self.initialize(context)
return self._write_dist_info(Path(metadata_directory))

def initialize(self, context: Context) -> None:
self._fix_dependencies()
return super().initialize(context)

def _fix_dependencies(self) -> None:
"""Fix the dependencies and remove dynamic variables from the metadata"""
metadata = self.config.metadata
Expand All @@ -107,6 +97,16 @@ def _fix_dependencies(self) -> None:
expand_vars(dep, root) for dep in deps
]

def initialize(self, context: Context) -> None:
self._fix_dependencies()
return super().initialize(context)

def prepare_metadata(self, metadata_directory: str) -> Path:
"""Write the dist-info files under the given directory"""
context = self.build_context(Path(metadata_directory))
self.initialize(context)
return self._write_dist_info(Path(metadata_directory))

def _collect_files(self, context: Context, root: Path) -> FileMap:
files = super()._collect_files(context, root)
if root == self.location:
Expand Down

0 comments on commit 0a9b213

Please sign in to comment.