Skip to content

Commit affabe0

Browse files
finswimmerabn
andcommitted
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 <[email protected]>
1 parent e9738b1 commit affabe0

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

docs/docs/cli.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ will create a folder as follows:
3131
```text
3232
my-package
3333
├── pyproject.toml
34-
├── README.rst
34+
├── README.md
3535
├── my_package
3636
│ └── __init__.py
3737
└── tests
@@ -56,7 +56,7 @@ That will create a folder structure as follows:
5656
```text
5757
my-package
5858
├── pyproject.toml
59-
├── README.rst
59+
├── README.md
6060
├── src
6161
│ └── my_package
6262
│ └── __init__.py
@@ -76,6 +76,7 @@ will create the following structure:
7676
```text
7777
my-package
7878
├── pyproject.toml
79+
├── README.md
7980
├── src
8081
│ └── my
8182
│ └── package

poetry/console/commands/new.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ class NewCommand(Command):
1515
options = [
1616
option("name", None, "Set the resulting package name.", flag=False),
1717
option("src", None, "Use the src layout for the project."),
18+
option(
19+
"readme",
20+
None,
21+
"Specify the readme file format. One of md (default) or rst",
22+
flag=False,
23+
),
1824
]
1925

2026
def handle(self) -> None:
@@ -46,7 +52,7 @@ def handle(self) -> None:
4652
"exists and is not empty".format(path)
4753
)
4854

49-
readme_format = "rst"
55+
readme_format = self.option("readme") or "md"
5056

5157
config = GitConfig()
5258
author = None

tests/console/commands/test_new.py

+24-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
import pytest
1+
from pathlib import Path
2+
from typing import Optional
23

3-
from cleo.testers import CommandTester
4+
import pytest
45

5-
from poetry.console import Application
66
from poetry.factory import Factory
77
from poetry.poetry import Poetry
8-
from poetry.utils._compat import Path # noqa
98

109

1110
@pytest.fixture
12-
def command(app, poetry): # type: (Application, Poetry) -> CommandTester
13-
command = app.find("new")
14-
command._pool = poetry.pool
15-
return CommandTester(command)
11+
def tester(command_tester_factory):
12+
return command_tester_factory("new")
1613

1714

18-
def verify_project_directory(path, package_name, package_path, include_from=None):
15+
def verify_project_directory(
16+
path: Path, package_name: str, package_path: str, include_from: Optional[str] = None
17+
) -> Poetry:
1918
package_path = Path(package_path)
2019
assert path.is_dir()
2120

@@ -47,6 +46,8 @@ def verify_project_directory(path, package_name, package_path, include_from=None
4746
assert len(packages) == 1
4847
assert packages[0] == package_include
4948

49+
return poetry
50+
5051

5152
@pytest.mark.parametrize(
5253
"options,directory,package_name,package_path,include_from",
@@ -134,9 +135,21 @@ def verify_project_directory(path, package_name, package_path, include_from=None
134135
],
135136
)
136137
def test_command_new(
137-
options, directory, package_name, package_path, include_from, command, tmp_dir
138+
options, directory, package_name, package_path, include_from, tester, tmp_dir
138139
):
139140
path = Path(tmp_dir) / directory
140141
options.append(path.as_posix())
141-
command.execute(" ".join(options))
142+
tester.execute(" ".join(options))
142143
verify_project_directory(path, package_name, package_path, include_from)
144+
145+
146+
@pytest.mark.parametrize("fmt", [(None,), ("md",), ("rst",)])
147+
def test_command_new_with_readme(fmt, tester, tmp_dir):
148+
fmt = "md"
149+
package = "package"
150+
path = Path(tmp_dir) / package
151+
options = ["--readme {}".format(fmt) if fmt else "md", path.as_posix()]
152+
tester.execute(" ".join(options))
153+
154+
poetry = verify_project_directory(path, package, package, None)
155+
assert poetry.local_config.get("readme") == "README.{}".format(fmt or "md")

0 commit comments

Comments
 (0)