diff --git a/docs/docs/basic-usage.md b/docs/docs/basic-usage.md index 86887943377..19a724b69b3 100644 --- a/docs/docs/basic-usage.md +++ b/docs/docs/basic-usage.md @@ -16,7 +16,7 @@ This will create the `poetry-demo` directory with the following content: ```text poetry-demo ├── pyproject.toml -├── README.rst +├── README.md ├── poetry_demo │ └── __init__.py └── tests diff --git a/docs/docs/cli.md b/docs/docs/cli.md index 1a142216924..437df068fa6 100644 --- a/docs/docs/cli.md +++ b/docs/docs/cli.md @@ -39,7 +39,7 @@ will create a folder as follows: ```text my-package ├── pyproject.toml -├── README.rst +├── README.md ├── my_package │ └── __init__.py └── tests @@ -65,7 +65,7 @@ That will create a folder structure as follows: ```text my-package ├── pyproject.toml -├── README.rst +├── README.md ├── src │ └── my_package │ └── __init__.py diff --git a/poetry/console/commands/init.py b/poetry/console/commands/init.py index 93dfc610db6..79195de3f50 100644 --- a/poetry/console/commands/init.py +++ b/poetry/console/commands/init.py @@ -17,6 +17,7 @@ class InitCommand(Command): init {--name= : Name of the package} {--description= : Description of the package} + {--readme= : Readme file of the package} {--author= : Author name of the package} {--dependency=* : Package to require with an optional version constraint, e.g. requests:^2.10.0 or requests=2.11.1} @@ -76,6 +77,12 @@ def handle(self): ) description = self.ask(question) + readme = self.option("readme") or "" + question = self.create_question( + "Readme [{}]: ".format(readme), default=readme + ) + readme = self.ask(question) + author = self.option("author") if not author and vcs_config and vcs_config.get("user.name"): author = vcs_config["user.name"] @@ -141,6 +148,7 @@ def handle(self): name, version, description=description, + readme=readme, author=authors[0] if authors else None, license=license, python=python, diff --git a/poetry/console/commands/new.py b/poetry/console/commands/new.py index c0ceb352726..fc6666a9e8d 100644 --- a/poetry/console/commands/new.py +++ b/poetry/console/commands/new.py @@ -35,7 +35,7 @@ def handle(self): "exists and is not empty".format(path) ) - readme_format = "rst" + readme_format = "md" config = GitConfig() author = None diff --git a/poetry/layouts/layout.py b/poetry/layouts/layout.py index e46ade211ad..94e4612efd6 100644 --- a/poetry/layouts/layout.py +++ b/poetry/layouts/layout.py @@ -48,6 +48,7 @@ def __init__( project, version="0.1.0", description="", + readme=None, readme_format="md", author=None, license=None, @@ -59,6 +60,7 @@ def __init__( self._package_name = module_name(project) self._version = version self._description = description + self._readme = readme self._readme_format = readme_format self._license = license self._python = python @@ -73,11 +75,11 @@ def __init__( self._author = author - def create(self, path, with_tests=True): + def create(self, path, with_tests=True, readme_format="md"): path.mkdir(parents=True, exist_ok=True) self._create_default(path) - self._create_readme(path) + self._create_readme(path, readme_format) if with_tests: self._create_tests(path) @@ -94,6 +96,10 @@ def generate_poetry_content(self): poetry_content["name"] = self._project poetry_content["version"] = self._version poetry_content["description"] = self._description + + if self._readme: + poetry_content["readme"] = self._readme + poetry_content["authors"].append(self._author) if self._license: poetry_content["license"] = self._license @@ -122,13 +128,18 @@ def generate_poetry_content(self): def _create_default(self, path, src=True): raise NotImplementedError() - 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, readme_format): + readme_file = path / "README.{}".format(self._readme_format) + + with open(readme_file, "w") as f: + if readme_format == "md": + f.write("# {}".format(self._project)) + elif readme_format == "rst": + f.write("=" * len(self._project)) + f.write("# {}".format(self._project)) + f.write("=" * len(self._project)) - readme_file.touch() + self._readme = readme_file def _create_tests(self, path): self._dev_dependencies["pytest"] = "^3.0"