From 971a739749c2cd7bd89300d09d617aba89920133 Mon Sep 17 00:00:00 2001 From: finswimmer Date: Fri, 7 Aug 2020 00:00:41 +0200 Subject: [PATCH] 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 --- docs/docs/cli.md | 5 +++-- poetry/console/commands/new.py | 8 +++++++- tests/console/commands/test_new.py | 20 +++++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/docs/docs/cli.md b/docs/docs/cli.md index 1916e358eac..08be27eb2b6 100644 --- a/docs/docs/cli.md +++ b/docs/docs/cli.md @@ -30,7 +30,7 @@ will create a folder as follows: ```text my-package ├── pyproject.toml -├── README.rst +├── README.md ├── my_package │ └── __init__.py └── tests @@ -55,7 +55,7 @@ That will create a folder structure as follows: ```text my-package ├── pyproject.toml -├── README.rst +├── README.md ├── src │ └── my_package │ └── __init__.py @@ -75,6 +75,7 @@ will create the following structure: ```text my-package ├── pyproject.toml +├── README.md ├── src │ └── my │ └── package diff --git a/poetry/console/commands/new.py b/poetry/console/commands/new.py index db82c9d03dd..3f719f08e60 100644 --- a/poetry/console/commands/new.py +++ b/poetry/console/commands/new.py @@ -15,6 +15,12 @@ class NewCommand(Command): options = [ option("name", None, "Set the resulting package name.", flag=False), 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): @@ -45,7 +51,7 @@ def handle(self): "exists and is not empty".format(path) ) - readme_format = "rst" + readme_format = self.option("readme") or "md" config = GitConfig() author = None diff --git a/tests/console/commands/test_new.py b/tests/console/commands/test_new.py index 1ac42facd04..c22af656699 100644 --- a/tests/console/commands/test_new.py +++ b/tests/console/commands/test_new.py @@ -1,3 +1,5 @@ +from typing import Optional + import pytest from cleo.testers import CommandTester @@ -15,7 +17,9 @@ def command(app, poetry): # type: (Application, Poetry) -> CommandTester return CommandTester(command) -def verify_project_directory(path, package_name, package_path, include_from=None): +def verify_project_directory( + path, package_name, package_path, include_from=None +): # type: (Path, str, str, Optional[str]) -> Poetry package_path = Path(package_path) assert path.is_dir() @@ -47,6 +51,8 @@ def verify_project_directory(path, package_name, package_path, include_from=None assert len(packages) == 1 assert packages[0] == package_include + return poetry + @pytest.mark.parametrize( "options,directory,package_name,package_path,include_from", @@ -140,3 +146,15 @@ def test_command_new( options.append(path.as_posix()) command.execute(" ".join(options)) verify_project_directory(path, package_name, package_path, include_from) + + +@pytest.mark.parametrize("fmt", [(None,), ("md",), ("rst",)]) +def test_command_new_with_readme(fmt, command, tmp_dir): + fmt = "md" + package = "package" + path = Path(tmp_dir) / package + options = ["--readme {}".format(fmt) if fmt else "md", path.as_posix()] + command.execute(" ".join(options)) + + poetry = verify_project_directory(path, package, package, None) + assert poetry.local_config.get("readme") == "README.{}".format(fmt or "md")