|
75 | 75 | )
|
76 | 76 | import pkg_resources
|
77 | 77 | from ..compat import py311
|
| 78 | +from ..compat.encoding import encoding_for_open |
78 | 79 | from .._path import ensure_directory
|
79 | 80 | from ..extern.jaraco.text import yield_lines
|
80 |
| -import locale |
81 |
| - |
82 | 81 |
|
83 | 82 | # Turn on PEP440Warnings
|
84 | 83 | warnings.filterwarnings("default", category=pkg_resources.PEP440Warning)
|
@@ -492,7 +491,7 @@ def check_site_dir(self): # noqa: C901 # is too complex (12) # FIXME
|
492 | 491 | try:
|
493 | 492 | if test_exists:
|
494 | 493 | os.unlink(testfile)
|
495 |
| - open(testfile, 'w', encoding=locale.getpreferredencoding(False)).close() |
| 494 | + open(testfile, 'w', encoding=encoding_for_open).close() |
496 | 495 | os.unlink(testfile)
|
497 | 496 | except OSError:
|
498 | 497 | self.cant_write_to_target()
|
@@ -589,7 +588,7 @@ def check_pth_processing(self):
|
589 | 588 | os.unlink(ok_file)
|
590 | 589 | dirname = os.path.dirname(ok_file)
|
591 | 590 | os.makedirs(dirname, exist_ok=True)
|
592 |
| - f = open(pth_file, 'w', encoding=locale.getpreferredencoding(False)) |
| 591 | + f = open(pth_file, 'w', encoding=encoding_for_open) |
593 | 592 | except OSError:
|
594 | 593 | self.cant_write_to_target()
|
595 | 594 | else:
|
@@ -1017,7 +1016,7 @@ def install_exe(self, dist_filename, tmpdir):
|
1017 | 1016 |
|
1018 | 1017 | # Write EGG-INFO/PKG-INFO
|
1019 | 1018 | if not os.path.exists(pkg_inf):
|
1020 |
| - f = open(pkg_inf, 'w', encoding=locale.getpreferredencoding(False)) |
| 1019 | + f = open(pkg_inf, 'w', encoding=encoding_for_open) |
1021 | 1020 | f.write('Metadata-Version: 1.0\n')
|
1022 | 1021 | for k, v in cfg.items('metadata'):
|
1023 | 1022 | if k != 'target_version':
|
@@ -1088,7 +1087,7 @@ def process(src, dst):
|
1088 | 1087 | if locals()[name]:
|
1089 | 1088 | txt = os.path.join(egg_tmp, 'EGG-INFO', name + '.txt')
|
1090 | 1089 | if not os.path.exists(txt):
|
1091 |
| - f = open(txt, 'w', encoding=locale.getpreferredencoding(False)) |
| 1090 | + f = open(txt, 'w', encoding=encoding_for_open) |
1092 | 1091 | f.write('\n'.join(locals()[name]) + '\n')
|
1093 | 1092 | f.close()
|
1094 | 1093 |
|
@@ -1278,7 +1277,7 @@ def update_pth(self, dist): # noqa: C901 # is too complex (11) # FIXME
|
1278 | 1277 | filename = os.path.join(self.install_dir, 'setuptools.pth')
|
1279 | 1278 | if os.path.islink(filename):
|
1280 | 1279 | os.unlink(filename)
|
1281 |
| - with open(filename, 'wt', encoding=locale.getpreferredencoding(False)) as f: |
| 1280 | + with open(filename, 'wt', encoding=encoding_for_open) as f: |
1282 | 1281 | f.write(self.pth_file.make_relative(dist.location) + '\n')
|
1283 | 1282 |
|
1284 | 1283 | def unpack_progress(self, src, dst):
|
@@ -1504,9 +1503,7 @@ def expand_paths(inputs): # noqa: C901 # is too complex (11) # FIXME
|
1504 | 1503 | continue
|
1505 | 1504 |
|
1506 | 1505 | # Read the .pth file
|
1507 |
| - f = open( |
1508 |
| - os.path.join(dirname, name), encoding=locale.getpreferredencoding(False) |
1509 |
| - ) |
| 1506 | + f = open(os.path.join(dirname, name), encoding=encoding_for_open) |
1510 | 1507 | lines = list(yield_lines(f))
|
1511 | 1508 | f.close()
|
1512 | 1509 |
|
@@ -1622,7 +1619,7 @@ def _load_raw(self):
|
1622 | 1619 | paths = []
|
1623 | 1620 | dirty = saw_import = False
|
1624 | 1621 | seen = dict.fromkeys(self.sitedirs)
|
1625 |
| - f = open(self.filename, 'rt', encoding=locale.getpreferredencoding(False)) |
| 1622 | + f = open(self.filename, 'rt', encoding=encoding_for_open) |
1626 | 1623 | for line in f:
|
1627 | 1624 | path = line.rstrip()
|
1628 | 1625 | # still keep imports and empty/commented lines for formatting
|
@@ -1693,9 +1690,7 @@ def save(self):
|
1693 | 1690 | data = '\n'.join(lines) + '\n'
|
1694 | 1691 | if os.path.islink(self.filename):
|
1695 | 1692 | os.unlink(self.filename)
|
1696 |
| - with open( |
1697 |
| - self.filename, 'wt', encoding=locale.getpreferredencoding(False) |
1698 |
| - ) as f: |
| 1693 | + with open(self.filename, 'wt', encoding=encoding_for_open) as f: |
1699 | 1694 | f.write(data)
|
1700 | 1695 | elif os.path.exists(self.filename):
|
1701 | 1696 | log.debug("Deleting empty %s", self.filename)
|
|
0 commit comments