Commit b145c6d1 authored by Godefroid Chapelle's avatar Godefroid Chapelle

Problem: files opened without check that they exist

Solution: proper os.path.isfile each time it is needed in
make_egg_after_pip_install

some variable rename
parent 0c8d2e57
Check that file top_level.txt exists before opening.
Add check for other files as well.
...@@ -1716,9 +1716,12 @@ def make_egg_after_pip_install(dest, distinfo_dir): ...@@ -1716,9 +1716,12 @@ def make_egg_after_pip_install(dest, distinfo_dir):
# `pip install` does not build the namespace aware __init__.py files # `pip install` does not build the namespace aware __init__.py files
# but they are needed in egg directories. # but they are needed in egg directories.
# Add them before moving files setup by pip # Add them before moving files setup by pip
ns_file = os.path.join(dest, distinfo_dir, 'namespace_packages.txt') namespace_packages_file = os.path.join(
if os.path.exists(ns_file): dest, distinfo_dir,
with open(ns_file) as f: 'namespace_packages.txt'
)
if os.path.isfile(namespace_packages_file):
with open(namespace_packages_file) as f:
namespace_packages = [ namespace_packages = [
line.strip().replace('.', os.path.sep) line.strip().replace('.', os.path.sep)
for line in f.readlines() for line in f.readlines()
...@@ -1734,9 +1737,9 @@ def make_egg_after_pip_install(dest, distinfo_dir): ...@@ -1734,9 +1737,9 @@ def make_egg_after_pip_install(dest, distinfo_dir):
# Remove `bin` directory if needed # Remove `bin` directory if needed
# as there is no way to avoid script installation # as there is no way to avoid script installation
# when running `pip install` # when running `pip install`
ep_file = os.path.join(dest, distinfo_dir, 'entry_points.txt') entry_points_file = os.path.join(dest, distinfo_dir, 'entry_points.txt')
if os.path.exists(ep_file): if os.path.isfile(entry_points_file):
with open(ep_file) as f: with open(entry_points_file) as f:
content = f.read() content = f.read()
if "console_scripts" in content or "gui_scripts" in content: if "console_scripts" in content or "gui_scripts" in content:
bin_dir = os.path.join(dest, BIN_SCRIPTS) bin_dir = os.path.join(dest, BIN_SCRIPTS)
...@@ -1759,11 +1762,15 @@ def make_egg_after_pip_install(dest, distinfo_dir): ...@@ -1759,11 +1762,15 @@ def make_egg_after_pip_install(dest, distinfo_dir):
os.path.join(egg_dir, new_distinfo_dir) os.path.join(egg_dir, new_distinfo_dir)
) )
with open(os.path.join(egg_dir, new_distinfo_dir, 'top_level.txt')) as f: top_level_file = os.path.join(egg_dir, new_distinfo_dir, 'top_level.txt')
if os.path.isfile(top_level_file):
with open(top_level_file) as f:
top_levels = filter( top_levels = filter(
(lambda x: len(x) != 0), (lambda x: len(x) != 0),
[line.strip() for line in f.readlines()] [line.strip() for line in f.readlines()]
) )
else:
top_levels = ()
# Move all top_level modules or packages # Move all top_level modules or packages
for top_level in top_levels: for top_level in top_levels:
...@@ -1781,11 +1788,13 @@ def make_egg_after_pip_install(dest, distinfo_dir): ...@@ -1781,11 +1788,13 @@ def make_egg_after_pip_install(dest, distinfo_dir):
shutil.move(top_level_pyc, egg_dir) shutil.move(top_level_pyc, egg_dir)
continue continue
record_file = os.path.join(egg_dir, new_distinfo_dir, 'RECORD')
if os.path.isfile(record_file):
if PY3: if PY3:
with open(os.path.join(egg_dir, new_distinfo_dir, 'RECORD'), newline='') as f: with open(record_file, newline='') as f:
all_files = [row[0] for row in csv.reader(f)] all_files = [row[0] for row in csv.reader(f)]
else: else:
with open(os.path.join(egg_dir, new_distinfo_dir, 'RECORD'), 'rb') as f: with open(record_file, 'rb') as f:
all_files = [row[0] for row in csv.reader(f)] all_files = [row[0] for row in csv.reader(f)]
# There might be some c extensions left over # There might be some c extensions left over
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment