Commit a22683a8 by Sébastien Eustace

Fix new command creating invalid pyproject.toml files

parent 7ae77fd7
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
- Fixed handling of markers with the `in` operator. - Fixed handling of markers with the `in` operator.
- Fixed `update` not properly adding new packages to the lock file. - Fixed `update` not properly adding new packages to the lock file.
- Fixed solver adding uninstall operations for non-installed packages. - Fixed solver adding uninstall operations for non-installed packages.
- Fixed `new` command creating invalid `pyproject.toml` files.
## [0.6.5] - 2018-03-22 ## [0.6.5] - 2018-03-22
......
from pathlib import Path from pathlib import Path
from poetry.layouts import layout
from .command import Command from .command import Command
...@@ -15,6 +13,8 @@ class NewCommand(Command): ...@@ -15,6 +13,8 @@ class NewCommand(Command):
""" """
def handle(self): def handle(self):
from poetry.layouts import layout
layout_ = layout('standard') layout_ = layout('standard')
path = Path.cwd() / Path(self.argument('path')) path = Path.cwd() / Path(self.argument('path'))
......
import toml from poetry.toml import dumps
from poetry.toml import loads
from poetry.utils.helpers import module_name from poetry.utils.helpers import module_name
from poetry.vcs.git import Git from poetry.vcs.git import Git
...@@ -12,6 +12,21 @@ def test_version(): ...@@ -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): class Layout(object):
def __init__(self, project, version='0.1.0', readme_format='md', author=None): def __init__(self, project, version='0.1.0', readme_format='md', author=None):
...@@ -84,32 +99,13 @@ class Layout(object): ...@@ -84,32 +99,13 @@ class Layout(object):
) )
def _write_poetry(self, path): def _write_poetry(self, path):
output = { content = loads(POETRY_DEFAULT)
'tool': { poetry_content = content['tool']['poetry']
'poetry': { poetry_content['name'] = self._project
'name': self._project, poetry_content['version'] = self._version
'version': self._version, poetry_content['authors'].append(self._author)
'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)
poetry = path / 'pyproject.toml' poetry = path / 'pyproject.toml'
with poetry.open('w') as f: with poetry.open('w') as f:
f.write(content) f.write(dumps(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