Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encodings for various generated files #368

Closed
5 changes: 3 additions & 2 deletions get-poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
directory, it will look for them in the base system.
"""
import argparse
import io
import json
import os
import platform
Expand Down Expand Up @@ -152,7 +153,7 @@ def run(self):
print(colorize("info", "Retrieving metadata"))

r = urlopen(self.METADATA_URL)
metadata = json.loads(r.read().decode())
metadata = json.loads(r.read().decode("utf-8"))
r.close()

def _compare_versions(x, y):
Expand Down Expand Up @@ -281,7 +282,7 @@ def install(self, version):
wheel_data = os.path.join(
dist, "poetry-{}.dist-info".format(version), "WHEEL"
)
with open(wheel_data) as f:
with io.open(wheel_data, encoding="utf-8") as f:
wheel_data = Parser().parsestr(f.read())

tag = wheel_data["Tag"]
Expand Down
2 changes: 1 addition & 1 deletion poetry/console/commands/develop.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def handle(self):
else:
builder = SdistBuilder(self.poetry, NullVenv(), NullIO())

with setup.open("w") as f:
with setup.open("w", encoding="utf-8") as f:
f.write(decode(builder.build_setup()))

try:
Expand Down
2 changes: 1 addition & 1 deletion poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def handle(self):

return 1

with (Path.cwd() / "pyproject.toml").open("w") as f:
with (Path.cwd() / "pyproject.toml").open("w", encoding="utf-8") as f:
f.write(content)

def _determine_requirements(
Expand Down
2 changes: 1 addition & 1 deletion poetry/console/commands/self/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def update(self, release):
os.unlink(str(file))

wheel_data = dist / "poetry-{}.dist-info".format(version) / "WHEEL"
with wheel_data.open() as f:
with wheel_data.open(encoding="utf-8") as f:
wheel_data = Parser().parsestr(f.read())

tag = wheel_data["Tag"]
Expand Down
3 changes: 2 additions & 1 deletion poetry/json/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
import json
import os

Expand All @@ -17,7 +18,7 @@ def validate_object(obj, schema_name): # type: (dict, str) -> None
if not os.path.exists(schema):
raise ValueError("Schema {} does not exist.".format(schema_name))

with open(schema) as f:
with io.open(schema, encoding="utf-8") as f:
schema = json.loads(f.read())

try:
Expand Down
4 changes: 2 additions & 2 deletions poetry/layouts/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _create_tests(self, path):
tests.mkdir()
tests_init.touch(exist_ok=False)

with tests_default.open("w") as f:
with tests_default.open("w", encoding="utf-8") as f:
f.write(
TESTS_DEFAULT.format(
package_name=self._package_name, version=self._version
Expand All @@ -137,5 +137,5 @@ def _write_poetry(self, path):

poetry = path / "pyproject.toml"

with poetry.open("w") as f:
with poetry.open("w", encoding="utf-8") as f:
f.write(content)
2 changes: 1 addition & 1 deletion poetry/layouts/src.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ def _create_default(self, path):

package_path.mkdir(parents=True)

with package_init.open("w") as f:
with package_init.open("w", encoding="utf-8") as f:
f.write(DEFAULT.format(version=self._version))
2 changes: 1 addition & 1 deletion poetry/layouts/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ def _create_default(self, path):

package_path.mkdir()

with package_init.open("w") as f:
with package_init.open("w", encoding="utf-8") as f:
f.write(DEFAULT.format(version=self._version))
3 changes: 2 additions & 1 deletion poetry/masonry/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import contextlib
import hashlib
import io
import os
import re
import tempfile
Expand Down Expand Up @@ -233,7 +234,7 @@ def _add_file(self, wheel, full_path, rel_path):
zinfo.external_attr |= 0x10 # MS-DOS directory flag

hashsum = hashlib.sha256()
with open(full_path, "rb") as src:
with io.open(full_path, "rb") as src:
while True:
buf = src.read(1024 * 8)
if not buf:
Expand Down
2 changes: 1 addition & 1 deletion poetry/masonry/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def from_package(cls, package): # type: (...) -> Metadata
meta.version = normalize_version(package.version.text)
meta.summary = package.description
if package.readme:
with package.readme.open() as f:
with package.readme.open(encoding="utf-8") as f:
meta.description = f.read()

meta.keywords = ",".join(package.keywords)
Expand Down
4 changes: 2 additions & 2 deletions poetry/packages/directory_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(
poetry = Poetry.create(self._full_path)
builder = SdistBuilder(poetry, NullVenv(), NullIO())

with setup.open("w") as f:
with setup.open("w", encoding="utf-8") as f:
f.write(decode(builder.build_setup()))

package = poetry.package
Expand Down Expand Up @@ -102,7 +102,7 @@ def __init__(
reqs = []
requires = egg_info / "requires.txt"
if requires.exists():
with requires.open() as f:
with requires.open(encoding="utf-8") as f:
reqs = parse_requires(f.read())

package = Package(meta.name, meta.version)
Expand Down
2 changes: 1 addition & 1 deletion poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def search_for_vcs(self, dependency): # type: (VCSDependency) -> List[Package]
reqs = []
requires = egg_info / "requires.txt"
if requires.exists():
with requires.open() as f:
with requires.open(encoding="utf-8") as f:
reqs = parse_requires(f.read())

package = Package(meta.name, meta.version)
Expand Down
3 changes: 2 additions & 1 deletion poetry/repositories/legacy_repository.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cgi
import io
import re

try:
Expand Down Expand Up @@ -341,7 +342,7 @@ def _get_release_info(self, name, version): # type: (str, str) -> dict

def _download(self, url, dest): # type: (str, str) -> None
r = self._session.get(url, stream=True)
with open(dest, "wb") as f:
with io.open(dest, "wb") as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
Expand Down
9 changes: 5 additions & 4 deletions poetry/repositories/pypi_repository.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import io
import os
import re
import tarfile
Expand Down Expand Up @@ -451,7 +452,7 @@ def _get_info_from_sdist(

requires = egg_info / "requires.txt"
if requires.exists():
with requires.open() as f:
with requires.open(encoding="utf-8") as f:
info["requires_dist"] = parse_requires(f.read())

return info
Expand All @@ -463,7 +464,7 @@ def _get_info_from_sdist(

requires = egg_info / "requires.txt"
if requires.exists():
with requires.open() as f:
with requires.open(encoding="utf-8") as f:
info["requires_dist"] = parse_requires(f.read())

return info
Expand Down Expand Up @@ -501,7 +502,7 @@ def _inspect_sdist_with_setup(self, sdist_dir):
else:
requires = egg_info / "requires.txt"
if requires.exists():
with requires.open() as f:
with requires.open(encoding="utf-8") as f:
info["requires_dist"] = parse_requires(f.read())
except Exception:
pass
Expand All @@ -512,7 +513,7 @@ def _inspect_sdist_with_setup(self, sdist_dir):

def _download(self, url, dest): # type: (str, str) -> None
r = get(url, stream=True)
with open(dest, "wb") as f:
with io.open(dest, "wb") as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
Expand Down
3 changes: 2 additions & 1 deletion poetry/spdx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
import json
import os

Expand Down Expand Up @@ -26,7 +27,7 @@ def load_licenses():

licenses_file = os.path.join(os.path.dirname(__file__), "data", "licenses.json")

with open(licenses_file) as f:
with io.open(licenses_file, encoding="utf-8") as f:
data = json.loads(f.read())

for name, license in data.items():
Expand Down
5 changes: 3 additions & 2 deletions poetry/spdx/updater.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
import json
import os

Expand All @@ -20,15 +21,15 @@ def dump(self, file=None):

licenses_url = self._base_url + "licenses.json"

with open(file, "w") as f:
with io.open(file, "w", encoding="utf-8") as f:
f.write(
json.dumps(self.get_licenses(licenses_url), indent=2, sort_keys=True)
)

def get_licenses(self, url):
licenses = {}
with urlopen(url) as r:
data = json.loads(r.read().decode())
data = json.loads(r.read().decode("utf-8"))

for info in data["licenses"]:
licenses[info["licenseId"]] = [
Expand Down
4 changes: 2 additions & 2 deletions tests/console/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ def repo():
def poetry(repo):
p = Poetry.create(Path(__file__).parent.parent / "fixtures" / "simple_project")

with p.file.path.open() as f:
with p.file.path.open(encoding="utf-8") as f:
content = f.read()

p.pool.remove_repository("pypi")
p.pool.add_repository(repo)

yield p

with p.file.path.open("w") as f:
with p.file.path.open("w", encoding="utf-8") as f:
f.write(content)


Expand Down
2 changes: 1 addition & 1 deletion tests/repositories/test_legacy_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _get(self, endpoint):

fixture = self.FIXTURES / (name + ".html")

with fixture.open() as f:
with fixture.open(encoding="utf-8") as f:
return Page(self._url + endpoint, f.read(), {})


Expand Down
2 changes: 1 addition & 1 deletion tests/repositories/test_pypi_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _get(self, url):
if not fixture.exists():
fixture = self.JSON_FIXTURES / (name + ".json")

with fixture.open() as f:
with fixture.open(encoding="utf-8") as f:
return json.loads(f.read())

def _download(self, url, dest):
Expand Down