rhiza 0.5.1__py3-none-any.whl → 0.5.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,11 @@
1
- """Command-line helpers for working with Rhiza templates.
2
-
3
- This module currently exposes a thin wrapper that shells out to the
4
- `tools/inject_rhiza.sh` script. It exists so the functionality can be
5
- invoked via a Python entry point while delegating the heavy lifting to
6
- the maintained shell script.
7
- """
8
-
9
1
  import shutil
10
2
  import subprocess
11
- import sys
12
3
  import tempfile
13
4
  from pathlib import Path
14
5
 
15
6
  from loguru import logger
16
7
 
17
- from rhiza.commands.init import init
8
+ from rhiza.commands import init
18
9
  from rhiza.models import RhizaTemplate
19
10
 
20
11
 
@@ -37,46 +28,44 @@ def expand_paths(base_dir: Path, paths: list[str]) -> list[Path]:
37
28
  return all_files
38
29
 
39
30
 
40
- def materialize(target: Path, branch: str, force: bool):
41
- """Materialize rhiza templates into TARGET repository."""
42
- # Convert to absolute path to avoid surprises
31
+ def materialize(target: Path, branch: str, force: bool) -> None:
32
+ """Materialize Rhiza templates into the target repository.
33
+
34
+ This performs a sparse checkout of the template repository and copies
35
+ the selected files into the target repository, recording all files
36
+ under template control in `.rhiza.history`.
37
+ """
43
38
  target = target.resolve()
44
39
 
45
40
  logger.info(f"Target repository: {target}")
46
41
  logger.info(f"Rhiza branch: {branch}")
47
42
 
48
43
  # -----------------------
49
- # Ensure template.yml
44
+ # Ensure Rhiza is initialized
50
45
  # -----------------------
51
- template_file = target / ".github" / "template.yml"
52
- # template_file.parent.mkdir(parents=True, exist_ok=True)
53
-
54
- # Initialize rhiza if not already initialized, e.g. construct a template.yml file
55
46
  init(target)
56
47
 
57
- # -----------------------
58
- # Load template.yml
59
- # -----------------------
48
+ template_file = target / ".github" / "template.yml"
60
49
  template = RhizaTemplate.from_yaml(template_file)
61
50
 
62
51
  rhiza_repo = template.template_repository
63
- # Use template branch if specified, otherwise fall back to CLI parameter
64
- rhiza_branch = template.template_branch if template.template_branch else branch
52
+ rhiza_branch = template.template_branch or branch
65
53
  include_paths = template.include
66
54
  excluded_paths = template.exclude
67
55
 
68
56
  if not include_paths:
69
- logger.error("No include paths found in template.yml")
70
- raise sys.exit(1)
57
+ raise RuntimeError("No include paths found in template.yml")
71
58
 
72
59
  logger.info("Include paths:")
73
60
  for p in include_paths:
74
61
  logger.info(f" - {p}")
75
62
 
76
63
  # -----------------------
77
- # Sparse clone rhiza
64
+ # Sparse clone template repo
78
65
  # -----------------------
79
66
  tmp_dir = Path(tempfile.mkdtemp())
67
+ materialized_files: list[Path] = []
68
+
80
69
  logger.info(f"Cloning {rhiza_repo}@{rhiza_branch} into temporary directory")
81
70
 
82
71
  try:
@@ -84,12 +73,10 @@ def materialize(target: Path, branch: str, force: bool):
84
73
  [
85
74
  "git",
86
75
  "clone",
87
- "--depth",
88
- "1",
76
+ "--depth", "1",
89
77
  "--filter=blob:none",
90
78
  "--sparse",
91
- "--branch",
92
- rhiza_branch,
79
+ "--branch", rhiza_branch,
93
80
  f"https://github.com/{rhiza_repo}.git",
94
81
  str(tmp_dir),
95
82
  ],
@@ -97,30 +84,46 @@ def materialize(target: Path, branch: str, force: bool):
97
84
  stdout=subprocess.DEVNULL,
98
85
  )
99
86
 
100
- subprocess.run(["git", "sparse-checkout", "init"], cwd=tmp_dir, check=True)
101
- subprocess.run(["git", "sparse-checkout", "set", "--skip-checks", *include_paths], cwd=tmp_dir, check=True)
87
+ subprocess.run(
88
+ ["git", "sparse-checkout", "init", "--cone"],
89
+ cwd=tmp_dir,
90
+ check=True,
91
+ )
102
92
 
103
- # After sparse-checkout
93
+ subprocess.run(
94
+ ["git", "sparse-checkout", "set", "--skip-checks", *include_paths],
95
+ cwd=tmp_dir,
96
+ check=True,
97
+ )
98
+
99
+ # -----------------------
100
+ # Expand include/exclude paths
101
+ # -----------------------
104
102
  all_files = expand_paths(tmp_dir, include_paths)
105
103
 
106
- # Filter out excluded files
107
- # excluded_set = {tmp_dir / e for e in excluded_paths}
108
- excluded_files = expand_paths(tmp_dir, excluded_paths)
104
+ excluded_files = {
105
+ f.resolve()
106
+ for f in expand_paths(tmp_dir, excluded_paths)
107
+ }
109
108
 
110
- files_to_copy = [f for f in all_files if f not in excluded_files]
111
- # print(files_to_copy)
109
+ files_to_copy = [
110
+ f for f in all_files
111
+ if f.resolve() not in excluded_files
112
+ ]
112
113
 
113
- # Copy loop
114
- materialized_files = []
114
+ # -----------------------
115
+ # Copy files into target repo
116
+ # -----------------------
115
117
  for src_file in files_to_copy:
116
118
  dst_file = target / src_file.relative_to(tmp_dir)
117
119
  relative_path = dst_file.relative_to(target)
118
120
 
119
- # Track this file as being under template control
120
121
  materialized_files.append(relative_path)
121
122
 
122
123
  if dst_file.exists() and not force:
123
- logger.warning(f"{relative_path} already exists — use force=True to overwrite")
124
+ logger.warning(
125
+ f"{relative_path} already exists — use --force to overwrite"
126
+ )
124
127
  continue
125
128
 
126
129
  dst_file.parent.mkdir(parents=True, exist_ok=True)
@@ -130,9 +133,25 @@ def materialize(target: Path, branch: str, force: bool):
130
133
  finally:
131
134
  shutil.rmtree(tmp_dir)
132
135
 
133
- # Write .rhiza.history file listing all files under template control
136
+ # -----------------------
137
+ # Warn about workflow files
138
+ # -----------------------
139
+ workflow_files = [
140
+ p for p in materialized_files
141
+ if p.parts[:2] == (".github", "workflows")
142
+ ]
143
+
144
+ if workflow_files:
145
+ logger.warning(
146
+ "Workflow files were materialized. Updating these files requires "
147
+ "a token with the 'workflow' permission in GitHub Actions."
148
+ )
149
+
150
+ # -----------------------
151
+ # Write .rhiza.history
152
+ # -----------------------
134
153
  history_file = target / ".rhiza.history"
135
- with open(history_file, "w") as f:
154
+ with history_file.open("w", encoding="utf-8") as f:
136
155
  f.write("# Rhiza Template History\n")
137
156
  f.write("# This file lists all files managed by the Rhiza template.\n")
138
157
  f.write(f"# Template repository: {rhiza_repo}\n")
@@ -141,19 +160,22 @@ def materialize(target: Path, branch: str, force: bool):
141
160
  f.write("# Files under template control:\n")
142
161
  for file_path in sorted(materialized_files):
143
162
  f.write(f"{file_path}\n")
144
- logger.info(f"Created {history_file.relative_to(target)} with {len(materialized_files)} files")
163
+
164
+ logger.info(
165
+ f"Created {history_file.relative_to(target)} "
166
+ f"with {len(materialized_files)} files"
167
+ )
145
168
 
146
169
  logger.success("Rhiza templates materialized successfully")
147
- logger.info("""
148
- Next steps:
149
- 1. Review changes:
150
- git status
151
- git diff
152
-
153
- 2. Commit:
154
- git add .
155
- git commit -m "chore: import rhiza templates"
156
-
157
- This is a one-shot snapshot.
158
- Re-run this script to update templates explicitly.
159
- """)
170
+
171
+ logger.info(
172
+ "Next steps:\n"
173
+ " 1. Review changes:\n"
174
+ " git status\n"
175
+ " git diff\n\n"
176
+ " 2. Commit:\n"
177
+ " git add .\n"
178
+ ' git commit -m "chore: import rhiza templates"\n\n'
179
+ "This is a one-shot snapshot.\n"
180
+ "Re-run this command to update templates explicitly."
181
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rhiza
3
- Version: 0.5.1
3
+ Version: 0.5.2
4
4
  Summary: Reusable configuration templates for modern Python projects
5
5
  Project-URL: Homepage, https://github.com/jebel-quant/rhiza-cli
6
6
  Project-URL: Repository, https://github.com/jebel-quant/rhiza-cli
@@ -4,10 +4,10 @@ rhiza/cli.py,sha256=v7VaGUEnfuGRMOGh8I7Luh-QiUHj0to7tsSXVFuUyts,3458
4
4
  rhiza/models.py,sha256=-n5eyPcU35IVsbvy7F-kyKR343TkOrx25kooLCF9whg,3001
5
5
  rhiza/commands/__init__.py,sha256=KcoFX52xQ1NFdgVeGsAkIaqmJrRso1GOq0vFL0WEB44,300
6
6
  rhiza/commands/init.py,sha256=K8NN9x_gMWeoD1gx9PCDkGUCN3luxZgp7tVD2jCqT94,1929
7
- rhiza/commands/materialize.py,sha256=0P17Y3FcPvB7KBt2IAU7mDJpH9rgJsi08lSxOZWsQ9I,5253
7
+ rhiza/commands/materialize.py,sha256=6dE5uG41HkSERFqupS29PaHh32lveHRvbxEttaCfBpk,5525
8
8
  rhiza/commands/validate.py,sha256=itcLg44GiuZ7hZ67Bscj1RavdERlWgq40rJDaYOp2zM,4829
9
- rhiza-0.5.1.dist-info/METADATA,sha256=dkZJnJ-aw2N_T8jbKSom3MWFCkOEbQfmH8r23hx6AZU,19938
10
- rhiza-0.5.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
11
- rhiza-0.5.1.dist-info/entry_points.txt,sha256=NAwZUpbXvfKv50a_Qq-PxMHl3lcjAyZO63IBeuUNgfY,45
12
- rhiza-0.5.1.dist-info/licenses/LICENSE,sha256=4m5X7LhqX-6D0Ks79Ys8CLpmza8cxDG34g4S9XSNAGY,1077
13
- rhiza-0.5.1.dist-info/RECORD,,
9
+ rhiza-0.5.2.dist-info/METADATA,sha256=3X4vrQOv-eb1Znj_VAq8J5OmHAPI3V6vgM4dNTSasaw,19938
10
+ rhiza-0.5.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
11
+ rhiza-0.5.2.dist-info/entry_points.txt,sha256=NAwZUpbXvfKv50a_Qq-PxMHl3lcjAyZO63IBeuUNgfY,45
12
+ rhiza-0.5.2.dist-info/licenses/LICENSE,sha256=4m5X7LhqX-6D0Ks79Ys8CLpmza8cxDG34g4S9XSNAGY,1077
13
+ rhiza-0.5.2.dist-info/RECORD,,
File without changes