diff --git a/docs/docs/pyproject.md b/docs/docs/pyproject.md index 004fa5c1b22..6904a68545b 100644 --- a/docs/docs/pyproject.md +++ b/docs/docs/pyproject.md @@ -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 diff --git a/poetry/json/schemas/poetry-schema.json b/poetry/json/schemas/poetry-schema.json index e94b90d28cc..96de00677c2 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." } } + }, + "private": { + "type": "boolean", + "description": "Mark as private. Turn off the default publish behavior." } }, "definitions": { diff --git a/poetry/publishing/publisher.py b/poetry/publishing/publisher.py index d30a9a47119..7d42d54b458 100644 --- a/poetry/publishing/publisher.py +++ b/poetry/publishing/publisher.py @@ -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( + "This project can't be published using default repository " + "as it is marked as a private package.\n" + "You probably don't want to publish it to default pypi " + "repository.\n\n" + "Please use `poetry publish -r ` " + "to publish this package" + ) + return + elif not repository_name: url = "https://upload.pypi.org/legacy/" repository_name = "pypi" else: diff --git a/tests/console/commands/test_publish.py b/tests/console/commands/test_publish.py index dccc43ee87d..5016994a154 100644 --- a/tests/console/commands/test_publish.py +++ b/tests/console/commands/test_publish.py @@ -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()