From 6681d8bf2a05eb27cf5e776d0a71147c23eece43 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 12 May 2022 12:39:52 -0400 Subject: [PATCH] chore: minor cleanups from #361 Co-authored-by: layday Apply suggestions from code review tests: add test for coverage --- .github/workflows/check.yml | 2 +- .readthedocs.yml | 6 +++++- setup.cfg | 2 +- src/build/__init__.py | 29 ++++++++++++++++++----------- src/build/__main__.py | 2 +- tests/test_module.py | 9 +++++++++ 6 files changed, 35 insertions(+), 15 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ed9908d8..148e7e58 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -29,5 +29,5 @@ jobs: - name: Setup run environment run: tox -vv --notest -e docs - - name: Run check for type + - name: Run check for docs run: tox -e docs --skip-pkg-install diff --git a/.readthedocs.yml b/.readthedocs.yml index 60278c43..76beb6b2 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,7 +1,11 @@ version: 2 +build: + os: ubuntu-20.04 + tools: + python: '3.10' + python: - version: 3.8 install: - method: pip path: . diff --git a/setup.cfg b/setup.cfg index f1ab1ad9..f314a613 100644 --- a/setup.cfg +++ b/setup.cfg @@ -64,7 +64,7 @@ test = typing = importlib-metadata>=4.6.4 mypy==0.942 - typing-extensions>=3.7.4.3 + typing-extensions>=3.7.4.3;python_version < "3.8" virtualenv = virtualenv>=20.0.35 diff --git a/src/build/__init__.py b/src/build/__init__.py index a6fa436f..ce742040 100644 --- a/src/build/__init__.py +++ b/src/build/__init__.py @@ -3,6 +3,7 @@ """ build - A simple, correct PEP 517 build frontend """ + __version__ = '0.7.0' import contextlib @@ -24,6 +25,7 @@ Callable, Dict, Iterator, + List, Mapping, MutableMapping, Optional, @@ -71,18 +73,18 @@ } -_logger = logging.getLogger('build') +_logger = logging.getLogger(__name__) class BuildException(Exception): """ - Exception raised by ProjectBuilder + Exception raised by :class:`ProjectBuilder` """ class BuildBackendException(Exception): """ - Exception raised when the backend fails + Exception raised when a backend operation fails """ def __init__( @@ -131,7 +133,7 @@ def __str__(self) -> str: class TypoWarning(Warning): """ - Warning raised when a potential typo is found + Warning raised when a possible typo is found """ @@ -428,12 +430,13 @@ def build( def metadata_path(self, output_directory: PathType) -> str: """ - Generates the metadata directory of a distribution and returns its path. + Generate the metadata directory of a distribution and return its path. If the backend does not support the ``prepare_metadata_for_build_wheel`` - hook, a wheel will be built and the metadata extracted. + hook, a wheel will be built and the metadata will be extracted from it. :param output_directory: Directory to put the metadata distribution in + :returns: The path of the metadata directory """ # prepare_metadata hook metadata = self.prepare('wheel', output_directory) @@ -491,12 +494,12 @@ def _handle_backend(self, hook: str) -> Iterator[None]: @staticmethod def log(message: str) -> None: """ - Prints message + Log a message. The default implementation uses the logging module but this function can be - overwritten by users to have a different implementation. + overridden by users to have a different implementation. - :param msg: Message to output + :param message: Message to output """ if sys.version_info >= (3, 8): _logger.log(logging.INFO, message, stacklevel=2) @@ -504,7 +507,7 @@ def log(message: str) -> None: _logger.log(logging.INFO, message) -__all__ = ( +__all__ = [ '__version__', 'BuildBackendException', 'BuildException', @@ -514,4 +517,8 @@ def log(message: str) -> None: 'RunnerType', 'TypoWarning', 'check_dependency', -) +] + + +def __dir__() -> List[str]: + return __all__ diff --git a/src/build/__main__.py b/src/build/__main__.py index 843564bd..df244cc9 100644 --- a/src/build/__main__.py +++ b/src/build/__main__.py @@ -79,7 +79,7 @@ def _error(msg: str, code: int = 1) -> NoReturn: # pragma: no cover :param code: Error code """ print('{red}ERROR{reset} {}'.format(msg, **_STYLES)) - exit(code) + raise SystemExit(code) class _ProjectBuilder(ProjectBuilder): diff --git a/tests/test_module.py b/tests/test_module.py index 87cc631e..1d3d1cc1 100644 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -1,7 +1,16 @@ # SPDX-License-Identifier: MIT +import sys + +import pytest + import build def test_version(): assert build.__version__ + + +@pytest.mark.skipif(sys.version_info < (3, 7), reason='Python 3.7+ required for dir support') +def test_dir(): + assert set(dir(build)) == set(build.__all__)