diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3277627305..0941dd3f5c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -54,7 +54,7 @@ repos: # auto format Python codes within docstrings - id: blacken-docs - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.2 + rev: v0.3.2 hooks: # lint & attempt to correct failures (e.g. pyupgrade) - id: ruff diff --git a/conda_build/__version__.py b/conda_build/__version__.py index e835e1be9d..e664582d94 100644 --- a/conda_build/__version__.py +++ b/conda_build/__version__.py @@ -6,6 +6,7 @@ Conda-build abides by CEP-8 which specifies using CalVer, so the dev version is: YY.MM.MICRO.devN+gHASH[.dirty] """ + try: from setuptools_scm import get_version diff --git a/conda_build/_link.py b/conda_build/_link.py index 21ea66aaed..af841c0275 100644 --- a/conda_build/_link.py +++ b/conda_build/_link.py @@ -4,6 +4,7 @@ This is code that is added to noarch Python packages. See conda_build/noarch_python.py. """ + from __future__ import annotations import os diff --git a/conda_build/api.py b/conda_build/api.py index a8fc525e66..f83e235354 100644 --- a/conda_build/api.py +++ b/conda_build/api.py @@ -8,6 +8,7 @@ Design philosophy: put variability into config. Make each function here accept kwargs, but only use those kwargs in config. Config must change to support new features elsewhere. """ + from __future__ import annotations # imports are done locally to keep the api clean and limited strictly diff --git a/conda_build/build.py b/conda_build/build.py index 9e62fc7293..f2ffb06cdf 100644 --- a/conda_build/build.py +++ b/conda_build/build.py @@ -3,6 +3,7 @@ """ Module that does most of the heavy lifting for the ``conda build`` command. """ + import fnmatch import json import os diff --git a/conda_build/config.py b/conda_build/config.py index 5d4ba590d3..9a33dac858 100644 --- a/conda_build/config.py +++ b/conda_build/config.py @@ -3,6 +3,7 @@ """ Module to store conda build settings. """ + from __future__ import annotations import copy diff --git a/conda_build/convert.py b/conda_build/convert.py index c2882d1508..793f0dc93c 100644 --- a/conda_build/convert.py +++ b/conda_build/convert.py @@ -3,6 +3,7 @@ """ Tools for converting conda packages """ + import glob import hashlib import json diff --git a/conda_build/create_test.py b/conda_build/create_test.py index 1788bbe97d..1a8a0f1c34 100644 --- a/conda_build/create_test.py +++ b/conda_build/create_test.py @@ -3,6 +3,7 @@ """ Module to handle generating test files. """ + from __future__ import annotations import json diff --git a/conda_build/deprecations.py b/conda_build/deprecations.py index 67ceb59c7f..494f0f85f1 100644 --- a/conda_build/deprecations.py +++ b/conda_build/deprecations.py @@ -1,6 +1,7 @@ # Copyright (C) 2014 Anaconda, Inc # SPDX-License-Identifier: BSD-3-Clause """Tools to aid in deprecating code.""" + from __future__ import annotations import sys diff --git a/conda_build/jinja_context.py b/conda_build/jinja_context.py index 2ef9b910d1..cc5c3b24c7 100644 --- a/conda_build/jinja_context.py +++ b/conda_build/jinja_context.py @@ -73,39 +73,13 @@ def __init__( # Using any of these methods on an Undefined variable # results in another Undefined variable. - __add__ = ( - __radd__ - ) = ( - __mul__ - ) = ( - __rmul__ - ) = ( - __div__ - ) = ( - __rdiv__ - ) = ( - __truediv__ - ) = ( + __add__ = __radd__ = __mul__ = __rmul__ = __div__ = __rdiv__ = __truediv__ = ( __rtruediv__ - ) = ( - __floordiv__ - ) = ( - __rfloordiv__ - ) = ( - __mod__ - ) = ( - __rmod__ - ) = ( - __pos__ - ) = ( - __neg__ - ) = ( + ) = __floordiv__ = __rfloordiv__ = __mod__ = __rmod__ = __pos__ = __neg__ = ( __call__ - ) = ( - __getitem__ - ) = __lt__ = __le__ = __gt__ = __ge__ = __complex__ = __pow__ = __rpow__ = ( - lambda self, *args, **kwargs: self._return_undefined(self._undefined_name) - ) + ) = __getitem__ = __lt__ = __le__ = __gt__ = __ge__ = __complex__ = __pow__ = ( + __rpow__ + ) = lambda self, *args, **kwargs: self._return_undefined(self._undefined_name) # Accessing an attribute of an Undefined variable # results in another Undefined variable. diff --git a/conda_build/metadata.py b/conda_build/metadata.py index 633b6de8fc..e3b814d8a7 100644 --- a/conda_build/metadata.py +++ b/conda_build/metadata.py @@ -1341,8 +1341,7 @@ def fromdict(cls, metadata, config=None, variant=None): return m @overload - def get_section(self, section: Literal["source", "outputs"]) -> list[dict]: - ... + def get_section(self, section: Literal["source", "outputs"]) -> list[dict]: ... @overload def get_section( @@ -1356,8 +1355,7 @@ def get_section( "about", "extra", ], - ) -> dict: - ... + ) -> dict: ... def get_section(self, name): section = self.meta.get(name) @@ -2553,9 +2551,9 @@ def get_output_metadata_set( ) ] = (out, out_metadata) out_metadata_map[HashableDict(out)] = out_metadata - ref_metadata.other_outputs = ( - out_metadata.other_outputs - ) = all_output_metadata + ref_metadata.other_outputs = out_metadata.other_outputs = ( + all_output_metadata + ) except SystemExit: if not permit_undefined_jinja: raise diff --git a/conda_build/os_utils/macho.py b/conda_build/os_utils/macho.py index 950ebd6d57..516df7a0a6 100644 --- a/conda_build/os_utils/macho.py +++ b/conda_build/os_utils/macho.py @@ -191,12 +191,10 @@ def find_apple_cctools_executable(name, build_prefix, nofail=False): tool = tool_xcr if os.path.exists(tool): return tool - except Exception as _: # noqa + except Exception: # noqa print( - "ERROR :: Failed to run `{}`. Please use `conda` to install `cctools` into your base environment.\n" - " An option on macOS is to install `Xcode` or `Command Line Tools for Xcode`.".format( - tool - ) + f"ERROR :: Failed to run `{tool}`. Use `conda` to install `cctools` into your base environment.\n" + f" An option on macOS is to install `Xcode` or `Command Line Tools for Xcode`." ) sys.exit(1) return tool diff --git a/conda_build/post.py b/conda_build/post.py index 4512c9e508..eea8a584b6 100644 --- a/conda_build/post.py +++ b/conda_build/post.py @@ -1402,9 +1402,11 @@ def check_overlinking_impl( if diffs: log = utils.get_logger(__name__) log.warning( - "Partially parsed some '.tbd' files in sysroot {}, pretending .tbds are their install-names\n" + "Partially parsed some '.tbd' files in sysroot %s, pretending .tbds are their install-names\n" "Adding support to 'conda-build' for parsing these in 'liefldd.py' would be easy and useful:\n" - "{} ...".format(sysroot, list(diffs)[1:3]) + "%s...", + sysroot, + list(diffs)[1:3], ) sysroots_files[srs] = sysroot_files sysroots_files = OrderedDict( diff --git a/conda_build/skeletons/cpan.py b/conda_build/skeletons/cpan.py index 891f62f3cb..8d1d996e1b 100644 --- a/conda_build/skeletons/cpan.py +++ b/conda_build/skeletons/cpan.py @@ -3,6 +3,7 @@ """ Tools for converting CPAN packages to conda recipes. """ + import codecs import gzip import hashlib @@ -149,7 +150,6 @@ class InvalidReleaseError(RuntimeError): - """ An exception that is raised when a release is not available on MetaCPAN. """ @@ -158,7 +158,6 @@ class InvalidReleaseError(RuntimeError): class PerlTmpDownload(TmpDownload): - """ Subclass Conda's TmpDownload to replace : in download filenames. Critical on win. diff --git a/conda_build/skeletons/cran.py b/conda_build/skeletons/cran.py index 423941164e..7140c9a89f 100755 --- a/conda_build/skeletons/cran.py +++ b/conda_build/skeletons/cran.py @@ -3,6 +3,7 @@ """ Tools for converting Cran packages to conda recipes. """ + from __future__ import annotations import argparse diff --git a/conda_build/skeletons/pypi.py b/conda_build/skeletons/pypi.py index 92e2ff9efd..abf1a173bc 100644 --- a/conda_build/skeletons/pypi.py +++ b/conda_build/skeletons/pypi.py @@ -3,6 +3,7 @@ """ Tools for converting PyPI packages to conda recipes. """ + import keyword import logging import os diff --git a/conda_build/source.py b/conda_build/source.py index 436a4137b2..3583f0b8ce 100644 --- a/conda_build/source.py +++ b/conda_build/source.py @@ -379,9 +379,8 @@ def git_mirror_checkout_recursive( ) if verbose: print( - "Relative submodule {} found: url is {}, submod_mirror_dir is {}".format( - submod_name, submod_url, submod_mirror_dir - ) + f"Relative submodule {submod_name} found: url is {submod_url}, " + f"submod_mirror_dir is {submod_mirror_dir}" ) with TemporaryDirectory() as temp_checkout_dir: git_mirror_checkout_recursive( diff --git a/conda_build/utils.py b/conda_build/utils.py index 7635c45a6f..36a65ead4e 100644 --- a/conda_build/utils.py +++ b/conda_build/utils.py @@ -1132,8 +1132,9 @@ def convert_path_for_cygwin_or_msys2(exe, path): def get_skip_message(m): - return "Skipped: {} from {} defines build/skip for this configuration ({}).".format( - m.name(), m.path, {k: m.config.variant[k] for k in m.get_used_vars()} + return ( + f"Skipped: {m.name()} from {m.path} defines build/skip for this configuration " + f"({({k: m.config.variant[k] for k in m.get_used_vars()})})." ) @@ -1897,13 +1898,11 @@ def sort_list_in_nested_structure(dictionary, omissions=""): @overload -def ensure_valid_spec(spec: str, warn: bool = False) -> str: - ... +def ensure_valid_spec(spec: str, warn: bool = False) -> str: ... @overload -def ensure_valid_spec(spec: MatchSpec, warn: bool = False) -> MatchSpec: - ... +def ensure_valid_spec(spec: MatchSpec, warn: bool = False) -> MatchSpec: ... def ensure_valid_spec(spec: str | MatchSpec, warn: bool = False) -> str | MatchSpec: diff --git a/conda_build/variants.py b/conda_build/variants.py index 2ece5f4bd6..e4c541ed96 100644 --- a/conda_build/variants.py +++ b/conda_build/variants.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: BSD-3-Clause """This file handles the parsing of feature specifications from files, ending up with a configuration matrix""" + import os.path import re import sys @@ -303,15 +304,10 @@ def _combine_spec_dictionaries( ensure_list(v) ): raise ValueError( - "All entries associated by a zip_key " - "field must be the same length. In {}, {} and {} are " - "different ({} and {})".format( - spec_source, - k, - group_item, - len(ensure_list(v)), - len(ensure_list(spec[group_item])), - ) + f"All entries associated by a zip_key " + f"field must be the same length. In {spec_source}, {k} and {group_item} " + f"are different ({len(ensure_list(v))} and " + f"{len(ensure_list(spec[group_item]))})" ) values[group_item] = ensure_list(spec[group_item]) elif k in values: @@ -338,17 +334,10 @@ def _combine_spec_dictionaries( ] if len(missing_subvalues): raise ValueError( - "variant config in {} is ambiguous because it\n" - "does not fully implement all zipped keys (To be clear: missing {})\n" - "or specifies a subspace that is not fully implemented (To be clear:\n" - ".. we did not find {} from {} in {}:{}).".format( - spec_source, - missing_group_items, - missing_subvalues, - spec, - k, - values[k], - ) + f"variant config in {spec_source} is ambiguous because it does not fully " + f"implement all zipped keys (missing {missing_group_items}) or specifies a " + f"subspace that is not fully implemented (we did not find {missing_subvalues} " + f"from {spec} in {k}:{values[k]})." ) return values diff --git a/tests/bdist-recipe/conda_build_test/__init__.py b/tests/bdist-recipe/conda_build_test/__init__.py index 3574c4128a..1f22b11325 100644 --- a/tests/bdist-recipe/conda_build_test/__init__.py +++ b/tests/bdist-recipe/conda_build_test/__init__.py @@ -3,4 +3,5 @@ """ conda build test package """ + print("conda_build_test has been imported") diff --git a/tests/test_api_build.py b/tests/test_api_build.py index 0d2bd3b5f0..fab08891c2 100644 --- a/tests/test_api_build.py +++ b/tests/test_api_build.py @@ -3,6 +3,7 @@ """ This module tests the build API. These are high-level integration tests. """ + from __future__ import annotations import json @@ -306,9 +307,7 @@ def test_output_build_path_git_source(testing_config): test_path = os.path.join( testing_config.croot, testing_config.host_subdir, - "conda-build-test-source-git-jinja2-1.20.2-py{}{}{}_0_g262d444.tar.bz2".format( - sys.version_info.major, sys.version_info.minor, _hash - ), + f"conda-build-test-source-git-jinja2-1.20.2-py{sys.version_info.major}{sys.version_info.minor}{_hash}_0_g262d444.tar.bz2", ) assert output == test_path @@ -819,15 +818,15 @@ def test_noarch(testing_workdir): def test_disable_pip(testing_metadata): testing_metadata.config.disable_pip = True testing_metadata.meta["requirements"] = {"host": ["python"], "run": ["python"]} - testing_metadata.meta["build"][ - "script" - ] = 'python -c "import pip; print(pip.__version__)"' + testing_metadata.meta["build"]["script"] = ( + 'python -c "import pip; print(pip.__version__)"' + ) with pytest.raises(subprocess.CalledProcessError): api.build(testing_metadata) - testing_metadata.meta["build"][ - "script" - ] = 'python -c "import setuptools; print(setuptools.__version__)"' + testing_metadata.meta["build"]["script"] = ( + 'python -c "import setuptools; print(setuptools.__version__)"' + ) with pytest.raises(subprocess.CalledProcessError): api.build(testing_metadata) diff --git a/tests/test_api_debug.py b/tests/test_api_debug.py index 42fa1275fe..af24d8acfb 100644 --- a/tests/test_api_debug.py +++ b/tests/test_api_debug.py @@ -4,6 +4,7 @@ This module tests the test API. These are high-level integration tests. Lower level unit tests should go in test_render.py """ + from __future__ import annotations import subprocess diff --git a/tests/test_api_render.py b/tests/test_api_render.py index 868053876b..5a4c722836 100644 --- a/tests/test_api_render.py +++ b/tests/test_api_render.py @@ -4,6 +4,7 @@ This module tests the test API. These are high-level integration tests. Lower level unit tests should go in test_render.py """ + import os import re diff --git a/tests/test_api_skeleton_cpan.py b/tests/test_api_skeleton_cpan.py index 238635ba50..9f08ccbae6 100644 --- a/tests/test_api_skeleton_cpan.py +++ b/tests/test_api_skeleton_cpan.py @@ -5,7 +5,6 @@ conda_build.api.skeletonize and check the output files """ - import pytest from conda_build import api diff --git a/tests/test_api_skeleton_cran.py b/tests/test_api_skeleton_cran.py index 9b62b4ac30..912b2bee0c 100644 --- a/tests/test_api_skeleton_cran.py +++ b/tests/test_api_skeleton_cran.py @@ -4,6 +4,7 @@ Integrative tests of the CRAN skeleton that start from conda_build.api.skeletonize and check the output files """ + from pathlib import Path from typing import Sequence diff --git a/tests/test_api_test.py b/tests/test_api_test.py index a258bbba0d..2bb76838aa 100644 --- a/tests/test_api_test.py +++ b/tests/test_api_test.py @@ -3,6 +3,7 @@ """ This module tests the test API. These are high-level integration tests. """ + import os import pytest diff --git a/tests/test_build.py b/tests/test_build.py index f11be7727c..16bffa648f 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -4,6 +4,7 @@ This file tests the build.py module. It sits lower in the stack than the API tests, and is more unit-test oriented. """ + import json import os import sys diff --git a/tests/test_cpan_skeleton.py b/tests/test_cpan_skeleton.py index 2b726f6c88..1b02331f4b 100644 --- a/tests/test_cpan_skeleton.py +++ b/tests/test_cpan_skeleton.py @@ -4,7 +4,6 @@ Unit tests of the CPAN skeleton utility functions """ - from pathlib import Path import pytest diff --git a/tests/test_cran_skeleton.py b/tests/test_cran_skeleton.py index a0f5575114..0db839a8f4 100644 --- a/tests/test_cran_skeleton.py +++ b/tests/test_cran_skeleton.py @@ -3,6 +3,7 @@ """ Unit tests of the CRAN skeleton utility functions """ + import os import pytest diff --git a/tests/test_develop.py b/tests/test_develop.py index add9f65c03..d72bb247d3 100644 --- a/tests/test_develop.py +++ b/tests/test_develop.py @@ -3,6 +3,7 @@ """ Simple tests for testing functions in develop module - lower level than going through API. """ + from pathlib import Path from typing import Generator