From bb5666f2c032f764480ef8926c49b15c6f0307b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Baasch=20de=20Souza?= Date: Sun, 8 Jul 2018 22:19:21 -0300 Subject: [PATCH 1/3] Change READMEs' default format to md; add project name to new READMEs --- poetry/console/commands/new.py | 2 +- poetry/layouts/layout.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/poetry/console/commands/new.py b/poetry/console/commands/new.py index 16d876ada1a..cdae347dcfe 100644 --- a/poetry/console/commands/new.py +++ b/poetry/console/commands/new.py @@ -34,7 +34,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 a41654886bd..db17ac9647a 100644 --- a/poetry/layouts/layout.py +++ b/poetry/layouts/layout.py @@ -107,12 +107,10 @@ 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" + readme_file = path / "README.{}".format(self._readme_format) - readme_file.touch() + with open(readme_file, "w") as f: + f.write("# {}".format(self._project)) def _create_tests(self, path): self._dev_dependencies["pytest"] = "^3.0" From df8d3a15640d886e8f1e3997be4078860d1d0146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Baasch=20de=20Souza?= Date: Sun, 8 Jul 2018 22:26:15 -0300 Subject: [PATCH 2/3] Update docs with new default format for README --- docs/docs/basic-usage.md | 16 ++++++++-------- docs/docs/cli.md | 4 ++-- docs/docs/pyproject.md | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/docs/basic-usage.md b/docs/docs/basic-usage.md index f897447d4f8..3bf2f5bf495 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 @@ -56,7 +56,7 @@ Poetry uses this information to search for the right set of files in package "re in the `tool.poetry.repositories` section, or on [PyPI](https://pypi.org) by default. Also, instead of modifying the `pyproject.toml` file by hand, you can use the `add` command. - + ```bash $ poetry add pendulum ``` @@ -75,20 +75,20 @@ Please read [versions](/versions/) for more in-depth information on versions, ho !!!note **How does Poetry download the right files?** - + When you specify a dependency in `pyproject.toml`, Poetry first take the name of the package that you have requested and searches for it in any repository you have registered using the `repositories` key. If you have not registered any extra repositories, or it does not find a package with that name in the repositories you have specified, it falls back on PyPI. - + When Poetry finds the right package, it then attempts to find the best match for the version constraint you have specified. - + ## Installing dependencies To install the defined dependencies for your project, just run the `install` command. - + ```bash poetry install ``` @@ -132,7 +132,7 @@ the dependencies installed are still working even if your dependencies released !!!note For libraries it is not necessary to commit the lock file. - + ## Updating dependencies to their latest versions @@ -159,7 +159,7 @@ or create a brand new one for you to always work isolated from your global Pytho The created virtualenv will use the Python executable for which `poetry` has been installed. - + What this means is if you project is Python 2.7 only you should install `poetry` for your global Python 2.7 executable and use it to manage your project. diff --git a/docs/docs/cli.md b/docs/docs/cli.md index c5feb5dbce5..56ee4d08e77 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/docs/docs/pyproject.md b/docs/docs/pyproject.md index 2ff6317a36b..46f7880c86b 100644 --- a/docs/docs/pyproject.md +++ b/docs/docs/pyproject.md @@ -48,7 +48,7 @@ Authors must be in the form `name `. ## readme -The readme file of the package. **Required** +The readme file of the package. **Optional** The file can be either `README.rst` or `README.md`. From a8b534811c1e11541673eb426d34ef9b824321d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Baasch=20de=20Souza?= Date: Mon, 9 Jul 2018 14:15:40 -0300 Subject: [PATCH 3/3] Automatically add readme to pyproject.toml --- poetry/console/commands/init.py | 10 +++++++++- poetry/layouts/layout.py | 21 +++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/poetry/console/commands/init.py b/poetry/console/commands/init.py index e3550d623b2..3361c8e2fe6 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} @@ -48,7 +49,7 @@ def handle(self): self.line( [ "", - "This command will guide you through creating your poetry.toml config.", + "This command will guide you through creating your pyproject.toml config.", "", ] ) @@ -75,6 +76,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"] @@ -126,6 +133,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/layouts/layout.py b/poetry/layouts/layout.py index db17ac9647a..5f113ac8898 100644 --- a/poetry/layouts/layout.py +++ b/poetry/layouts/layout.py @@ -43,6 +43,7 @@ def __init__( project, version="0.1.0", description="", + readme=None, readme_format="md", author=None, license=None, @@ -54,6 +55,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 @@ -68,11 +70,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) @@ -89,6 +91,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 @@ -106,11 +112,18 @@ def generate_poetry_content(self): def _create_default(self, path, src=True): raise NotImplementedError() - def _create_readme(self, path): + def _create_readme(self, path, readme_format): readme_file = path / "README.{}".format(self._readme_format) with open(readme_file, "w") as f: - f.write("# {}".format(self._project)) + 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)) + + self._readme = readme_file def _create_tests(self, path): self._dev_dependencies["pytest"] = "^3.0"