Unverified Commit a22683a8 authored by Sébastien Eustace's avatar Sébastien Eustace
Browse files

Fix new command creating invalid pyproject.toml files

parent 7ae77fd7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
- Fixed handling of markers with the `in` operator.
- Fixed `update` not properly adding new packages to the lock file.
- Fixed solver adding uninstall operations for non-installed packages.
- Fixed `new` command creating invalid `pyproject.toml` files.


## [0.6.5] - 2018-03-22
+2 −2
Original line number Diff line number Diff line
from pathlib import Path

from poetry.layouts import layout

from .command import Command


@@ -15,6 +13,8 @@ class NewCommand(Command):
    """

    def handle(self):
        from poetry.layouts import layout

        layout_ = layout('standard')

        path = Path.cwd() / Path(self.argument('path'))
+23 −27
Original line number Diff line number Diff line
import toml

from poetry.toml import dumps
from poetry.toml import loads
from poetry.utils.helpers import module_name
from poetry.vcs.git import Git

@@ -12,6 +12,21 @@ def test_version():
"""


POETRY_DEFAULT = """\
[tool.poetry]
name = ""
version = ""
description = ""
authors = []

[tool.poetry.dependencies]
python = "*"

[tool.poetry.dev-dependencies]
pytest = "^3.5"
"""


class Layout(object):

    def __init__(self, project, version='0.1.0', readme_format='md', author=None):
@@ -84,32 +99,13 @@ class Layout(object):
            )

    def _write_poetry(self, path):
        output = {
            'tool': {
                'poetry': {
                    'name': self._project,
                    'version': self._version,
                    'authors': [self._author],
                }
            }
        }

        content = toml.dumps(output, preserve=True)

        output = {
            'tool': {
                'poetry': {
                    'dependencies': {},
                    'dev-dependencies': {
                        'pytest': '^3.4'
                    }
                }
            }
        }

        content += '\n' + toml.dumps(output, preserve=True)
        content = loads(POETRY_DEFAULT)
        poetry_content = content['tool']['poetry']
        poetry_content['name'] = self._project
        poetry_content['version'] = self._version
        poetry_content['authors'].append(self._author)

        poetry = path / 'pyproject.toml'

        with poetry.open('w') as f:
            f.write(content)
            f.write(dumps(content))