From e8d4d7c3f0aaf1777e3b74f53ab9e345cd80c8c8 Mon Sep 17 00:00:00 2001 From: Lukasz Boldys Date: Wed, 8 Apr 2020 22:23:34 +0200 Subject: [PATCH] Add publish-default package setting that overrides the default behaviour of publish --- docs/docs/pyproject.md | 4 ++++ docs/docs/repositories.md | 3 ++- poetry/json/schemas/poetry-schema.json | 4 ++++ poetry/publishing/publisher.py | 3 +++ tests/console/commands/test_publish.py | 14 ++++++++++++++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/docs/docs/pyproject.md b/docs/docs/pyproject.md index 004fa5c1b22..2764761ca90 100644 --- a/docs/docs/pyproject.md +++ b/docs/docs/pyproject.md @@ -293,3 +293,7 @@ build-backend = "poetry.core.masonry.api" If your `pyproject.toml` file still references `poetry` directly as a build backend, you should update it to reference `poetry_core` instead. + +## publish-default + +Name of the repository that will be used as a default when running `poetry publish`. If not provided the [PyPI](https://pypi.org) will be used. diff --git a/docs/docs/repositories.md b/docs/docs/repositories.md index d281f6ca77a..baa033aed48 100644 --- a/docs/docs/repositories.md +++ b/docs/docs/repositories.md @@ -3,7 +3,8 @@ ## Using the PyPI repository By default, Poetry is configured to use the [PyPI](https://pypi.org) repository, -for package installation and publishing. +for package installation and publishing. User can override this behavior by setting +`publish-default` in the `[tool.poetry]` section. So, when you add dependencies to your project, Poetry will assume they are available on PyPI. diff --git a/poetry/json/schemas/poetry-schema.json b/poetry/json/schemas/poetry-schema.json index e94b90d28cc..bf1771455d1 100644 --- a/poetry/json/schemas/poetry-schema.json +++ b/poetry/json/schemas/poetry-schema.json @@ -173,6 +173,10 @@ "description": "The full url of the custom url." } } + }, + "publish-default": { + "type": "string", + "description": "Name of the default publish repository." } }, "definitions": { diff --git a/poetry/publishing/publisher.py b/poetry/publishing/publisher.py index d30a9a47119..e70267c18a0 100644 --- a/poetry/publishing/publisher.py +++ b/poetry/publishing/publisher.py @@ -38,6 +38,9 @@ def publish( client_cert=None, dry_run=False, ): # type: (Optional[str], Optional[str], Optional[str], Optional[Path], Optional[Path], Optional[bool]) -> None + # Set repository name to publish-default. It will be None if not set + repository_name = repository_name or self._package.publish_default + if not repository_name: url = "https://upload.pypi.org/legacy/" repository_name = "pypi" diff --git a/tests/console/commands/test_publish.py b/tests/console/commands/test_publish.py index dccc43ee87d..32b9cdd5c40 100644 --- a/tests/console/commands/test_publish.py +++ b/tests/console/commands/test_publish.py @@ -107,3 +107,17 @@ def test_publish_dry_run(app_tester, http): assert "Publishing simple-project (1.2.3) to PyPI" in output assert "- Uploading simple-project-1.2.3.tar.gz" in error assert "- Uploading simple_project-1.2.3-py2.py3-none-any.whl" in error + + +def test_publish_with_publish_default_set(app, app_tester, http): + app.poetry.package.publish_default = "private_pypi" + app_tester.execute("publish") + + expected = """ +Publishing simple-project (1.2.3) to private_pypi + +[RuntimeError] +Repository private_pypi is not defined +""" + + assert app_tester.io.fetch_output() == expected