Skip to content

Commit

Permalink
Simplify conditional encoding in install_scripts and easy_install
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Apr 21, 2024
1 parent 645c25b commit 61d220b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
8 changes: 2 additions & 6 deletions setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,12 +874,8 @@ def write_script(self, script_name, contents, mode="t", blockers=()):
if os.path.exists(target):
os.unlink(target)

if "b" not in mode and isinstance(contents, str):
kw = {"encoding": "utf-8"}
else:
kw = {}

with open(target, "w" + mode, **kw) as f:
encoding = None if "b" in mode else "utf-8"
with open(target, "w" + mode, encoding=encoding) as f:
f.write(contents)
chmod(target, 0o777 - mask)

Expand Down
8 changes: 2 additions & 6 deletions setuptools/command/install_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@ def write_script(self, script_name, contents, mode="t", *ignored):
target = os.path.join(self.install_dir, script_name)
self.outfiles.append(target)

if "b" not in mode and isinstance(contents, str):
kw = {"encoding": "utf-8"}
else:
kw = {}

encoding = None if "b" in mode else "utf-8"
mask = current_umask()
if not self.dry_run:
ensure_directory(target)
with open(target, "w" + mode, **kw) as f:
with open(target, "w" + mode, encoding=encoding) as f:
f.write(contents)
chmod(target, 0o777 - mask)

0 comments on commit 61d220b

Please sign in to comment.