Skip to content

Commit

Permalink
Merge pull request #390 from orsinium-forks/private-classifier
Browse files Browse the repository at this point in the history
Allow `Private :: Do Not Upload` classifier.
  • Loading branch information
takluyver authored Apr 2, 2021
2 parents f8e318e + e44077a commit b944ecc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
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

0 comments on commit b944ecc

Please sign in to comment.