Commit affabe04 by finswimmer Committed by Arun Babu Neelicattu

command/new: make readme format configurable

This change makes readme formant configurable, defaulting to markdown
when using the new command.

Resolves: #280
Closes: #1515

Co-authored-by: Arun Babu Neelicattu <arun.neelicattu@gmail.com>
parent e9738b1c
...@@ -31,7 +31,7 @@ will create a folder as follows: ...@@ -31,7 +31,7 @@ will create a folder as follows:
```text ```text
my-package my-package
├── pyproject.toml ├── pyproject.toml
├── README.rst ├── README.md
├── my_package ├── my_package
│ └── __init__.py │ └── __init__.py
└── tests └── tests
...@@ -56,7 +56,7 @@ That will create a folder structure as follows: ...@@ -56,7 +56,7 @@ That will create a folder structure as follows:
```text ```text
my-package my-package
├── pyproject.toml ├── pyproject.toml
├── README.rst ├── README.md
├── src ├── src
│ └── my_package │ └── my_package
│ └── __init__.py │ └── __init__.py
...@@ -76,6 +76,7 @@ will create the following structure: ...@@ -76,6 +76,7 @@ will create the following structure:
```text ```text
my-package my-package
├── pyproject.toml ├── pyproject.toml
├── README.md
├── src ├── src
│ └── my │ └── my
│ └── package │ └── package
......
...@@ -15,6 +15,12 @@ class NewCommand(Command): ...@@ -15,6 +15,12 @@ class NewCommand(Command):
options = [ options = [
option("name", None, "Set the resulting package name.", flag=False), option("name", None, "Set the resulting package name.", flag=False),
option("src", None, "Use the src layout for the project."), option("src", None, "Use the src layout for the project."),
option(
"readme",
None,
"Specify the readme file format. One of md (default) or rst",
flag=False,
),
] ]
def handle(self) -> None: def handle(self) -> None:
...@@ -46,7 +52,7 @@ class NewCommand(Command): ...@@ -46,7 +52,7 @@ class NewCommand(Command):
"exists and is not empty".format(path) "exists and is not empty".format(path)
) )
readme_format = "rst" readme_format = self.option("readme") or "md"
config = GitConfig() config = GitConfig()
author = None author = None
......
import pytest from pathlib import Path
from typing import Optional
from cleo.testers import CommandTester import pytest
from poetry.console import Application
from poetry.factory import Factory from poetry.factory import Factory
from poetry.poetry import Poetry from poetry.poetry import Poetry
from poetry.utils._compat import Path # noqa
@pytest.fixture @pytest.fixture
def command(app, poetry): # type: (Application, Poetry) -> CommandTester def tester(command_tester_factory):
command = app.find("new") return command_tester_factory("new")
command._pool = poetry.pool
return CommandTester(command)
def verify_project_directory(path, package_name, package_path, include_from=None): def verify_project_directory(
path: Path, package_name: str, package_path: str, include_from: Optional[str] = None
) -> Poetry:
package_path = Path(package_path) package_path = Path(package_path)
assert path.is_dir() assert path.is_dir()
...@@ -47,6 +46,8 @@ def verify_project_directory(path, package_name, package_path, include_from=None ...@@ -47,6 +46,8 @@ def verify_project_directory(path, package_name, package_path, include_from=None
assert len(packages) == 1 assert len(packages) == 1
assert packages[0] == package_include assert packages[0] == package_include
return poetry
@pytest.mark.parametrize( @pytest.mark.parametrize(
"options,directory,package_name,package_path,include_from", "options,directory,package_name,package_path,include_from",
...@@ -134,9 +135,21 @@ def verify_project_directory(path, package_name, package_path, include_from=None ...@@ -134,9 +135,21 @@ def verify_project_directory(path, package_name, package_path, include_from=None
], ],
) )
def test_command_new( def test_command_new(
options, directory, package_name, package_path, include_from, command, tmp_dir options, directory, package_name, package_path, include_from, tester, tmp_dir
): ):
path = Path(tmp_dir) / directory path = Path(tmp_dir) / directory
options.append(path.as_posix()) options.append(path.as_posix())
command.execute(" ".join(options)) tester.execute(" ".join(options))
verify_project_directory(path, package_name, package_path, include_from) verify_project_directory(path, package_name, package_path, include_from)
@pytest.mark.parametrize("fmt", [(None,), ("md",), ("rst",)])
def test_command_new_with_readme(fmt, tester, tmp_dir):
fmt = "md"
package = "package"
path = Path(tmp_dir) / package
options = ["--readme {}".format(fmt) if fmt else "md", path.as_posix()]
tester.execute(" ".join(options))
poetry = verify_project_directory(path, package, package, None)
assert poetry.local_config.get("readme") == "README.{}".format(fmt or "md")
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