diff --git a/concore_cli/commands/run.py b/concore_cli/commands/run.py index c6aaed2..91a876b 100644 --- a/concore_cli/commands/run.py +++ b/concore_cli/commands/run.py @@ -5,10 +5,17 @@ from rich.panel import Panel from rich.progress import Progress, SpinnerColumn, TextColumn +def _find_mkconcore_path(): + for parent in Path(__file__).resolve().parents: + candidate = parent / "mkconcore.py" + if candidate.exists(): + return candidate + return None + def run_workflow(workflow_file, source, output, exec_type, auto_build, console): workflow_path = Path(workflow_file).resolve() source_path = Path(source).resolve() - output_path = Path(output) + output_path = Path(output).resolve() if not source_path.exists(): raise FileNotFoundError(f"Source directory '{source}' not found") @@ -24,6 +31,10 @@ def run_workflow(workflow_file, source, output, exec_type, auto_build, console): console.print(f"[cyan]Type:[/cyan] {exec_type}") console.print() + mkconcore_path = _find_mkconcore_path() + if mkconcore_path is None: + raise FileNotFoundError("mkconcore.py not found. Please install concore from source.") + with Progress( SpinnerColumn(), TextColumn("[progress.description]{task.description}"), @@ -33,7 +44,8 @@ def run_workflow(workflow_file, source, output, exec_type, auto_build, console): try: result = subprocess.run( - [sys.executable, 'mkconcore.py', str(workflow_path), str(source_path), str(output_path), exec_type], + [sys.executable, str(mkconcore_path), str(workflow_path), str(source_path), str(output_path), exec_type], + cwd=mkconcore_path.parent, capture_output=True, text=True, check=True diff --git a/mkconcore.py b/mkconcore.py index 10135dc..e630dd9 100644 --- a/mkconcore.py +++ b/mkconcore.py @@ -72,11 +72,22 @@ import copy_with_port_portname import numpy as np -MKCONCORE_VER = "22-09-18" - -GRAPHML_FILE = sys.argv[1] -TRIMMED_LOGS = True -CONCOREPATH = "." +MKCONCORE_VER = "22-09-18" + +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) + +def _resolve_concore_path(): + script_concore = os.path.join(SCRIPT_DIR, "concore.py") + if os.path.exists(script_concore): + return SCRIPT_DIR + cwd_concore = os.path.join(os.getcwd(), "concore.py") + if os.path.exists(cwd_concore): + return os.getcwd() + return SCRIPT_DIR + +GRAPHML_FILE = sys.argv[1] +TRIMMED_LOGS = True +CONCOREPATH = _resolve_concore_path() CPPWIN = "g++" #Windows C++ 6/22/21 CPPEXE = "g++" #Ubuntu/macOS C++ 6/22/21 VWIN = "iverilog" #Windows verilog 6/25/21 diff --git a/tests/test_cli.py b/tests/test_cli.py index af31a36..a90cc3f 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -67,7 +67,22 @@ def test_run_command_missing_source(self): result = self.runner.invoke(cli, ['init', 'test-project']) result = self.runner.invoke(cli, ['run', 'test-project/workflow.graphml', '--source', 'nonexistent']) self.assertNotEqual(result.exit_code, 0) - + + def test_run_command_from_project_dir(self): + with self.runner.isolated_filesystem(temp_dir=self.temp_dir): + result = self.runner.invoke(cli, ['init', 'test-project']) + self.assertEqual(result.exit_code, 0) + + result = self.runner.invoke(cli, [ + 'run', + 'test-project/workflow.graphml', + '--source', 'test-project/src', + '--output', 'out', + '--type', 'posix' + ]) + self.assertEqual(result.exit_code, 0) + self.assertTrue(Path('out/src/concore.py').exists()) + def test_run_command_existing_output(self): with self.runner.isolated_filesystem(temp_dir=self.temp_dir): result = self.runner.invoke(cli, ['init', 'test-project'])