Skip to content

Commit

Permalink
Supply a copy of _optim_args_from_interpreter_flags for Python 3.5 co…
Browse files Browse the repository at this point in the history
…mpatibility. Ref pypa/setuptools#2357.
  • Loading branch information
jaraco committed Sep 1, 2020
1 parent 607b411 commit 383e223
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions distutils/py35compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
import subprocess


def __optim_args_from_interpreter_flags():
"""Return a list of command-line arguments reproducing the current
optimization settings in sys.flags."""
args = []
value = sys.flags.optimize
if value > 0:
args.append("-" + "O" * value)
return args


_optim_args_from_interpreter_flags = getattr(
subprocess,
"_optim_args_from_interpreter_flags",
__optim_args_from_interpreter_flags,
)
4 changes: 3 additions & 1 deletion distutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from distutils.spawn import spawn
from distutils import log
from distutils.errors import DistutilsByteCompileError
from .py35compat import _optim_args_from_interpreter_flags


def get_host_platform():
"""Return a string that identifies the current platform. This is used mainly to
Expand Down Expand Up @@ -420,7 +422,7 @@ def byte_compile (py_files,
""" % (optimize, force, prefix, base_dir, verbose))

cmd = [sys.executable]
cmd.extend(subprocess._optim_args_from_interpreter_flags())
cmd.extend(_optim_args_from_interpreter_flags())
cmd.append(script_name)
spawn(cmd, dry_run=dry_run)
execute(os.remove, (script_name,), "removing %s" % script_name,
Expand Down

0 comments on commit 383e223

Please sign in to comment.