Repository: pypa/build
Pull request #503 (2022-08-01 19:48:47)

pre-commit: bump repositories
<!--pre-commit.ci start-->
updates:
- [github.com/asottile/pyupgrade: v2.37.2 → v2.37.3](https://github.com/asottile/pyupgrade/compare/v2.37.2...v2.37.3)
- [github.com/asottile/setup-cfg-fmt: v1.20.2 → v2.0.0](https://github.com/asottile/setup-cfg-fmt/compare/v1.20.2...v2.0.0)
- [github.com/PyCQA/flake8: 4.0.1 → 5.0.2](https://github.com/PyCQA/flake8/compare/4.0.1...5.0.2)
<!--pre-commit.ci end-->


Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 289e3d7..66b6252 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -18,7 +18,7 @@ repos:
       - id: trailing-whitespace
       - id: double-quote-string-fixer
   - repo: https://github.com/asottile/pyupgrade
-    rev: v2.37.2
+    rev: v2.37.3
     hooks:
       - id: pyupgrade
         args: ["--py36-plus"]
@@ -30,7 +30,7 @@ repos:
     rev: v1.12.1
     hooks:
       - id: blacken-docs
-        additional_dependencies: [black==22.3.0]
+        additional_dependencies: [black==22.6]
   - repo: https://github.com/pre-commit/mirrors-prettier
     rev: "v2.7.1"
     hooks:
@@ -40,14 +40,15 @@ repos:
     hooks:
       - id: isort
   - repo: https://github.com/asottile/setup-cfg-fmt
-    rev: v1.20.2
+    rev: v2.0.0
     hooks:
       - id: setup-cfg-fmt
+        args: [--include-version-classifiers, --max-py-version=3.11]
   - repo: https://github.com/PyCQA/flake8
-    rev: "4.0.1"
+    rev: "5.0.4"
     hooks:
       - id: flake8
-        additional_dependencies: ["flake8-bugbear == 22.3.23"]
+        additional_dependencies: ["flake8-bugbear==22.7.1"]
         language_version: python3.9
   - repo: https://github.com/codespell-project/codespell
     rev: "v2.1.0"
diff --git a/setup.cfg b/setup.cfg
index 27ba248..d3e3056 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -17,6 +17,7 @@ classifiers =
     Programming Language :: Python :: 3.8
     Programming Language :: Python :: 3.9
     Programming Language :: Python :: 3.10
+    Programming Language :: Python :: 3.11
     Programming Language :: Python :: Implementation :: CPython
     Programming Language :: Python :: Implementation :: PyPy
 project_urls =
diff --git a/src/build/__init__.py b/src/build/__init__.py
index 6985ed0..ea534b3 100644
--- a/src/build/__init__.py
+++ b/src/build/__init__.py
@@ -290,9 +290,9 @@ class ProjectBuilder:
         except FileNotFoundError:
             spec = {}
         except PermissionError as e:
-            raise BuildException(f"{e.strerror}: '{e.filename}' ")
+            raise BuildException(f"{e.strerror}: '{e.filename}' ")  # noqa: B904 # use raise from
         except TOMLDecodeError as e:
-            raise BuildException(f'Failed to parse {spec_file}: {e} ')
+            raise BuildException(f'Failed to parse {spec_file}: {e} ')  # noqa: B904 # use raise from
 
         self._build_system = _parse_build_system_table(spec)
         self._backend = self._build_system['build-backend']
@@ -486,15 +486,17 @@ class ProjectBuilder:
             try:
                 yield
             except pep517.wrappers.BackendUnavailable as exception:
-                raise BuildBackendException(
+                raise BuildBackendException(  # noqa: B904 # use raise from
                     exception,
                     f"Backend '{self._backend}' is not available.",
                     sys.exc_info(),
                 )
             except subprocess.CalledProcessError as exception:
-                raise BuildBackendException(exception, f'Backend subprocess exited when trying to invoke {hook}')
+                raise BuildBackendException(  # noqa: B904 # use raise from
+                    exception, f'Backend subprocess exited when trying to invoke {hook}'
+                )
             except Exception as exception:
-                raise BuildBackendException(exception, exc_info=sys.exc_info())
+                raise BuildBackendException(exception, exc_info=sys.exc_info())  # noqa: B904 # use raise from
 
     @staticmethod
     def log(message: str) -> None:
diff --git a/src/build/env.py b/src/build/env.py
index b9e8f62..101aadd 100644
--- a/src/build/env.py
+++ b/src/build/env.py
@@ -18,11 +18,6 @@ from typing import Callable, Collection, List, Optional, Tuple, Type
 import build
 
 
-if sys.version_info < (3, 8):
-    import importlib_metadata as metadata
-else:
-    from importlib import metadata
-
 try:
     import virtualenv
 except ModuleNotFoundError:
@@ -260,6 +255,11 @@ def _create_isolated_env_venv(path: str) -> Tuple[str, str]:
 
     import packaging.version
 
+    if sys.version_info < (3, 8):
+        import importlib_metadata as metadata
+    else:
+        from importlib import metadata
+
     symlinks = _fs_supports_symlink()
     try:
         venv.EnvBuilder(with_pip=True, symlinks=symlinks).create(path)


Test patch:
diff --git a/tests/test_env.py b/tests/test_env.py
index a1ee0cb..7f683c4 100644
--- a/tests/test_env.py
+++ b/tests/test_env.py
@@ -117,7 +117,11 @@ def test_isolated_env_log(mocker, caplog, package_test_flit):
         ('INFO', 'Installing packages in isolated environment... (something)'),
     ]
     if sys.version_info >= (3, 8):  # stacklevel
-        assert [(record.lineno) for record in caplog.records] == [frameinfo.lineno + 1, 107, 198]
+        assert [(record.lineno) for record in caplog.records] == [
+            frameinfo.lineno + 1,
+            frameinfo.lineno - 7,
+            frameinfo.lineno + 84,
+        ]
 
 
 @pytest.mark.isolated
@@ -139,7 +143,8 @@ def test_pip_needs_upgrade_mac_os_11(mocker, pip_version, arch):
     mocker.patch('platform.system', return_value='Darwin')
     mocker.patch('platform.machine', return_value=arch)
     mocker.patch('platform.mac_ver', return_value=('11.0', ('', '', ''), ''))
-    mocker.patch('build.env.metadata.distributions', return_value=(SimpleNamespace(version=pip_version),))
+    metadata_name = 'importlib_metadata' if sys.version_info < (3, 8) else 'importlib.metadata'
+    mocker.patch(metadata_name + '.distributions', return_value=(SimpleNamespace(version=pip_version),))
 
     min_version = Version('20.3' if arch == 'x86_64' else '21.0.1')
     with build.env.IsolatedEnvBuilder():