Skip to content

Commit b76aa45

Browse files
committed
Fix: Resolve absolute paths in run.py to support execution outside repo root
1 parent 0c1ed0d commit b76aa45

3 files changed

Lines changed: 46 additions & 8 deletions

File tree

concore_cli/commands/run.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55
from rich.panel import Panel
66
from rich.progress import Progress, SpinnerColumn, TextColumn
77

8+
def _find_mkconcore_path():
9+
for parent in Path(__file__).resolve().parents:
10+
candidate = parent / "mkconcore.py"
11+
if candidate.exists():
12+
return candidate
13+
return None
14+
815
def run_workflow(workflow_file, source, output, exec_type, auto_build, console):
916
workflow_path = Path(workflow_file).resolve()
1017
source_path = Path(source).resolve()
11-
output_path = Path(output)
18+
output_path = Path(output).resolve()
1219

1320
if not source_path.exists():
1421
raise FileNotFoundError(f"Source directory '{source}' not found")
@@ -24,6 +31,10 @@ def run_workflow(workflow_file, source, output, exec_type, auto_build, console):
2431
console.print(f"[cyan]Type:[/cyan] {exec_type}")
2532
console.print()
2633

34+
mkconcore_path = _find_mkconcore_path()
35+
if mkconcore_path is None:
36+
raise FileNotFoundError("mkconcore.py not found. Please install concore from source.")
37+
2738
with Progress(
2839
SpinnerColumn(),
2940
TextColumn("[progress.description]{task.description}"),
@@ -33,7 +44,8 @@ def run_workflow(workflow_file, source, output, exec_type, auto_build, console):
3344

3445
try:
3546
result = subprocess.run(
36-
[sys.executable, 'mkconcore.py', str(workflow_path), str(source_path), str(output_path), exec_type],
47+
[sys.executable, str(mkconcore_path), str(workflow_path), str(source_path), str(output_path), exec_type],
48+
cwd=mkconcore_path.parent,
3749
capture_output=True,
3850
text=True,
3951
check=True

mkconcore.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,22 @@
7272
import copy_with_port_portname
7373
import numpy as np
7474

75-
MKCONCORE_VER = "22-09-18"
76-
77-
GRAPHML_FILE = sys.argv[1]
78-
TRIMMED_LOGS = True
79-
CONCOREPATH = "."
75+
MKCONCORE_VER = "22-09-18"
76+
77+
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
78+
79+
def _resolve_concore_path():
80+
script_concore = os.path.join(SCRIPT_DIR, "concore.py")
81+
if os.path.exists(script_concore):
82+
return SCRIPT_DIR
83+
cwd_concore = os.path.join(os.getcwd(), "concore.py")
84+
if os.path.exists(cwd_concore):
85+
return os.getcwd()
86+
return SCRIPT_DIR
87+
88+
GRAPHML_FILE = sys.argv[1]
89+
TRIMMED_LOGS = True
90+
CONCOREPATH = _resolve_concore_path()
8091
CPPWIN = "g++" #Windows C++ 6/22/21
8192
CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21
8293
VWIN = "iverilog" #Windows verilog 6/25/21

tests/test_cli.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,22 @@ def test_run_command_missing_source(self):
6767
result = self.runner.invoke(cli, ['init', 'test-project'])
6868
result = self.runner.invoke(cli, ['run', 'test-project/workflow.graphml', '--source', 'nonexistent'])
6969
self.assertNotEqual(result.exit_code, 0)
70-
70+
71+
def test_run_command_from_project_dir(self):
72+
with self.runner.isolated_filesystem(temp_dir=self.temp_dir):
73+
result = self.runner.invoke(cli, ['init', 'test-project'])
74+
self.assertEqual(result.exit_code, 0)
75+
76+
result = self.runner.invoke(cli, [
77+
'run',
78+
'test-project/workflow.graphml',
79+
'--source', 'test-project/src',
80+
'--output', 'out',
81+
'--type', 'posix'
82+
])
83+
self.assertEqual(result.exit_code, 0)
84+
self.assertTrue(Path('out/src/concore.py').exists())
85+
7186
def test_run_command_existing_output(self):
7287
with self.runner.isolated_filesystem(temp_dir=self.temp_dir):
7388
result = self.runner.invoke(cli, ['init', 'test-project'])

0 commit comments

Comments
 (0)