Skip to content

Commit 7ab05be

Browse files
authored
Merge pull request #215 from Titas-Ghosh/fix-concore-run-path-error
Fix: Enable concore run execution from outside repository root
2 parents 8a42f69 + b76aa45 commit 7ab05be

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
@@ -86,11 +86,22 @@ def safe_name(value, context):
8686
raise ValueError(f"Unsafe {context}: '{value}' contains illegal characters.")
8787
return value
8888

89-
MKCONCORE_VER = "22-09-18"
90-
91-
GRAPHML_FILE = sys.argv[1]
92-
TRIMMED_LOGS = True
93-
CONCOREPATH = "."
89+
MKCONCORE_VER = "22-09-18"
90+
91+
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
92+
93+
def _resolve_concore_path():
94+
script_concore = os.path.join(SCRIPT_DIR, "concore.py")
95+
if os.path.exists(script_concore):
96+
return SCRIPT_DIR
97+
cwd_concore = os.path.join(os.getcwd(), "concore.py")
98+
if os.path.exists(cwd_concore):
99+
return os.getcwd()
100+
return SCRIPT_DIR
101+
102+
GRAPHML_FILE = sys.argv[1]
103+
TRIMMED_LOGS = True
104+
CONCOREPATH = _resolve_concore_path()
94105
CPPWIN = "g++" #Windows C++ 6/22/21
95106
CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21
96107
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)