Skip to content

Commit

Permalink
Move imported path checking inside read_path() function (#407)
Browse files Browse the repository at this point in the history
This makes it work properly again!
  • Loading branch information
mkruselj authored Oct 25, 2023
1 parent 1760edb commit 3c22bf9
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions compiler/ksp_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,16 +411,21 @@ def read_path(basepath, filepath):
paths = []
out = ''

# see if we're importing a folder or a file
if os.path.isdir(path):
for root, dirs, files in os.walk(path):
for f in files:
split = os.path.splitext(f)

if split[1] == '.ksp':
paths.append(os.path.join(root, f))
elif os.path.isfile(path):
paths.append(path)
if os.path.exists(path):
# see if we're importing a folder or a file
if os.path.isdir(path):
for root, dirs, files in os.walk(path):
for f in files:
split = os.path.splitext(f)

if split[1] == '.ksp':
paths.append(os.path.join(root, f))
elif os.path.isfile(path):
paths.append(path)
else:
raise ParseException(line, 'Imported path does not exist or could not be read!\n\n'
'Try saving .ksp files before compiling in order to make relative paths work, '
'or check existence of the following path:\n\n%s' % path)

out_data = []

Expand Down Expand Up @@ -450,18 +455,13 @@ def read_path(basepath, filepath):
m = import_re.match(str(line))

if not m:
raise ParseException(line, "Syntax error in import statement!")
raise ParseException(line, 'Syntax error in import statement!')

# load the code in the given file
filename = m.group('filename')
namespace = m.group('asname')

try:
new_sources = read_path(basepath, filename)
except IOError:
raise ParseException(line, \
"File does not exist or could not be read! '%s' "
"\nTry saving the files before compiling in order to make relative paths work." % filename)
new_sources = read_path(basepath, filename)

for path, source in new_sources:
if path not in compiler_import_cache:
Expand Down

0 comments on commit 3c22bf9

Please sign in to comment.