Skip to content

Commit

Permalink
Sprinkle encoding parameters throughout. Fixes EncodingWarnings when …
Browse files Browse the repository at this point in the history
…PYTHONWARNDEFAULTENCODING is set.
  • Loading branch information
jaraco committed Apr 15, 2023
1 parent ef81847 commit 25b7dff
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v10.0.6
=======

Fixed ``EncodingWarnings``.

v10.0.5
=======

Expand Down
2 changes: 1 addition & 1 deletion pip_run/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ def intercept(args):
"""
Detect certain args and intercept them.
"""
usage = files(__package__).joinpath('usage.txt').read_text()
usage = files(__package__).joinpath('usage.txt').read_text(encoding='utf-8')
argparse.ArgumentParser(usage=usage).parse_known_args(args)
2 changes: 1 addition & 1 deletion pip_run/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def empty(path):
>>> target = getfixture('tmp_path')
>>> empty(target)
True
>>> _ = target.joinpath('file.txt').write_text('contents')
>>> _ = target.joinpath('file.txt').write_text('contents', encoding='utf-8')
>>> empty(target)
False
Expand Down
4 changes: 2 additions & 2 deletions pip_run/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def inject_sitecustomize(target: pathlib.Path):
>>> tmp_path = getfixture('tmp_path')
>>> inject_sitecustomize(tmp_path)
>>> sc = tmp_path / 'sitecustomize.py'
>>> 'Path' not in sc.read_text()
>>> 'Path' not in sc.read_text(encoding='utf-8')
True
"""
hook = textwrap.dedent(
Expand All @@ -24,7 +24,7 @@ def inject_sitecustomize(target: pathlib.Path):
site.addsitedir({os.fspath(target)!r})
"""
).lstrip()
target.joinpath('sitecustomize.py').write_text(hook)
target.joinpath('sitecustomize.py').write_text(hook, encoding='utf-8')


def _build_env(target):
Expand Down
2 changes: 1 addition & 1 deletion pip_run/mode/persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def cache_key(args):
for req in sorted(parsed.package):
hash.update(req + '\n')
for file in sorted(parsed.requirement):
hash.update('req:\n' + file.read_text())
hash.update('req:\n' + file.read_text(encoding='utf-8'))
return hash.hexdigest()


Expand Down
2 changes: 1 addition & 1 deletion pip_run/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _read(self, var_name):
class SourceDepsReader(DepsReader):
@classmethod
def load(cls, script: pathlib.Path):
return cls(script.read_text())
return cls(script.read_text(encoding='utf-8'))


def _load_json(path: pathlib.Path):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_pkg_imported(tmp_path):
pip_args = ['sampleproject']
cmd = [sys.executable, '-m', 'pip-run'] + pip_args + ['--', str(script)]

out = subprocess.check_output(cmd, text=True)
out = subprocess.check_output(cmd, text=True, encoding='utf-8')
assert 'Import succeeded' in out


Expand Down Expand Up @@ -175,7 +175,7 @@ def test_pkg_loaded_from_alternate_index(tmp_path):
)
cmd = [sys.executable, '-m', 'pip-run', '-v', '--', str(tmp_path / 'script')]

out = subprocess.check_output(cmd, text=True)
out = subprocess.check_output(cmd, text=True, encoding='utf-8')
assert 'Import succeeded' in out
assert 'devpi.net' in out

Expand Down Expand Up @@ -216,5 +216,5 @@ def test_pkg_loaded_from_url(tmp_path):

script = tmp_path.joinpath('script_dir', 'script')
cmd = [sys.executable, '-m', 'pip-run', '--no-index', '--', str(script)]
out = subprocess.check_output(cmd, text=True)
out = subprocess.check_output(cmd, text=True, encoding='utf-8')
assert 'Successfully imported barbazquux.py' in out

0 comments on commit 25b7dff

Please sign in to comment.