-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from noirbizarre/feature/reuse-scripts
Feature: reuse PDM scripts
- Loading branch information
Showing
11 changed files
with
494 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,14 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import shutil | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
import toml | ||
|
||
|
||
def setup_env() -> None: | ||
os.environ.update({"PDM_IGNORE_SAVED_PYTHON": "1", "PDM_USE_VENV": "1"}) | ||
old_passenv = os.getenv("TOX_TESTENV_PASSENV") | ||
new_env = ["PDM_*"] | ||
if old_passenv: | ||
new_env.append(old_passenv) | ||
os.environ["TOX_TESTENV_PASSENV"] = " ".join(new_env) | ||
|
||
|
||
def clone_pdm_files(env_path: str | Path, root: str | Path) -> None: | ||
"""Initialize the PDM project for the given VirtualEnv by cloning | ||
the pyproject.toml and pdm.lock files to the venv path. | ||
""" | ||
env_path = Path(env_path) | ||
if not env_path.exists(): | ||
env_path.mkdir(parents=True) | ||
root = Path(root) | ||
if not root.joinpath("pyproject.toml").exists(): | ||
return | ||
old_pyproject = toml.load(root.joinpath("pyproject.toml").open("r")) | ||
if "name" in old_pyproject.get("project", {}): | ||
del old_pyproject["project"]["name"] | ||
with env_path.joinpath("pyproject.toml").open("w") as f: | ||
toml.dump(old_pyproject, f) | ||
|
||
if root.joinpath("pdm.lock").exists(): | ||
shutil.copy2(root.joinpath("pdm.lock"), env_path.joinpath("pdm.lock")) | ||
|
||
|
||
def detect_pdm_files(root: str | Path) -> bool: | ||
root = Path(root) | ||
pyproject = root.joinpath("pyproject.toml") | ||
if not pyproject.exists(): | ||
return False | ||
with pyproject.open("r") as f: | ||
toml_data = toml.load(f) | ||
return "project" in toml_data | ||
def pdm_scripts(root: Path) -> dict[str, Any]: | ||
pyproject_toml = root / "pyproject.toml" | ||
if pyproject_toml.exists(): | ||
pyproject = toml.load(pyproject_toml.open("r")) | ||
return pyproject.get("tool", {}).get("pdm", {}).get("scripts", {}) | ||
return {} |