Skip to content

Commit 045b8dc

Browse files
committed
feat: allow for a divergence between the git repo root and the uv workspace root
1 parent adb0966 commit 045b8dc

3 files changed

Lines changed: 203 additions & 192 deletions

File tree

bough/analyzer.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ class BoughAnalyzer:
3939

4040
def __init__(
4141
self,
42+
repo_root: Path,
4243
workspace_root: Path,
4344
config: "BoughConfig",
4445
packages: dict[str, Package] | None = None,
4546
) -> None:
47+
self.repo_root = repo_root
4648
self.workspace_root = workspace_root
4749
logger.debug(f"Initializing analyzer for workspace: {workspace_root}")
4850
self.config = config
@@ -54,10 +56,12 @@ def __init__(
5456
logger.debug(f"Discovered {len(self.packages)} packages")
5557

5658
@classmethod
57-
def from_workspace(cls, workspace_root: Path, config_path: Path) -> "BoughAnalyzer":
59+
def from_workspace(
60+
cls, repo_root: Path, workspace_root: Path, config_path: Path
61+
) -> "BoughAnalyzer":
5862
"""Create analyzer by discovering packages from workspace."""
5963
config = load_config(config_path)
60-
return cls(workspace_root, config)
64+
return cls(repo_root, workspace_root, config)
6165

6266
def _discover_packages(self) -> None:
6367
root_pyproject = self.workspace_root / "pyproject.toml"
@@ -159,8 +163,9 @@ def _find_direct_packages(
159163
changed_files: set[str],
160164
) -> set[str]:
161165
directly_affected = set()
166+
strip_prefix = self.workspace_root.relative_to(self.repo_root)
162167
for file_path in changed_files:
163-
file_path_obj = Path(file_path)
168+
file_path_obj = Path(file_path).relative_to(strip_prefix)
164169

165170
if self._matches_patterns(file_path, self.config.ignore):
166171
logger.debug(f"Ignoring file {file_path} (matches ignore patterns)")
@@ -210,7 +215,7 @@ def find_affected(
210215
"""Return the affected packages and files."""
211216
logger.debug(f"Analyzing changes from {base_commit} to HEAD")
212217

213-
files = find_changed_files(self.workspace_root, base_commit)
218+
files = find_changed_files(self.repo_root, base_commit)
214219
all_affected = self._find_transitive_packages(self._find_direct_packages(files))
215220

216221
if selection != "buildable":

bough/cli.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ def main() -> None:
2323
default=Path.cwd(),
2424
help="Path to workspace root (default: current directory)",
2525
)
26+
default_parser.add_argument(
27+
"--repo",
28+
type=Path,
29+
default=Path.cwd(),
30+
help="Path to git repository root (default: current directory)",
31+
)
2632
default_parser.add_argument(
2733
"--verbose",
2834
"-v",
@@ -74,7 +80,7 @@ def main() -> None:
7480
config_path = args.config or args.workspace / ".bough.yaml"
7581

7682
try:
77-
analyzer = BoughAnalyzer.from_workspace(args.workspace, config_path)
83+
analyzer = BoughAnalyzer.from_workspace(args.repo, args.workspace, config_path)
7884

7985
if args.command == "graph":
8086
output = fmt.dependency_graph(analyzer)

0 commit comments

Comments
 (0)