Skip to content

Commit

Permalink
layouts: add readme to pyproject.toml on creation
Browse files Browse the repository at this point in the history
Relates-to: #280

Co-authored-by: Arun Babu Neelicattu <[email protected]>
  • Loading branch information
finswimmer and abn committed Sep 22, 2020
1 parent f27e192 commit 87fc8d5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
23 changes: 16 additions & 7 deletions poetry/layouts/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
description = ""
authors = []
license = ""
readme = ""
packages = []
[tool.poetry.dependencies]
Expand All @@ -34,6 +35,8 @@


class Layout(object):
ACCEPTED_README_FORMATS = {"md", "rst"}

def __init__(
self,
project,
Expand All @@ -53,7 +56,15 @@ def __init__(
self._package_name = ".".join(self._package_path_relative.parts)
self._version = version
self._description = description
self._readme_format = readme_format

self._readme_format = readme_format.lower()
if self._readme_format not in self.ACCEPTED_README_FORMATS:
raise ValueError(
"Invalid readme format '{}', use one of {}.".format(
readme_format, ", ".join(self.ACCEPTED_README_FORMATS)
)
)

self._license = license
self._python = python
self._dependencies = dependencies or {}
Expand Down Expand Up @@ -115,6 +126,7 @@ def generate_poetry_content(self):
else:
poetry_content.remove("license")

poetry_content["readme"] = "README.{}".format(self._readme_format)
packages = self.get_package_include()
if packages:
poetry_content["packages"].append(packages)
Expand Down Expand Up @@ -154,13 +166,10 @@ def _create_default(self, path):
package_init = package_path / "__init__.py"
package_init.touch()

def _create_readme(self, path):
if self._readme_format == "rst":
readme_file = path / "README.rst"
else:
readme_file = path / "README.md"

def _create_readme(self, path): # type: (Path) -> Path
readme_file = path.joinpath("README.{}".format(self._readme_format))
readme_file.touch()
return readme_file

@staticmethod
def _create_tests(path):
Expand Down
10 changes: 10 additions & 0 deletions tests/console/commands/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_basic_interactive(app, mocker, poetry):
description = "This is a description"
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]
[tool.poetry.dependencies]
Expand Down Expand Up @@ -87,6 +88,7 @@ def test_interactive_with_dependencies(app, repo, mocker, poetry):
description = "This is a description"
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]
[tool.poetry.dependencies]
Expand Down Expand Up @@ -128,6 +130,7 @@ def test_empty_license(app, mocker, poetry):
version = "1.2.3"
description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"
packages = [{{include = "my_package"}}]
[tool.poetry.dependencies]
Expand Down Expand Up @@ -180,6 +183,7 @@ def test_interactive_with_git_dependencies(
description = "This is a description"
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]
[tool.poetry.dependencies]
Expand Down Expand Up @@ -233,6 +237,7 @@ def test_interactive_with_git_dependencies_with_reference(
description = "This is a description"
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]
[tool.poetry.dependencies]
Expand Down Expand Up @@ -286,6 +291,7 @@ def test_interactive_with_git_dependencies_and_other_name(
description = "This is a description"
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]
[tool.poetry.dependencies]
Expand Down Expand Up @@ -339,6 +345,7 @@ def test_interactive_with_directory_dependency(
description = "This is a description"
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]
[tool.poetry.dependencies]
Expand Down Expand Up @@ -392,6 +399,7 @@ def test_interactive_with_directory_dependency_and_other_name(
description = "This is a description"
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]
[tool.poetry.dependencies]
Expand Down Expand Up @@ -443,6 +451,7 @@ def test_interactive_with_file_dependency(app, repo, mocker, poetry):
description = "This is a description"
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]
[tool.poetry.dependencies]
Expand Down Expand Up @@ -484,6 +493,7 @@ def test_python_option(app, mocker, poetry):
description = "This is a description"
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]
[tool.poetry.dependencies]
Expand Down

0 comments on commit 87fc8d5

Please sign in to comment.