Skip to content

Commit

Permalink
Use better temporary files mechanism in install_unpacked_wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Grant committed Feb 5, 2020
1 parent 34d97cf commit b57e097
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 6 deletions.
63 changes: 63 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,69 @@
.. towncrier release notes start
20.1.dev0 (2020-02-05)
======================



20.1.dev0 (2020-02-05)
======================



20.1.dev0 (2020-02-05)
======================



20.1.dev0 (2020-02-05)
======================

No significant changes.


20.1.dev0 (2020-02-05)
======================

Deprecations and Removals
-------------------------

- Remove unused ``tests/scripts/test_all_pip.py`` test script and the ``tests/scripts`` folder. (`#7680 <https://github.com/pypa/pip/issues/7680>`_)

Vendored Libraries
------------------

- Update semi-supported debundling script to reflect that appdirs is vendored.


20.1.dev0 (2020-02-05)
======================

Deprecations and Removals
-------------------------

- Remove unused ``tests/scripts/test_all_pip.py`` test script and the ``tests/scripts`` folder. (`#7680 <https://github.com/pypa/pip/issues/7680>`_)

Vendored Libraries
------------------

- Update semi-supported debundling script to reflect that appdirs is vendored.


20.1.dev0 (2020-02-05)
======================

Deprecations and Removals
-------------------------

- Remove unused ``tests/scripts/test_all_pip.py`` test script and the ``tests/scripts`` folder. (`#7680 <https://github.com/pypa/pip/issues/7680>`_)

Vendored Libraries
------------------

- Update semi-supported debundling script to reflect that appdirs is vendored.


20.0.2 (2020-01-24)
===================

Expand Down
1 change: 0 additions & 1 deletion news/7680.removal

This file was deleted.

1 change: 0 additions & 1 deletion news/7690.vendor

This file was deleted.

Empty file.
Empty file.
Empty file.
6 changes: 3 additions & 3 deletions src/pip/_internal/operations/install/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from pip._internal.exceptions import InstallationError
from pip._internal.locations import get_major_minor_version
from pip._internal.utils.filesystem import adjacent_tmp_file, replace
from pip._internal.utils.misc import captured_stdout, ensure_dir, hash_file
from pip._internal.utils.temp_dir import TempDirectory
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
Expand Down Expand Up @@ -575,9 +576,8 @@ def is_entrypoint_wrapper(name):

# Record details of all files installed
record = os.path.join(dest_info_dir, 'RECORD')
temp_record = os.path.join(dest_info_dir, 'RECORD.pip')
with open_for_csv(record, 'r') as record_in:
with open_for_csv(temp_record, 'w+') as record_out:
with adjacent_tmp_file(record, mode='w') as record_out:
reader = csv.reader(record_in)
outrows = get_csv_rows_for_installed(
reader, installed=installed, changed=changed,
Expand All @@ -587,7 +587,7 @@ def is_entrypoint_wrapper(name):
# Sort to simplify testing.
for row in sorted_outrows(outrows):
writer.writerow(row)
shutil.move(temp_record, record)
replace(record_out.name, record)


def install_wheel(
Expand Down
3 changes: 2 additions & 1 deletion src/pip/_internal/utils/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ def is_socket(path):


@contextmanager
def adjacent_tmp_file(path):
def adjacent_tmp_file(path, mode='w+b'):
# type: (str) -> Iterator[NamedTemporaryFileResult]
"""Given a path to a file, open a temp file next to it securely and ensure
it is written to disk after the context reaches its end.
"""
with NamedTemporaryFile(
mode=mode,
delete=False,
dir=os.path.dirname(path),
prefix=os.path.basename(path),
Expand Down

0 comments on commit b57e097

Please sign in to comment.