Skip to content

Commit 7b3a649

Browse files
committed
add the option to compile code as a module. can also provide the base path to use for generating the dotted path.
1 parent 4e41f1e commit 7b3a649

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pyjs.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ def compile_file(infile, outfile, options):
7272
outfile.write('load("py-builtins.js");\n')
7373

7474
c = Compiler()
75-
c.append_string(infile.read())
75+
if options.as_module:
76+
kwargs = {}
77+
if options.module_base:
78+
kwargs["base"] = options.module_base
79+
c.append_module(infile.read(), infile.name, **kwargs)
80+
else:
81+
c.append_string(infile.read())
7682
outfile.write(str(c))
7783

7884
def run_once(input_filenames, options):
@@ -231,6 +237,18 @@ def main():
231237
default = False,
232238
help = "Watch the input files for changes and recompile. If the input file is a single file, watch it for changes and recompile. If a directory, recompile if any .py or .pyjaco files in the directory have changes.")
233239

240+
parser.add_option("-m", "--as-module",
241+
action = "store_true",
242+
dest = "as_module",
243+
default = False,
244+
help = "Compile code as a module.")
245+
246+
parser.add_option("--base",
247+
action = "store",
248+
dest = "module_base",
249+
default = None,
250+
help = "base path used to calculate dotted path for module")
251+
234252
options, args = parser.parse_args()
235253

236254
if len(args) == 0 and options.builtins != "generate":

0 commit comments

Comments
 (0)