From 732466cc888dc3a8a853e884be6cc5556f583f9b Mon Sep 17 00:00:00 2001 From: Tomer Vromen Date: Sun, 29 Mar 2020 16:45:02 +0300 Subject: [PATCH 1/4] Enable running with alternative python, inside venv --- pyperformance/cli.py | 13 +++++++++++-- pyperformance/cli_run.py | 7 ++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pyperformance/cli.py b/pyperformance/cli.py index dbfe4645..a39c3491 100644 --- a/pyperformance/cli.py +++ b/pyperformance/cli.py @@ -150,7 +150,9 @@ def parse_args(): "inside the virtual environment.")) cmd.add_argument("-p", "--python", help="Python executable (default: use running Python)", - default=sys.executable) + # See comment below + # default=sys.executable + ) cmd.add_argument("--venv", help="Path to the virtual environment") @@ -164,7 +166,7 @@ def parse_args(): parser.print_help() sys.exit(1) - if hasattr(options, 'python'): + if options.python is not None: # Replace "~" with the user home directory options.python = os.path.expanduser(options.python) # Try to the absolute path to the binary @@ -174,6 +176,13 @@ def parse_args(): options.python) sys.exit(1) options.python = os.path.realpath(abs_python) + else: + # It would seems like it's possible to put sys.executable as the + # default when calling add_argument, but for some reason it returns + # another value in some cases: When the python binary is a symbolic + # link, the sys.executable in add_argument returns the realpath, while + # here it returns the relative path (before following the link). + options.python = sys.executable return (parser, options) diff --git a/pyperformance/cli_run.py b/pyperformance/cli_run.py index c5009e28..cb38e9ec 100644 --- a/pyperformance/cli_run.py +++ b/pyperformance/cli_run.py @@ -26,11 +26,12 @@ def cmd_run(parser, options): print("ERROR: the output file %s already exists!" % options.output) sys.exit(1) - if not os.path.isabs(sys.executable): - print("ERROR: sys.executable is not an absolute path") + executable = options.python + if not os.path.isabs(executable): + print("ERROR: \"%s\" is not an absolute path" % executable) sys.exit(1) bench_funcs, bench_groups, should_run = get_benchmarks_to_run(options) - cmd_prefix = [sys.executable] + cmd_prefix = [executable] suite, errors = run_benchmarks(bench_funcs, should_run, cmd_prefix, options) if not suite: From 3a2468ecf1daf80cc4f1dc2c67e2651de292241d Mon Sep 17 00:00:00 2001 From: Tomer Vromen Date: Mon, 30 Mar 2020 08:29:55 +0300 Subject: [PATCH 2/4] fixup: fix after CI failure --- pyperformance/cli.py | 35 ++++++++++++++++++----------------- pyperformance/cli_run.py | 4 +++- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/pyperformance/cli.py b/pyperformance/cli.py index a39c3491..65bec87b 100644 --- a/pyperformance/cli.py +++ b/pyperformance/cli.py @@ -166,23 +166,24 @@ def parse_args(): parser.print_help() sys.exit(1) - if options.python is not None: - # Replace "~" with the user home directory - options.python = os.path.expanduser(options.python) - # Try to the absolute path to the binary - abs_python = shutil.which(options.python) - if not abs_python: - print("ERROR: Unable to locate the Python executable: %r" % - options.python) - sys.exit(1) - options.python = os.path.realpath(abs_python) - else: - # It would seems like it's possible to put sys.executable as the - # default when calling add_argument, but for some reason it returns - # another value in some cases: When the python binary is a symbolic - # link, the sys.executable in add_argument returns the realpath, while - # here it returns the relative path (before following the link). - options.python = sys.executable + if hasattr(options, 'python'): + if options.python is not None: + # Replace "~" with the user home directory + options.python = os.path.expanduser(options.python) + # Try to the absolute path to the binary + abs_python = shutil.which(options.python) + if not abs_python: + print("ERROR: Unable to locate the Python executable: %r" % + options.python) + sys.exit(1) + options.python = os.path.realpath(abs_python) + else: + # It would seems like it's possible to put sys.executable as the + # default when calling add_argument, but for some reason it returns + # another value in some cases: When the python binary is a symbolic + # link, the sys.executable in add_argument returns the realpath, while + # here it returns the relative path (before following the link). + options.python = sys.executable return (parser, options) diff --git a/pyperformance/cli_run.py b/pyperformance/cli_run.py index cb38e9ec..aab07e38 100644 --- a/pyperformance/cli_run.py +++ b/pyperformance/cli_run.py @@ -26,7 +26,9 @@ def cmd_run(parser, options): print("ERROR: the output file %s already exists!" % options.output) sys.exit(1) - executable = options.python + executable = sys.executable + if hasattr(options, 'python'): + executable = options.python if not os.path.isabs(executable): print("ERROR: \"%s\" is not an absolute path" % executable) sys.exit(1) From a4754082f0cbbd30030b6def5684ac10b33e3119 Mon Sep 17 00:00:00 2001 From: Tomer Vromen Date: Tue, 31 Mar 2020 10:07:28 +0300 Subject: [PATCH 3/4] fixup: after code review; undo some of the original changes and replace with another solution --- pyperformance/cli.py | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/pyperformance/cli.py b/pyperformance/cli.py index 65bec87b..7902c5cb 100644 --- a/pyperformance/cli.py +++ b/pyperformance/cli.py @@ -150,9 +150,7 @@ def parse_args(): "inside the virtual environment.")) cmd.add_argument("-p", "--python", help="Python executable (default: use running Python)", - # See comment below - # default=sys.executable - ) + default=sys.executable) cmd.add_argument("--venv", help="Path to the virtual environment") @@ -167,23 +165,15 @@ def parse_args(): sys.exit(1) if hasattr(options, 'python'): - if options.python is not None: - # Replace "~" with the user home directory - options.python = os.path.expanduser(options.python) - # Try to the absolute path to the binary - abs_python = shutil.which(options.python) - if not abs_python: - print("ERROR: Unable to locate the Python executable: %r" % - options.python) - sys.exit(1) - options.python = os.path.realpath(abs_python) - else: - # It would seems like it's possible to put sys.executable as the - # default when calling add_argument, but for some reason it returns - # another value in some cases: When the python binary is a symbolic - # link, the sys.executable in add_argument returns the realpath, while - # here it returns the relative path (before following the link). - options.python = sys.executable + # Replace "~" with the user home directory + options.python = os.path.expanduser(options.python) + # Try to the absolute path to the binary + abs_python = os.path.abspath(options.python) + if not abs_python: + print("ERROR: Unable to locate the Python executable: %r" % + options.python) + sys.exit(1) + options.python = abs_python return (parser, options) From d007eea3b36a0b60bf8691862c029f492fe651f7 Mon Sep 17 00:00:00 2001 From: tomerv Date: Wed, 1 Apr 2020 08:28:32 +0300 Subject: [PATCH 4/4] fixup: Apply suggestions from code review Co-Authored-By: Victor Stinner --- pyperformance/cli.py | 2 +- pyperformance/cli_run.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pyperformance/cli.py b/pyperformance/cli.py index 7902c5cb..8c7ca310 100644 --- a/pyperformance/cli.py +++ b/pyperformance/cli.py @@ -167,7 +167,7 @@ def parse_args(): if hasattr(options, 'python'): # Replace "~" with the user home directory options.python = os.path.expanduser(options.python) - # Try to the absolute path to the binary + # Try to get the absolute path to the binary abs_python = os.path.abspath(options.python) if not abs_python: print("ERROR: Unable to locate the Python executable: %r" % diff --git a/pyperformance/cli_run.py b/pyperformance/cli_run.py index aab07e38..a760c877 100644 --- a/pyperformance/cli_run.py +++ b/pyperformance/cli_run.py @@ -26,9 +26,10 @@ def cmd_run(parser, options): print("ERROR: the output file %s already exists!" % options.output) sys.exit(1) - executable = sys.executable if hasattr(options, 'python'): executable = options.python + else: + executable = sys.executable if not os.path.isabs(executable): print("ERROR: \"%s\" is not an absolute path" % executable) sys.exit(1)