8
8
9
9
import collections
10
10
import compileall
11
+ import contextlib
11
12
import csv
12
13
import logging
13
14
import os .path
32
33
from pip ._internal .utils .misc import captured_stdout , ensure_dir , hash_file
33
34
from pip ._internal .utils .temp_dir import TempDirectory
34
35
from pip ._internal .utils .typing import MYPY_CHECK_RUNNING
35
- from pip ._internal .utils .unpacking import unpack_file
36
+ from pip ._internal .utils .unpacking import current_umask , unpack_file
36
37
from pip ._internal .utils .wheel import parse_wheel
37
38
38
39
if MYPY_CHECK_RUNNING :
39
40
from email .message import Message
40
41
from typing import (
41
42
Dict , List , Optional , Sequence , Tuple , Any ,
42
- Iterable , Callable , Set ,
43
+ Iterable , Iterator , Callable , Set ,
43
44
)
44
45
45
46
from pip ._internal .models .scheme import Scheme
47
+ from pip ._internal .utils .filesystem import NamedTemporaryFileResult
46
48
47
49
InstalledCSVRow = Tuple [str , ...]
48
50
@@ -565,19 +567,27 @@ def is_entrypoint_wrapper(name):
565
567
if msg is not None :
566
568
logger .warning (msg )
567
569
570
+ generated_file_mode = 0o666 - current_umask ()
571
+
572
+ @contextlib .contextmanager
573
+ def _generate_file (path , ** kwargs ):
574
+ # type: (str, **Any) -> Iterator[NamedTemporaryFileResult]
575
+ with adjacent_tmp_file (path , ** kwargs ) as f :
576
+ yield f
577
+ os .chmod (f .name , generated_file_mode )
578
+ replace (f .name , path )
579
+
568
580
# Record pip as the installer
569
581
installer_path = os .path .join (dest_info_dir , 'INSTALLER' )
570
- with adjacent_tmp_file (installer_path ) as installer_file :
582
+ with _generate_file (installer_path ) as installer_file :
571
583
installer_file .write (b'pip\n ' )
572
- replace (installer_file .name , installer_path )
573
584
generated .append (installer_path )
574
585
575
586
# Record the PEP 610 direct URL reference
576
587
if direct_url is not None :
577
588
direct_url_path = os .path .join (dest_info_dir , DIRECT_URL_METADATA_NAME )
578
- with adjacent_tmp_file (direct_url_path ) as direct_url_file :
589
+ with _generate_file (direct_url_path ) as direct_url_file :
579
590
direct_url_file .write (direct_url .to_json ().encode ("utf-8" ))
580
- replace (direct_url_file .name , direct_url_path )
581
591
generated .append (direct_url_path )
582
592
583
593
# Record details of all files installed
@@ -589,10 +599,9 @@ def is_entrypoint_wrapper(name):
589
599
changed = changed ,
590
600
generated = generated ,
591
601
lib_dir = lib_dir )
592
- with adjacent_tmp_file (record_path , ** csv_io_kwargs ('w' )) as record_file :
602
+ with _generate_file (record_path , ** csv_io_kwargs ('w' )) as record_file :
593
603
writer = csv .writer (record_file )
594
604
writer .writerows (sorted_outrows (rows )) # sort to simplify testing
595
- replace (record_file .name , record_path )
596
605
597
606
598
607
def install_wheel (
0 commit comments