Skip to content

Commit

Permalink
Introduce/document VALIDATE_PYPROJECT_NO_NETWORK (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Mar 30, 2022
2 parents 9a1e75b + b6307ac commit ac752ca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
14 changes: 9 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,19 @@ To do so, don't forget to add it to your `virtual environment`_ or specify it as
``packaging`` and ``trove-classifiers`` will be automatically pulled as
dependencies. ``tomli`` is a lightweight parser for TOML, while
``packaging`` and ``trove-classifiers`` are used to validate aspects of `PEP
621`_
621`_.

If you are only interested in using the Python API and wants to keep the
depedependencies minimal, you can also install ``validate-pyproject``
dependencies minimal, you can also install ``validate-pyproject``
(without the ``[all]`` extra dependencies group).

If you don't install ``trove-classifiers``, ``validate-pyproject`` will
perform a weaker validation. On the other hand, if ``validate-pyproject``
cannot find a copy of ``packaging`` in your environment, the validation will
fail.
try to download a list of valid classifiers directly from PyPI
(to prevent that, set the environment variable
``NO_NETWORK`` or ``VALIDATE_PYPROJECT_NO_NETWORK``).

On the other hand, if ``validate-pyproject`` cannot find a copy of
``packaging`` in your environment, the validation will fail.

More details about ``validate-pyproject`` and its Python API can be found in
`our docs`_, which includes a description of the `used JSON schemas`_,
Expand Down
2 changes: 1 addition & 1 deletion src/validate_pyproject/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def __call__(self, value: str) -> bool:
if self.downloaded is False:
return True

if os.getenv("NO_NETWORK"):
if os.getenv("NO_NETWORK") or os.getenv("VALIDATE_PYPROJECT_NO_NETWORK"):
self.downloaded = False
msg = (
"Install ``trove-classifiers`` to ensure proper validation. "
Expand Down
7 changes: 5 additions & 2 deletions tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,11 @@ def test_valid_download_only_once(self, monkeypatch):
assert validator(classifier) is True
downloader.assert_called_once()

def test_always_valid_with_no_network(self, monkeypatch):
monkeypatch.setenv("NO_NETWORK", "1")
@pytest.mark.parametrize(
"no_network", ("NO_NETWORK", "VALIDATE_PYPROJECT_NO_NETWORK")
)
def test_always_valid_with_no_network(self, monkeypatch, no_network):
monkeypatch.setenv(no_network, "1")
validator = formats._TroveClassifier()
assert validator("Made Up :: Classifier") is True
assert not validator.downloaded
Expand Down
5 changes: 5 additions & 0 deletions tests/test_vendoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ def test_api(tmp_path):
def test_cli(tmp_path):
with pytest.warns(DeprecationWarning, match="will be removed"):
cli.run(["-O", str(tmp_path)])


def test_main(tmp_path):
with pytest.warns(DeprecationWarning, match="will be removed"):
cli.main(["-O", str(tmp_path)])

0 comments on commit ac752ca

Please sign in to comment.