Skip to content

Commit

Permalink
Add publish-default package setting that overrides the default behavi…
Browse files Browse the repository at this point in the history
…our of publish
  • Loading branch information
Lukasz Boldys committed Apr 13, 2020
1 parent 440cff1 commit e8d4d7c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/docs/pyproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 2 additions & 1 deletion docs/docs/repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions poetry/json/schemas/poetry-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@
"description": "The full url of the custom url."
}
}
},
"publish-default": {
"type": "string",
"description": "Name of the default publish repository."
}
},
"definitions": {
Expand Down
3 changes: 3 additions & 0 deletions poetry/publishing/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions tests/console/commands/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e8d4d7c

Please sign in to comment.