diff options
author | Filipe LaĆns <filipe.lains@gmail.com> | 2023-03-12 16:26:44 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-12 09:26:44 -0700 |
commit | e2a9ee59e58c48a663bb435dbeb36a160272f695 (patch) | |
tree | 63a66224afd78a6ce12af3af8b88b0ce1a764938 /src | |
parent | 0398e5b3ba4256851f046a3a350cee2309953a82 (diff) | |
download | virtualenv-e2a9ee59e58c48a663bb435dbeb36a160272f695.tar.gz |
Sepcify the encoding (#2515)
Diffstat (limited to 'src')
-rw-r--r-- | src/virtualenv/app_data/via_disk_folder.py | 4 | ||||
-rw-r--r-- | src/virtualenv/config/ini.py | 2 | ||||
-rw-r--r-- | src/virtualenv/create/creator.py | 2 | ||||
-rw-r--r-- | src/virtualenv/create/via_global_ref/api.py | 6 | ||||
-rw-r--r-- | src/virtualenv/create/via_global_ref/builtin/python2/python2.py | 4 | ||||
-rw-r--r-- | src/virtualenv/discovery/cached_py_info.py | 1 | ||||
-rw-r--r-- | src/virtualenv/seed/embed/via_app_data/pip_install/base.py | 16 | ||||
-rw-r--r-- | src/virtualenv/seed/wheels/acquire.py | 2 | ||||
-rw-r--r-- | src/virtualenv/util/subprocess/__init__.py | 1 |
9 files changed, 23 insertions, 15 deletions
diff --git a/src/virtualenv/app_data/via_disk_folder.py b/src/virtualenv/app_data/via_disk_folder.py index ad8292c..6c7f558 100644 --- a/src/virtualenv/app_data/via_disk_folder.py +++ b/src/virtualenv/app_data/via_disk_folder.py @@ -125,7 +125,7 @@ class JSONStoreDisk(ContentStore, metaclass=ABCMeta): def read(self): data, bad_format = None, False try: - data = json.loads(self.file.read_text()) + data = json.loads(self.file.read_text(encoding="utf-8")) logging.debug(f"got {self.msg} from %s", *self.msg_args) return data except ValueError: @@ -151,7 +151,7 @@ class JSONStoreDisk(ContentStore, metaclass=ABCMeta): def write(self, content): folder = self.file.parent folder.mkdir(parents=True, exist_ok=True) - self.file.write_text(json.dumps(content, sort_keys=True, indent=2)) + self.file.write_text(json.dumps(content, sort_keys=True, indent=2), encoding="utf-8") logging.debug(f"wrote {self.msg} at %s", *self.msg_args) diff --git a/src/virtualenv/config/ini.py b/src/virtualenv/config/ini.py index 50da884..f977fc0 100644 --- a/src/virtualenv/config/ini.py +++ b/src/virtualenv/config/ini.py @@ -44,7 +44,7 @@ class IniConfig: logging.error("failed to read config file %s because %r", config_file, exception) def _load(self): - with self.config_file.open("rt") as file_handler: + with self.config_file.open("rt", encoding="utf-8") as file_handler: return self.config_parser.read_file(file_handler) def get(self, key, as_type): diff --git a/src/virtualenv/create/creator.py b/src/virtualenv/create/creator.py index a973264..e561a3f 100644 --- a/src/virtualenv/create/creator.py +++ b/src/virtualenv/create/creator.py @@ -163,7 +163,7 @@ class Creator(metaclass=ABCMeta): # mark this folder to be ignored by VCS, handle https://www.python.org/dev/peps/pep-0610/#registered-vcs git_ignore = self.dest / ".gitignore" if not git_ignore.exists(): - git_ignore.write_text("# created by virtualenv automatically\n*\n") + git_ignore.write_text("# created by virtualenv automatically\n*\n", encoding="utf-8") # Mercurial - does not support the .hgignore file inside a subdirectory directly, but only if included via the # subinclude directive from root, at which point on might as well ignore the directory itself, see # https://www.selenic.com/mercurial/hgignore.5.html for more details diff --git a/src/virtualenv/create/via_global_ref/api.py b/src/virtualenv/create/via_global_ref/api.py index 7a4086f..884452e 100644 --- a/src/virtualenv/create/via_global_ref/api.py +++ b/src/virtualenv/create/via_global_ref/api.py @@ -87,15 +87,15 @@ class ViaGlobalRefApi(Creator, metaclass=ABCMeta): if text: pth = self.purelib / "_virtualenv.pth" logging.debug("create virtualenv import hook file %s", pth) - pth.write_text("import _virtualenv") + pth.write_text("import _virtualenv", encoding="utf-8") dest_path = self.purelib / "_virtualenv.py" logging.debug("create %s", dest_path) - dest_path.write_text(text) + dest_path.write_text(text, encoding="utf-8") def env_patch_text(self): """Patch the distutils package to not be derailed by its configuration files""" with self.app_data.ensure_extracted(Path(__file__).parent / "_virtualenv.py") as resolved_path: - text = resolved_path.read_text() + text = resolved_path.read_text(encoding="utf-8") return text.replace('"__SCRIPT_DIR__"', repr(os.path.relpath(str(self.script_dir), str(self.purelib)))) def _args(self): diff --git a/src/virtualenv/create/via_global_ref/builtin/python2/python2.py b/src/virtualenv/create/via_global_ref/builtin/python2/python2.py index 9b963b3..3452577 100644 --- a/src/virtualenv/create/via_global_ref/builtin/python2/python2.py +++ b/src/virtualenv/create/via_global_ref/builtin/python2/python2.py @@ -31,7 +31,7 @@ class Python2(ViaGlobalRefVirtualenvBuiltin, Python2Supports, metaclass=abc.ABCM if IS_ZIPAPP: custom_site_text = read_from_zipapp(custom_site) else: - custom_site_text = custom_site.read_text() + custom_site_text = custom_site.read_text(encoding="utf-8") expected = json.dumps([os.path.relpath(str(i), str(site_py)) for i in self.libs]) custom_site_text = custom_site_text.replace("___EXPECTED_SITE_PACKAGES___", expected) @@ -42,7 +42,7 @@ class Python2(ViaGlobalRefVirtualenvBuiltin, Python2Supports, metaclass=abc.ABCM skip_rewrite = os.linesep.join(f" {i}" for i in self.skip_rewrite.splitlines()).lstrip() custom_site_text = custom_site_text.replace("# ___SKIP_REWRITE____", skip_rewrite) - site_py.write_text(custom_site_text) + site_py.write_text(custom_site_text, encoding="utf-8") @property def reload_code(self): diff --git a/src/virtualenv/discovery/cached_py_info.py b/src/virtualenv/discovery/cached_py_info.py index 22ad249..a1a5aec 100644 --- a/src/virtualenv/discovery/cached_py_info.py +++ b/src/virtualenv/discovery/cached_py_info.py @@ -114,6 +114,7 @@ def _run_subprocess(cls, exe, app_data, env): stderr=subprocess.PIPE, stdout=subprocess.PIPE, env=env, + encoding="utf-8", ) out, err = process.communicate() code = process.returncode diff --git a/src/virtualenv/seed/embed/via_app_data/pip_install/base.py b/src/virtualenv/seed/embed/via_app_data/pip_install/base.py index 3c44b77..4fa3304 100644 --- a/src/virtualenv/seed/embed/via_app_data/pip_install/base.py +++ b/src/virtualenv/seed/embed/via_app_data/pip_install/base.py @@ -72,11 +72,11 @@ class PipInstall(metaclass=ABCMeta): def _generate_new_files(self): new_files = set() installer = self._dist_info / "INSTALLER" - installer.write_text("pip\n") + installer.write_text("pip\n", encoding="utf-8") new_files.add(installer) # inject a no-op root element, as workaround for bug in https://github.com/pypa/pip/issues/7226 marker = self._image_dir / f"{self._dist_info.stem}.virtualenv" - marker.write_text("") + marker.write_text("", encoding="utf-8") new_files.add(marker) folder = mkdtemp() try: @@ -120,7 +120,7 @@ class PipInstall(metaclass=ABCMeta): entry_points = self._dist_info / "entry_points.txt" if entry_points.exists(): parser = ConfigParser() - with entry_points.open() as file_handler: + with entry_points.open(encoding="utf-8") as file_handler: parser.read_file(file_handler) if "console_scripts" in parser.sections(): for name, value in parser.items("console_scripts"): @@ -152,11 +152,17 @@ class PipInstall(metaclass=ABCMeta): logging.debug("uninstall existing distribution %s from %s", dist.stem, dist_base) top_txt = dist / "top_level.txt" # add top level packages at folder level - paths = {dist.parent / i.strip() for i in top_txt.read_text().splitlines()} if top_txt.exists() else set() + paths = ( + {dist.parent / i.strip() for i in top_txt.read_text(encoding="utf-8").splitlines()} + if top_txt.exists() + else set() + ) paths.add(dist) # add the dist-info folder itself base_dirs, record = paths.copy(), dist / "RECORD" # collect entries in record that we did not register yet - for name in (i.split(",")[0] for i in record.read_text().splitlines()) if record.exists() else (): + for name in ( + (i.split(",")[0] for i in record.read_text(encoding="utf-8").splitlines()) if record.exists() else () + ): path = dist_base / name if not any(p in base_dirs for p in path.parents): # only add if not already added as a base dir paths.add(path) diff --git a/src/virtualenv/seed/wheels/acquire.py b/src/virtualenv/seed/wheels/acquire.py index d1fb3f3..21fde34 100644 --- a/src/virtualenv/seed/wheels/acquire.py +++ b/src/virtualenv/seed/wheels/acquire.py @@ -60,7 +60,7 @@ def download_wheel(distribution, version_spec, for_py_version, search_dirs, app_ ] # pip has no interface in python - must be a new sub-process env = pip_wheel_env_run(search_dirs, app_data, env) - process = Popen(cmd, env=env, stdout=PIPE, stderr=PIPE, universal_newlines=True) + process = Popen(cmd, env=env, stdout=PIPE, stderr=PIPE, universal_newlines=True, encoding="utf-8") out, err = process.communicate() if process.returncode != 0: kwargs = {"output": out, "stderr": err} diff --git a/src/virtualenv/util/subprocess/__init__.py b/src/virtualenv/util/subprocess/__init__.py index bc6ec4d..efae569 100644 --- a/src/virtualenv/util/subprocess/__init__.py +++ b/src/virtualenv/util/subprocess/__init__.py @@ -11,6 +11,7 @@ def run_cmd(cmd): stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, + encoding="utf-8", ) out, err = process.communicate() # input disabled code = process.returncode |