Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Don't parse stub file if interpreter is explicitly provided #128

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions compiler/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def make_command_line_parser():
required=True)
parser.add_argument(
'--stub_file',
help='Read imports and interpreter path from the specified stub file',
help='Read interpreter path from the specified stub file',
required=True)
parser.add_argument(
'--interpreter',
Expand Down Expand Up @@ -156,10 +156,7 @@ def main(argv):
args = parser.parse_args(argv[1:])

# Parse interpreter from stub file that's not available in Starlark
interpreter = parse_stub(args.stub_file)

if args.interpreter:
interpreter = args.interpreter
interpreter = args.interpreter or parse_stub(args.stub_file)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note parse_stub also validates interpreter. Really it should be broken into parse_interpreter and validate_interpreter
then this would be:

interpreter = args.interpreter or parse_interpreter(args.stub_file)
validate_interperter(interpreter)

or something


par = python_archive.PythonArchive(
main_filename=args.main_filename,
Expand Down
7 changes: 7 additions & 0 deletions subpar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def _parfile_impl(ctx):
]
for import_root in import_roots:
args.extend(['--import_root', import_root])
if ctx.attr.interpreter:
args.extend(['--interpreter', ctx.attr.interpreter])
args.append(main_py_file.path)

# Run compiler
Expand Down Expand Up @@ -137,6 +139,7 @@ parfile_attrs = {
cfg = "host",
),
"compiler_args": attr.string_list(default = []),
"interpreter": attr.string(),
dflems marked this conversation as resolved.
Show resolved Hide resolved
"zip_safe": attr.bool(default = True),
}

Expand Down Expand Up @@ -205,6 +208,7 @@ def par_binary(name, **kwargs):
"""
compiler = kwargs.pop("compiler", None)
compiler_args = kwargs.pop("compiler_args", [])
interpreter = kwargs.pop("interpreter", None)
zip_safe = kwargs.pop("zip_safe", True)
py_binary(name = name, **kwargs)

Expand All @@ -219,6 +223,7 @@ def par_binary(name, **kwargs):
compiler_args = compiler_args,
default_python_version = default_python_version,
imports = imports,
interpreter = interpreter,
main = main,
name = name + ".par",
src = name,
Expand All @@ -235,6 +240,7 @@ def par_test(name, **kwargs):
specifically need to test a module's behaviour when used in a .par binary.
"""
compiler = kwargs.pop("compiler", None)
interpreter = kwargs.pop("interpreter", None)
zip_safe = kwargs.pop("zip_safe", True)
py_test(name = name, **kwargs)

Expand All @@ -248,6 +254,7 @@ def par_test(name, **kwargs):
compiler = compiler,
default_python_version = default_python_version,
imports = imports,
interpreter = interpreter,
main = main,
name = name + ".par",
src = name,
Expand Down