Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add private property to project properties blocks publishing without -r #2322

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/docs/pyproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ any custom url in the `urls` section.

If you publish you package on PyPI, they will appear in the `Project Links` section.


## private

Setting this to `true` marks the project as private. This will prevent using
public PYPI repository by default when running `poetry publish`.
Publishing will require using `-r` option for projects mark as private.


## Poetry and PEP-517

[PEP-517](https://www.python.org/dev/peps/pep-0517/) introduces a standard way
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."
}
}
},
"private": {
"type": "boolean",
"description": "Mark as private. Turn off the default publish behavior."
}
},
"definitions": {
Expand Down
12 changes: 11 additions & 1 deletion poetry/publishing/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ def publish(
client_cert=None,
dry_run=False,
): # type: (Optional[str], Optional[str], Optional[str], Optional[Path], Optional[Path], Optional[bool]) -> None
if not repository_name:
if not repository_name and self._package.private:
self._io.write_line(
"<warning>This project can't be published using default repository "
"as it is marked as a <b>private</> package.\n"
"You probably don't want to publish it to default pypi "
"repository.</>\n\n"
"Please use <c1>`poetry publish -r <repository_name>`</> "
"to publish this package"
)
return
elif not repository_name:
url = "https://upload.pypi.org/legacy/"
repository_name = "pypi"
else:
Expand Down
12 changes: 12 additions & 0 deletions tests/console/commands/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,15 @@ 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_private_property(app, app_tester, http):
app.poetry.package.private = True
app_tester.execute("publish")

expected = (
"This project can't be published using default repository as it is "
"marked as a private package."
)

assert expected in app_tester.io.fetch_output()