Commit a50b9a7e by Sébastien Eustace

Fix keys and array order in lock file

parent c0283e96
......@@ -30,6 +30,7 @@
- Fixed `remove` command's case sensitivity. (Thanks to [@cauebs](https://github.com/cauebs))
- Fixed detection of `.egg-info` directory for non-poetry projects. (Thanks to [@gtors](https://github.com/gtors))
- Fixed only-wheel builds. (Thanks to [@gtors](https://github.com/gtors))
- Fixed key and array order in lock file to avoid having differences when relocking.
## [0.10.3] - 2018-06-04
......
import toml
from poetry.locations import CONFIG_DIR
from poetry.utils._compat import Path
from poetry.utils.toml_file import TomlFile
from .uploader import Uploader
......@@ -44,7 +43,7 @@ class Publisher:
repository_name = "pypi"
else:
# Retrieving config information
config_file = Path(CONFIG_DIR) / "config.toml"
config_file = TomlFile(Path(CONFIG_DIR) / "config.toml")
if not config_file.exists():
raise RuntimeError(
......@@ -52,8 +51,7 @@ class Publisher:
"Unable to get repository information"
)
with config_file.open() as f:
config = toml.loads(f.read())
config = config_file.read(raw=True)
if (
"repositories" not in config
......@@ -66,10 +64,9 @@ class Publisher:
url = config["repositories"][repository_name]["url"]
if not (username and password):
auth_file = Path(CONFIG_DIR) / "auth.toml"
auth_file = TomlFile(Path(CONFIG_DIR) / "auth.toml")
if auth_file.exists():
with auth_file.open() as f:
auth_config = toml.loads(f.read())
auth_config = auth_file.read(raw=True)
if (
"http-basic" in auth_config
......
......@@ -140,7 +140,18 @@ class Locker:
return False
def _write_lock_data(self, data):
self._lock.write(data)
# We want a clean lock file so we write
# packages first and metadata after
with self._lock.open("w", encoding="utf-8") as f:
f.write(self._lock.dumps({"package": data["package"]}, sort=True))
f.write("\n")
if "extras" in data:
f.write(self._lock.dumps({"extras": data["extras"]}, sort=True))
f.write("\n")
f.write(self._lock.dumps({"metadata": data["metadata"]}, sort=True))
f.write("\n")
self._lock_data = None
def _get_content_hash(self): # type: () -> str
......@@ -211,10 +222,12 @@ class Locker:
"optional": package.optional,
"python-versions": package.python_versions,
"platform": package.platform,
"hashes": package.hashes,
"dependencies": dependencies,
"hashes": sorted(package.hashes),
}
if dependencies:
data["dependencies"] = dependencies
if package.source_type:
data["source"] = {
"type": package.source_type,
......
# -*- coding: utf-8 -*-
import toml
import pytoml as toml
from poetry.toml import dumps
from poetry.toml import loads
......@@ -23,12 +23,17 @@ class TomlFile:
return loads(f.read())
def write(self, data): # type: (...) -> None
def dumps(self, data, sort=False): # type: (...) -> str
if not isinstance(data, TOMLFile):
data = toml.dumps(data)
data = toml.dumps(data, sort_keys=sort)
else:
data = dumps(data)
return data
def write(self, data, sort=False): # type: (...) -> None
data = self.dumps(data, sort=sort)
with self._path.open("w", encoding="utf-8") as f:
f.write(data)
......
......@@ -24,8 +24,8 @@ classifiers = [
[tool.poetry.dependencies]
python = "~2.7 || ^3.4"
cleo = "^0.6.7"
pytoml = "^0.1.16"
requests = "^2.18"
toml = "^0.9"
cachy = "^0.2"
requests-toolbelt = "^0.8.0"
jsonschema = "^2.6"
......
......@@ -3,7 +3,6 @@ from __future__ import unicode_literals
import sys
import pytest
import toml
from poetry.installation import Installer as BaseInstaller
from poetry.installation.noop_installer import NoopInstaller
......@@ -15,6 +14,7 @@ from poetry.repositories import Repository
from poetry.repositories.installed_repository import InstalledRepository
from poetry.utils._compat import Path
from poetry.utils._compat import PY2
from poetry.utils.toml_file import TomlFile
from poetry.utils.venv import NullVenv
from tests.helpers import get_dependency
......@@ -76,8 +76,6 @@ class Locker(BaseLocker):
package["python-versions"] = python_versions
package["platform"] = platform
if not package["dependencies"]:
del package["dependencies"]
self._written_data = data
......@@ -133,10 +131,9 @@ def installer(package, pool, locker, venv, installed):
def fixture(name):
file = Path(__file__).parent / "fixtures" / "{}.test".format(name)
file = TomlFile(Path(__file__).parent / "fixtures" / "{}.test".format(name))
with file.open() as f:
return toml.loads(f.read())
return file.read(raw=True)
def test_run_no_dependencies(installer, locker):
......
......@@ -2,10 +2,9 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import toml
from poetry.poetry import Poetry
from poetry.utils._compat import Path
from poetry.utils.toml_file import TomlFile
fixtures_dir = Path(__file__).parent / "fixtures"
......@@ -122,8 +121,7 @@ def test_poetry_with_packages_and_includes():
def test_check():
complete = fixtures_dir / "complete.toml"
with complete.open() as f:
content = toml.loads(f.read())["tool"]["poetry"]
complete = TomlFile(fixtures_dir / "complete.toml")
content = complete.read(raw=True)["tool"]["poetry"]
assert Poetry.check(content)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment