mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Confirm that pyc files are written during installation
In order to add generated pyc files to the RECORD file for our package, we need to know their path! To raise confidence that we're doing this correctly, we assert the existence of the expected 'pyc' files while still using the old installation logic. Some valid reasons why pyc files may not be generated: 1. Syntax error in the installed Python files 2. There is already a pyc file in-place that isn't writable by the current user We don't fail installation in those cases today, and we wouldn't want to change our behavior here, so we only assert that the pyc file was created if `compileall.compile_file` indicates success.
This commit is contained in:
parent
4cb6f729ab
commit
2ece73cc86
1 changed files with 16 additions and 1 deletions
|
@ -7,6 +7,7 @@ import collections
|
|||
import compileall
|
||||
import contextlib
|
||||
import csv
|
||||
import importlib
|
||||
import logging
|
||||
import os.path
|
||||
import re
|
||||
|
@ -467,6 +468,18 @@ def install_unpacked_wheel(
|
|||
continue
|
||||
yield os.path.join(dir_path, path)
|
||||
|
||||
def pyc_output_path(path):
|
||||
# type: (text_type) -> text_type
|
||||
"""Return the path the pyc file would have been written to.
|
||||
"""
|
||||
if PY2:
|
||||
if sys.flags.optimize:
|
||||
return path + 'o'
|
||||
else:
|
||||
return path + 'c'
|
||||
else:
|
||||
return importlib.util.cache_from_source(path)
|
||||
|
||||
# Compile all of the pyc files that we're going to be installing
|
||||
if pycompile:
|
||||
with captured_stdout() as stdout:
|
||||
|
@ -478,9 +491,11 @@ def install_unpacked_wheel(
|
|||
path_arg = ensure_str(
|
||||
path, encoding=sys.getfilesystemencoding()
|
||||
)
|
||||
compileall.compile_file(
|
||||
success = compileall.compile_file(
|
||||
path_arg, force=True, quiet=True
|
||||
)
|
||||
if success:
|
||||
assert os.path.exists(pyc_output_path(path))
|
||||
logger.debug(stdout.getvalue())
|
||||
|
||||
def record_installed(srcfile, destfile, modified=False):
|
||||
|
|
Loading…
Reference in a new issue