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

Allow Private :: Do Not Upload classifier. #390

Merged
merged 2 commits into from
Apr 2, 2021
Merged
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
2 changes: 2 additions & 0 deletions doc/pyproject_toml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ description-file
(``.rst``, ``.md`` or ``.txt``).
classifiers
A list of `Trove classifiers <https://pypi.python.org/pypi?%3Aaction=list_classifiers>`_.
Add ``Private :: Do Not Upload`` into the list to prevent a private package
from uploading on PyPI by accident.
requires-python
A version specifier for the versions of Python this requires, e.g. ``~=3.3`` or
``>=3.3,<4`` which are equivalents.
Expand Down
11 changes: 9 additions & 2 deletions flit/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

log = logging.getLogger(__name__)

CUSTOM_CLASSIFIERS = frozenset({
# https://github.com/pypa/warehouse/pull/5440
'Private :: Do Not Upload',
})


def get_cache_dir() -> Path:
"""Locate a platform-appropriate cache directory for flit to use

Expand Down Expand Up @@ -96,6 +102,7 @@ def validate_classifiers(classifiers):
classifiers = set(classifiers)
try:
valid_classifiers = _read_classifiers_cached()
valid_classifiers.update(CUSTOM_CLASSIFIERS)
problems = _verify_classifiers(classifiers, valid_classifiers)
except (FileNotFoundError, PermissionError) as e1:
# We haven't yet got the classifiers cached or couldn't read it
Expand All @@ -120,8 +127,8 @@ def validate_classifiers(classifiers):
log.warning(
"Couldn't get list of valid classifiers to check against")
return problems
else:
return _verify_classifiers(classifiers, valid_classifiers)
valid_classifiers.update(CUSTOM_CLASSIFIERS)
return _verify_classifiers(classifiers, valid_classifiers)


def validate_entrypoints(entrypoints):
Expand Down
20 changes: 20 additions & 0 deletions tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,26 @@ def mock_get_cache_dir():
assert classifiers == {"A", "B", "C"}


def test_validate_classifiers_private(monkeypatch):
"""
Test that `Private :: Do Not Upload` considered a valid classifier.
This is a special case because it is not listed in a trove classifier
but it is a way to make sure that a private package is not get uploaded
on PyPI by accident.

Implementation on PyPI side:
https://github.com/pypa/warehouse/pull/5440
Issue about officially documenting the trick:
https://github.com/pypa/packaging.python.org/issues/643
"""
monkeypatch.setattr(fv, "_read_classifiers_cached", lambda: set())

actual = fv.validate_classifiers({'invalid'})
assert actual == ["Unrecognised classifier: 'invalid'"]

assert fv.validate_classifiers({'Private :: Do Not Upload'}) == []


@responses.activate
@pytest.mark.parametrize("error", [PermissionError, OSError(errno.EROFS, "")])
def test_download_and_cache_classifiers_with_unacessible_dir(monkeypatch, error):
Expand Down