forked from linkml/linkml-project-copier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
90 lines (76 loc) · 2.42 KB
/
Copy pathhelpers.py
File metadata and controls
90 lines (76 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""Shared helpers for template tests."""
from __future__ import annotations
import os
import subprocess
from pathlib import Path
from copier import run_copy
TEMPLATE_ROOT = Path(__file__).resolve().parent.parent
ALL_LICENSES = ["MIT", "BSD-3-Clause", "Apache-2.0", "MPL-2.0", "LGPL-3.0-only", "GPL-3.0-only"]
DEFAULT_DATA = {
"project_name": "test-schema",
"project_slug": "test_schema",
"email": "test@example.org",
"full_name": "Test User",
"github_org": "test-org",
"project_description": "A test project.",
"license": "MIT",
"copyright_year": "2025",
"add_example": True,
"gh_action_pypi": True,
"gh_action_docs_preview": True,
}
def generate_project(
dest: Path,
data_overrides: dict | None = None,
) -> Path:
"""Generate a project from the copier template.
Args:
dest: Directory where the project will be generated.
data_overrides: Values to override in DEFAULT_DATA.
Returns:
Path to the generated project directory.
"""
data = {**DEFAULT_DATA, **(data_overrides or {})}
run_copy(
str(TEMPLATE_ROOT),
dest,
data=data,
defaults=True,
unsafe=True,
vcs_ref="HEAD",
)
return dest
def git_init(project_dir: Path) -> None:
"""Initialize a git repo with an initial commit (needed for dynamic versioning)."""
subprocess.run(["git", "init"], cwd=project_dir, check=True, capture_output=True)
subprocess.run(
["git", "config", "user.email", "test@test.com"],
cwd=project_dir,
check=True,
capture_output=True,
)
subprocess.run(
["git", "config", "user.name", "Test"],
cwd=project_dir,
check=True,
capture_output=True,
)
subprocess.run(["git", "add", "."], cwd=project_dir, check=True, capture_output=True)
subprocess.run(
["git", "commit", "-m", "init"],
cwd=project_dir,
check=True,
capture_output=True,
)
def run_just(project_dir: Path, *args: str, timeout: int = 600) -> subprocess.CompletedProcess:
"""Run a just command in the given project directory."""
# Remove VIRTUAL_ENV so the generated project's uv uses its own .venv
env = {k: v for k, v in os.environ.items() if k != "VIRTUAL_ENV"}
return subprocess.run(
["just", *args],
cwd=project_dir,
capture_output=True,
text=True,
timeout=timeout,
env=env,
)