Skip to content

Commit 519ee66

Browse files
authored
Merge pull request #413 from Titas-Ghosh/fix-mkconcore-path-handling
Fix mkconcore path handling for nested output directories
2 parents aa06d21 + 5354b99 commit 519ee66

2 files changed

Lines changed: 30 additions & 13 deletions

File tree

mkconcore.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def _resolve_concore_path():
142142
print(" type must be posix (macos or ubuntu), windows, or docker")
143143
sys.exit(1)
144144

145-
GRAPHML_FILE = sys.argv[1]
145+
ORIGINAL_CWD = os.getcwd()
146+
GRAPHML_FILE = os.path.abspath(sys.argv[1])
146147
TRIMMED_LOGS = True
147148
CONCOREPATH = _resolve_concore_path()
148149
CPPWIN = os.environ.get("CONCORE_CPPWIN", "g++") #Windows C++ 6/22/21
@@ -196,21 +197,22 @@ def _resolve_concore_path():
196197
OCTAVEEXE = _tools.get("OCTAVEEXE", OCTAVEEXE)
197198
OCTAVEWIN = _tools.get("OCTAVEWIN", OCTAVEWIN)
198199

199-
prefixedgenode = ""
200-
sourcedir = sys.argv[2]
201-
outdir = sys.argv[3]
202-
200+
prefixedgenode = ""
201+
sourcedir = os.path.abspath(sys.argv[2])
202+
outdir = os.path.abspath(sys.argv[3])
203+
203204
# Validate outdir argument (allow full paths)
204205
safe_name(outdir, "Output directory argument", allow_path=True)
205206

206207
if not os.path.isdir(sourcedir):
207208
logging.error(f"{sourcedir} does not exist")
208209
quit()
209210

210-
if len(sys.argv) == 4:
211-
prefixedgenode = outdir+"_" #nodes and edges prefixed with outdir_ only in case no type specified 3/24/21
212-
concoretype = "docker"
213-
else:
211+
if len(sys.argv) == 4:
212+
# Use only the output directory name in generated prefixes.
213+
prefixedgenode = os.path.basename(os.path.normpath(outdir)) + "_"
214+
concoretype = "docker"
215+
else:
214216
concoretype = sys.argv[4]
215217
if not (concoretype in ["posix","windows","docker","macos","ubuntu"]):
216218
logging.error(" type must be posix (macos or ubuntu), windows, or docker")
@@ -227,8 +229,8 @@ def _resolve_concore_path():
227229
logging.error(f"if intended, Remove/Rename {outdir} first")
228230
quit()
229231

230-
os.mkdir(outdir)
231-
os.chdir(outdir)
232+
os.makedirs(outdir)
233+
os.chdir(outdir)
232234
if concoretype == "windows":
233235
fbuild = open("build.bat","w")
234236
frun = open("run.bat", "w")
@@ -255,8 +257,8 @@ def cleanup_script_files():
255257
fh.close()
256258
atexit.register(cleanup_script_files)
257259

258-
os.mkdir("src")
259-
os.chdir("..")
260+
os.mkdir("src")
261+
os.chdir(ORIGINAL_CWD)
260262

261263
logging.info(f"mkconcore {MKCONCORE_VER}")
262264
logging.info(f"Concore path: {CONCOREPATH}")

tests/test_cli.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,21 @@ def test_run_command_default_type(self):
114114
else:
115115
self.assertTrue(Path('out/build').exists())
116116

117+
def test_run_command_nested_output_path(self):
118+
with self.runner.isolated_filesystem(temp_dir=self.temp_dir):
119+
result = self.runner.invoke(cli, ['init', 'test-project'])
120+
self.assertEqual(result.exit_code, 0)
121+
122+
result = self.runner.invoke(cli, [
123+
'run',
124+
'test-project/workflow.graphml',
125+
'--source', 'test-project/src',
126+
'--output', 'build/out',
127+
'--type', 'posix'
128+
])
129+
self.assertEqual(result.exit_code, 0)
130+
self.assertTrue(Path('build/out/src/concore.py').exists())
131+
117132
def test_run_command_subdir_source(self):
118133
with self.runner.isolated_filesystem(temp_dir=self.temp_dir):
119134
result = self.runner.invoke(cli, ['init', 'test-project'])

0 commit comments

Comments
 (0)