Skip to content

Commit

Permalink
Allow Private :: Do Not Upload classifier.
Browse files Browse the repository at this point in the history
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:
    pypi/warehouse#5440
Issue about officially documenting the trick:
    pypa/packaging.python.org#643
  • Loading branch information
orsinium committed Feb 3, 2021
1 parent 8f93601 commit 3255c1f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
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

0 comments on commit 3255c1f

Please sign in to comment.