Merge pull request #3362 from pypa/preserve-inline-spaces

Preserve inline spaces in toml
This commit is contained in:
Frost Ming
2018-12-07 09:47:48 +08:00
committed by GitHub
4 changed files with 48 additions and 29 deletions
+1
View File
@@ -0,0 +1 @@
The inline tables won't be rewritten now.
+24 -11
View File
@@ -83,19 +83,32 @@ def cleanup_toml(tml):
def convert_toml_outline_tables(parsed):
"""Converts all outline tables to inline tables."""
if isinstance(parsed, tomlkit.container.Container):
empty_inline_table = tomlkit.inline_table
else:
empty_inline_table = toml.TomlDecoder().get_empty_inline_table
def convert_tomlkit_table(section):
for key, value in section._body:
if not key:
continue
if hasattr(value, "keys") and not isinstance(value, tomlkit.items.InlineTable):
table = tomlkit.inline_table()
table.update(value.value)
section[key.key] = table
def convert_toml_table(section):
for package, value in section.items():
if hasattr(value, "keys") and not isinstance(value, toml.decoder.InlineTableDict):
table = toml.TomlDecoder().get_empty_inline_table()
table.update(value)
section[package] = table
is_tomlkit_parsed = isinstance(parsed, tomlkit.container.Container)
for section in ("packages", "dev-packages"):
table_data = parsed.get(section, {})
for package, value in table_data.items():
if hasattr(value, "keys") and not isinstance(
value, (tomlkit.items.InlineTable, toml.decoder.InlineTableDict)
):
table = empty_inline_table()
table.update(value)
table_data[package] = table
if not table_data:
continue
if is_tomlkit_parsed:
convert_tomlkit_table(table_data)
else:
convert_toml_table(table_data)
return parsed
+22
View File
@@ -446,3 +446,25 @@ def test_install_package_with_dots(PipenvInstance, pypi):
c = p.pipenv("install backports.html")
assert c.ok
assert "backports.html" in p.pipfile["packages"]
@pytest.mark.install
def test_rewrite_outline_table(PipenvInstance, pypi):
with PipenvInstance(pypi=pypi, chdir=True) as p:
with open(p.pipfile_path, 'w') as f:
contents = """
[packages]
six = {version = "*", editable = true}
[packages.requests]
version = "*"
""".strip()
f.write(contents)
c = p.pipenv("install -e click")
assert c.return_code == 0
with open(p.pipfile_path) as f:
contents = f.read()
assert "[packages.requests]" not in contents
assert 'six = {version = "*", editable = true}' in contents
assert 'requests = {version = "*"}' in contents
assert 'click = {' in contents
+1 -18
View File
@@ -148,24 +148,6 @@ six = {{version = "*", index = "pypi"}}
assert c.return_code == 0
@pytest.mark.install
@pytest.mark.project
def test_rewrite_outline_table(PipenvInstance, pypi):
with PipenvInstance(pypi=pypi, chdir=True) as p:
with open(p.pipfile_path, 'w') as f:
contents = """
[packages.requests]
version = "*"
""".strip()
f.write(contents)
c = p.pipenv('install click')
assert c.return_code == 0
with open(p.pipfile_path) as f:
contents = f.read()
assert "[packages.requests]" not in contents
assert 'requests = {version = "*"}' in contents
@pytest.mark.install
@pytest.mark.project
def test_include_editable_packages(PipenvInstance, pypi, testsroot, pathlib_tmpdir):
@@ -185,6 +167,7 @@ def test_include_editable_packages(PipenvInstance, pypi, testsroot, pathlib_tmpd
@pytest.mark.project
@pytest.mark.virtualenv
def test_run_in_virtualenv(PipenvInstance, pypi, virtualenv):
with PipenvInstance(chdir=True, pypi=pypi) as p:
os.environ.pop("PIPENV_IGNORE_VIRTUALENVS", None)