From 977f88285e9747a0962f7a068b92b356043ff88d Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Sat, 18 Nov 2023 19:34:48 -0500 Subject: [PATCH] Enable Ruff preview (#1045) --- backend/src/hatchling/builders/config.py | 15 +- backend/src/hatchling/dep/core.py | 4 +- backend/src/hatchling/licenses/parse.py | 6 +- backend/src/hatchling/metadata/core.py | 2 +- backend/src/hatchling/version/core.py | 2 +- .../src/hatchling/version/scheme/standard.py | 6 +- backend/tests/downstream/integrate.py | 16 +- release/macos/build_pkg.py | 1 + ruff.toml | 1137 ++++++++--------- scripts/update_distributions.py | 2 +- src/hatch/cli/run/__init__.py | 2 +- src/hatch/cli/terminal.py | 6 +- src/hatch/env/internal/interface.py | 3 +- src/hatch/env/plugin/interface.py | 2 +- src/hatch/utils/ci.py | 2 +- tests/conftest.py | 2 +- .../templates/sdist/standard_include.py | 2 +- .../sdist/standard_include_config_file.py | 2 +- ...tandard_only_packages_artifact_override.py | 2 +- .../helpers/templates/wheel/standard_tests.py | 2 +- 20 files changed, 606 insertions(+), 610 deletions(-) diff --git a/backend/src/hatchling/builders/config.py b/backend/src/hatchling/builders/config.py index e3c03cc36..d052985a3 100644 --- a/backend/src/hatchling/builders/config.py +++ b/backend/src/hatchling/builders/config.py @@ -275,16 +275,19 @@ def hook_config(self) -> dict[str, Any]: hook_config[hook_name] = config - final_hook_config = {} if not env_var_enabled(BuildEnvVars.NO_HOOKS): all_hooks_enabled = env_var_enabled(BuildEnvVars.HOOKS_ENABLE) - for hook_name, config in hook_config.items(): + final_hook_config = { + hook_name: config + for hook_name, config in hook_config.items() if ( all_hooks_enabled or config.get('enable-by-default', True) or env_var_enabled(f'{BuildEnvVars.HOOK_ENABLE_PREFIX}{hook_name.upper()}') - ): - final_hook_config[hook_name] = config + ) + } + else: + final_hook_config = {} self.__hook_config = final_hook_config @@ -693,7 +696,7 @@ def sources(self) -> dict[str, str]: raise TypeError(message) for relative_path in self.packages: - source, package = os.path.split(relative_path) + source, _package = os.path.split(relative_path) if source and normalize_relative_directory(relative_path) not in sources: sources[normalize_relative_directory(source)] = '' @@ -911,7 +914,7 @@ def set_build_data(self, build_data: dict[str, Any]) -> Generator: def env_var_enabled(env_var: str, *, default: bool = False) -> bool: if env_var in os.environ: - return os.environ[env_var] in ('1', 'true') + return os.environ[env_var] in {'1', 'true'} return default diff --git a/backend/src/hatchling/dep/core.py b/backend/src/hatchling/dep/core.py index 0eef5e31c..b54f41e48 100644 --- a/backend/src/hatchling/dep/core.py +++ b/backend/src/hatchling/dep/core.py @@ -91,7 +91,7 @@ def dependency_in_sync( vcs_info = direct_url_data['vcs_info'] vcs = vcs_info['vcs'] commit_id = vcs_info['commit_id'] - requested_revision = vcs_info['requested_revision'] if 'requested_revision' in vcs_info else None + requested_revision = vcs_info.get('requested_revision') # Try a few variations, see https://peps.python.org/pep-0440/#direct-references if ( @@ -99,7 +99,7 @@ def dependency_in_sync( ) or requirement.url == f'{vcs}+{url}@{commit_id}': return True - if requirement.url in (f'{vcs}+{url}', f'{vcs}+{url}@{requested_revision}'): + if requirement.url in {f'{vcs}+{url}', f'{vcs}+{url}@{requested_revision}'}: import subprocess if vcs == 'git': diff --git a/backend/src/hatchling/licenses/parse.py b/backend/src/hatchling/licenses/parse.py index 4698b0aad..29be5a458 100644 --- a/backend/src/hatchling/licenses/parse.py +++ b/backend/src/hatchling/licenses/parse.py @@ -39,11 +39,11 @@ def normalize_license_expression(raw_license_expression: str) -> str: # expression should evaluate as such. python_tokens = [] for token in tokens: - if token not in ('or', 'and', 'with', '(', ')'): + if token not in {'or', 'and', 'with', '(', ')'}: python_tokens.append('False') elif token == 'with': # noqa: S105 python_tokens.append('or') - elif token == '(' and python_tokens and python_tokens[-1] not in ('or', 'and'): # noqa: S105 + elif token == '(' and python_tokens and python_tokens[-1] not in {'or', 'and'}: # noqa: S105 message = f'invalid license expression: {raw_license_expression}' raise ValueError(message) else: @@ -62,7 +62,7 @@ def normalize_license_expression(raw_license_expression: str) -> str: # Take a final pass to check for unknown licenses/exceptions normalized_tokens = [] for token in tokens: - if token in ('or', 'and', 'with', '(', ')'): + if token in {'or', 'and', 'with', '(', ')'}: normalized_tokens.append(token.upper()) continue diff --git a/backend/src/hatchling/metadata/core.py b/backend/src/hatchling/metadata/core.py index d7bed8c4c..50dd61184 100644 --- a/backend/src/hatchling/metadata/core.py +++ b/backend/src/hatchling/metadata/core.py @@ -523,7 +523,7 @@ def readme(self) -> str: message = 'Field `content-type` in the `project.readme` table must be a string' raise TypeError(message) - if content_type not in ('text/markdown', 'text/x-rst', 'text/plain'): + if content_type not in {'text/markdown', 'text/x-rst', 'text/plain'}: message = ( 'Field `content-type` in the `project.readme` table must be one of the following: ' 'text/markdown, text/x-rst, text/plain' diff --git a/backend/src/hatchling/version/core.py b/backend/src/hatchling/version/core.py index fbb3209f1..6e8bac3a3 100644 --- a/backend/src/hatchling/version/core.py +++ b/backend/src/hatchling/version/core.py @@ -43,7 +43,7 @@ def read(self, pattern: str | bool) -> str: return self.__cached_read_data[0] def set_version(self, version: str) -> None: - old_version, file_contents, (start, end) = self.__cached_read_data # type: ignore + _old_version, file_contents, (start, end) = self.__cached_read_data # type: ignore with open(self.__path, 'w', encoding='utf-8') as f: f.write(f'{file_contents[:start]}{version}{file_contents[end:]}') diff --git a/backend/src/hatchling/version/scheme/standard.py b/backend/src/hatchling/version/scheme/standard.py index 984b4152d..d7fb03592 100644 --- a/backend/src/hatchling/version/scheme/standard.py +++ b/backend/src/hatchling/version/scheme/standard.py @@ -33,11 +33,11 @@ def update( reset_version_parts(original, release=update_release(original, [original.major + 1])) elif version == 'minor': reset_version_parts(original, release=update_release(original, [original.major, original.minor + 1])) - elif version in ('micro', 'patch', 'fix'): + elif version in {'micro', 'patch', 'fix'}: reset_version_parts( original, release=update_release(original, [original.major, original.minor, original.micro + 1]) ) - elif version in ('a', 'b', 'c', 'rc', 'alpha', 'beta', 'pre', 'preview'): + elif version in {'a', 'b', 'c', 'rc', 'alpha', 'beta', 'pre', 'preview'}: phase, number = parse_letter_version(version, 0) if original.pre: current_phase, current_number = parse_letter_version(*original.pre) @@ -45,7 +45,7 @@ def update( number = current_number + 1 reset_version_parts(original, pre=(phase, number)) - elif version in ('post', 'rev', 'r'): + elif version in {'post', 'rev', 'r'}: number = 0 if original.post is None else original.post + 1 reset_version_parts(original, post=parse_letter_version(version, number)) elif version == 'dev': diff --git a/backend/tests/downstream/integrate.py b/backend/tests/downstream/integrate.py index 544e64a94..7d8803e5f 100644 --- a/backend/tests/downstream/integrate.py +++ b/backend/tests/downstream/integrate.py @@ -22,11 +22,11 @@ def handle_remove_readonly(func, path, exc): # no cov # PermissionError: [WinError 5] Access is denied: '...\\.git\\...' - if func in (os.rmdir, os.remove, os.unlink) and exc[1].errno == errno.EACCES: + if func in {os.rmdir, os.remove, os.unlink} and exc[1].errno == errno.EACCES: os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) func(path) else: - raise + raise exc class EnvVars(dict): @@ -114,7 +114,7 @@ def main(): # Increment the minor version version_file = os.path.join(backend_path, 'src', 'hatchling', '__about__.py') - with open(version_file) as f: + with open(version_file, encoding='utf-8') as f: lines = f.readlines() for i, line in enumerate(lines): @@ -128,7 +128,7 @@ def main(): message = 'No version found' raise ValueError(message) - with open(version_file, 'w') as f: + with open(version_file, 'w', encoding='utf-8') as f: f.writelines(lines) print('<<<<< Building backend >>>>>') @@ -150,7 +150,7 @@ def main(): constraints = [] constraints_file = os.path.join(build_dir, 'constraints.txt') - with open(constraints_file, 'w') as f: + with open(constraints_file, 'w', encoding='utf-8') as f: f.write('\n'.join(constraints)) for project in os.listdir(HERE): @@ -164,14 +164,14 @@ def main(): # Not yet ported if os.path.isfile(potential_project_file): - with open(potential_project_file) as f: + with open(potential_project_file, encoding='utf-8') as f: project_config.update(tomli.loads(f.read())) if not python_version_supported(project_config): print('--> Unsupported version of Python, skipping') continue - with open(os.path.join(project_dir, 'data.json')) as f: + with open(os.path.join(project_dir, 'data.json'), encoding='utf-8') as f: test_data = json.loads(f.read()) with temp_dir() as d: @@ -199,7 +199,7 @@ def main(): if not os.path.isfile(project_file): sys.exit('--> Missing file: pyproject.toml') - with open(project_file) as f: + with open(project_file, encoding='utf-8') as f: project_config.update(tomli.loads(f.read())) for requirement in project_config.get('build-system', {}).get('requires', []): diff --git a/release/macos/build_pkg.py b/release/macos/build_pkg.py index 2a4f8b4e8..836ab40d6 100644 --- a/release/macos/build_pkg.py +++ b/release/macos/build_pkg.py @@ -4,6 +4,7 @@ At a high level, the goal is to have a directory that emulates the full path structure of the target machine which then gets packaged by tools that are only available on macOS. """ + from __future__ import annotations import argparse diff --git a/ruff.toml b/ruff.toml index 00c457b0f..1fe5fea17 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,571 +1,569 @@ line-length = 120 + +[lint] +preview = true select = [ - 'A001', - 'A002', - 'A003', - 'ARG001', - 'ARG002', - 'ARG003', - 'ARG004', - 'ARG005', - 'ASYNC100', - 'ASYNC101', - 'ASYNC102', - 'B002', - 'B003', - 'B004', - 'B005', - 'B006', - 'B007', - 'B008', - 'B009', - 'B010', - 'B011', - 'B012', - 'B013', - 'B014', - 'B015', - 'B016', - 'B017', - 'B018', - 'B019', - 'B020', - 'B021', - 'B022', - 'B023', - 'B024', - 'B025', - 'B026', - 'B028', - 'B029', - 'B030', - 'B031', - 'B032', - 'B033', - 'B034', - 'B904', - 'B905', - 'BLE001', - 'C400', - 'C401', - 'C402', - 'C403', - 'C404', - 'C405', - 'C406', - 'C408', - 'C409', - 'C410', - 'C411', - 'C413', - 'C414', - 'C415', - 'C416', - 'C417', - 'C418', - 'C419', - 'COM818', - 'DTZ001', - 'DTZ002', - 'DTZ003', - 'DTZ004', - 'DTZ005', - 'DTZ006', - 'DTZ007', - 'DTZ011', - 'DTZ012', - 'E101', - 'E112', - 'E113', - 'E115', - 'E116', - 'E201', - 'E202', - 'E211', - 'E221', - 'E222', - 'E223', - 'E224', - 'E225', - 'E226', - 'E227', - 'E228', - 'E231', - 'E241', - 'E242', - 'E251', - 'E252', - 'E261', - 'E262', - 'E265', - 'E266', - 'E271', - 'E272', - 'E273', - 'E274', - 'E275', - 'E401', - 'E402', - 'E501', - 'E701', - 'E702', - 'E703', - 'E711', - 'E712', - 'E713', - 'E714', - 'E721', - 'E722', - 'E731', - 'E741', - 'E742', - 'E743', - 'E902', - 'E999', - 'EM101', - 'EM102', - 'EM103', - 'EXE001', - 'EXE002', - 'EXE003', - 'EXE004', - 'EXE005', - 'F401', - 'F402', - 'F403', - 'F404', - 'F405', - 'F406', - 'F407', - 'F501', - 'F502', - 'F503', - 'F504', - 'F505', - 'F506', - 'F507', - 'F508', - 'F509', - 'F521', - 'F522', - 'F523', - 'F524', - 'F525', - 'F541', - 'F601', - 'F602', - 'F621', - 'F622', - 'F631', - 'F632', - 'F633', - 'F634', - 'F701', - 'F702', - 'F704', - 'F706', - 'F707', - 'F722', - 'F811', - 'F821', - 'F822', - 'F823', - 'F841', - 'F842', - 'F901', - 'FA100', - 'FA102', - 'FBT001', - 'FBT002', - 'FLY002', - 'FURB101', - 'FURB105', - 'FURB113', - 'FURB131', - 'FURB132', - 'FURB145', - 'FURB148', - 'FURB168', - 'FURB171', - 'FURB177', - 'G001', - 'G002', - 'G003', - 'G004', - 'G010', - 'G101', - 'G201', - 'G202', - 'I001', - 'I002', - 'ICN001', - 'ICN002', - 'ICN003', - 'INP001', - 'INT001', - 'INT002', - 'INT003', - 'ISC003', - 'LOG001', - 'LOG002', - 'LOG007', - 'LOG009', - 'N801', - 'N802', - 'N803', - 'N804', - 'N805', - 'N806', - 'N807', - 'N811', - 'N812', - 'N813', - 'N814', - 'N815', - 'N816', - 'N817', - 'N818', - 'N999', - 'PERF101', - 'PERF102', - 'PERF401', - 'PERF402', - 'PERF403', - 'PGH001', - 'PGH002', - 'PGH005', - 'PIE790', - 'PIE794', - 'PIE796', - 'PIE800', - 'PIE804', - 'PIE807', - 'PIE808', - 'PIE810', - 'PLC0105', - 'PLC0131', - 'PLC0132', - 'PLC0205', - 'PLC0208', - 'PLC0414', - 'PLC0415', - 'PLC1901', - 'PLC2401', - 'PLC2403', - 'PLC3002', - 'PLE0100', - 'PLE0101', - 'PLE0116', - 'PLE0117', - 'PLE0118', - 'PLE0241', - 'PLE0302', - 'PLE0307', - 'PLE0604', - 'PLE0605', - 'PLE0704', - 'PLE1205', - 'PLE1206', - 'PLE1300', - 'PLE1307', - 'PLE1310', - 'PLE1507', - 'PLE1700', - 'PLE2502', - 'PLE2510', - 'PLE2512', - 'PLE2513', - 'PLE2514', - 'PLE2515', - 'PLR0124', - 'PLR0133', - 'PLR0206', - 'PLR0402', - 'PLR0904', - 'PLR0916', - 'PLR1701', - 'PLR1706', - 'PLR1711', - 'PLR1714', - 'PLR1722', - 'PLR2004', - 'PLR5501', - 'PLR6201', - 'PLR6301', - 'PLW0108', - 'PLW0120', - 'PLW0127', - 'PLW0129', - 'PLW0131', - 'PLW0406', - 'PLW0602', - 'PLW0603', - 'PLW0604', - 'PLW0711', - 'PLW1501', - 'PLW1508', - 'PLW1509', - 'PLW1510', - 'PLW1514', - 'PLW1641', - 'PLW2101', - 'PLW2901', - 'PLW3201', - 'PLW3301', - 'PT001', - 'PT002', - 'PT003', - 'PT004', - 'PT005', - 'PT006', - 'PT007', - 'PT008', - 'PT009', - 'PT010', - 'PT011', - 'PT012', - 'PT013', - 'PT014', - 'PT015', - 'PT016', - 'PT017', - 'PT018', - 'PT019', - 'PT020', - 'PT021', - 'PT022', - 'PT023', - 'PT024', - 'PT025', - 'PT026', - 'PT027', - 'PYI001', - 'PYI002', - 'PYI003', - 'PYI004', - 'PYI005', - 'PYI006', - 'PYI007', - 'PYI008', - 'PYI009', - 'PYI010', - 'PYI011', - 'PYI012', - 'PYI013', - 'PYI014', - 'PYI015', - 'PYI016', - 'PYI017', - 'PYI018', - 'PYI019', - 'PYI020', - 'PYI021', - 'PYI024', - 'PYI025', - 'PYI026', - 'PYI029', - 'PYI030', - 'PYI032', - 'PYI033', - 'PYI034', - 'PYI035', - 'PYI036', - 'PYI041', - 'PYI042', - 'PYI043', - 'PYI044', - 'PYI045', - 'PYI046', - 'PYI047', - 'PYI048', - 'PYI049', - 'PYI050', - 'PYI051', - 'PYI052', - 'PYI053', - 'PYI054', - 'PYI055', - 'PYI056', - 'RET503', - 'RET504', - 'RET505', - 'RET506', - 'RET507', - 'RET508', - 'RSE102', - 'RUF001', - 'RUF002', - 'RUF003', - 'RUF005', - 'RUF006', - 'RUF007', - 'RUF008', - 'RUF009', - 'RUF010', - 'RUF011', - 'RUF012', - 'RUF013', - 'RUF015', - 'RUF016', - 'RUF017', - 'RUF018', - 'RUF019', - 'RUF100', - 'RUF200', - 'S101', - 'S102', - 'S103', - 'S104', - 'S105', - 'S106', - 'S107', - 'S108', - 'S110', - 'S112', - 'S113', - 'S201', - 'S301', - 'S302', - 'S303', - 'S304', - 'S305', - 'S306', - 'S307', - 'S308', - 'S310', - 'S311', - 'S312', - 'S313', - 'S314', - 'S315', - 'S316', - 'S317', - 'S318', - 'S319', - 'S320', - 'S321', - 'S323', - 'S324', - 'S501', - 'S505', - 'S506', - 'S507', - 'S508', - 'S509', - 'S601', - 'S602', - 'S604', - 'S605', - 'S606', - 'S607', - 'S608', - 'S609', - 'S612', - 'S701', - 'SIM101', - 'SIM102', - 'SIM103', - 'SIM105', - 'SIM107', - 'SIM108', - 'SIM109', - 'SIM110', - 'SIM112', - 'SIM114', - 'SIM115', - 'SIM116', - 'SIM117', - 'SIM118', - 'SIM201', - 'SIM202', - 'SIM208', - 'SIM210', - 'SIM211', - 'SIM212', - 'SIM220', - 'SIM221', - 'SIM222', - 'SIM223', - 'SIM300', - 'SIM401', - 'SIM910', - 'SLF001', - 'SLOT000', - 'SLOT001', - 'SLOT002', - 'T100', - 'T201', - 'T203', - 'TCH001', - 'TCH002', - 'TCH003', - 'TCH004', - 'TCH005', - 'TRIO100', - 'TRY002', - 'TRY003', - 'TRY004', - 'TRY200', - 'TRY201', - 'TRY300', - 'TRY301', - 'TRY302', - 'TRY400', - 'TRY401', - 'UP001', - 'UP003', - 'UP004', - 'UP005', - 'UP006', - 'UP007', - 'UP008', - 'UP009', - 'UP010', - 'UP011', - 'UP012', - 'UP013', - 'UP014', - 'UP015', - 'UP017', - 'UP018', - 'UP019', - 'UP020', - 'UP021', - 'UP022', - 'UP023', - 'UP024', - 'UP025', - 'UP026', - 'UP027', - 'UP028', - 'UP029', - 'UP030', - 'UP031', - 'UP032', - 'UP033', - 'UP034', - 'UP035', - 'UP036', - 'UP037', - 'UP038', - 'UP039', - 'UP040', - 'UP041', - 'W291', - 'W292', - 'W293', - 'W505', - 'W605', - 'YTT101', - 'YTT102', - 'YTT103', - 'YTT201', - 'YTT202', - 'YTT203', - 'YTT204', - 'YTT301', - 'YTT302', - 'YTT303', + "A001", + "A002", + "A003", + "ARG001", + "ARG002", + "ARG003", + "ARG004", + "ARG005", + "ASYNC100", + "ASYNC101", + "ASYNC102", + "B002", + "B003", + "B004", + "B005", + "B006", + "B007", + "B008", + "B009", + "B010", + "B011", + "B012", + "B013", + "B014", + "B015", + "B016", + "B017", + "B018", + "B019", + "B020", + "B021", + "B022", + "B023", + "B024", + "B025", + "B026", + "B028", + "B029", + "B030", + "B031", + "B032", + "B033", + "B034", + "B904", + "B905", + "BLE001", + "C400", + "C401", + "C402", + "C403", + "C404", + "C405", + "C406", + "C408", + "C409", + "C410", + "C411", + "C413", + "C414", + "C415", + "C416", + "C417", + "C418", + "C419", + "COM818", + "DTZ001", + "DTZ002", + "DTZ003", + "DTZ004", + "DTZ005", + "DTZ006", + "DTZ007", + "DTZ011", + "DTZ012", + "E101", + "E112", + "E113", + "E115", + "E116", + "E201", + "E202", + "E211", + "E221", + "E222", + "E223", + "E224", + "E225", + "E226", + "E227", + "E228", + "E231", + "E241", + "E242", + "E251", + "E252", + "E261", + "E262", + "E265", + "E266", + "E271", + "E272", + "E273", + "E274", + "E275", + "E401", + "E402", + "E501", + "E701", + "E702", + "E703", + "E711", + "E712", + "E713", + "E714", + "E721", + "E722", + "E731", + "E741", + "E742", + "E743", + "E902", + "E999", + "EM101", + "EM102", + "EM103", + "EXE001", + "EXE002", + "EXE003", + "EXE004", + "EXE005", + "F401", + "F402", + "F403", + "F404", + "F405", + "F406", + "F407", + "F501", + "F502", + "F503", + "F504", + "F505", + "F506", + "F507", + "F508", + "F509", + "F521", + "F522", + "F523", + "F524", + "F525", + "F541", + "F601", + "F602", + "F621", + "F622", + "F631", + "F632", + "F633", + "F634", + "F701", + "F702", + "F704", + "F706", + "F707", + "F722", + "F811", + "F821", + "F822", + "F823", + "F841", + "F842", + "F901", + "FA100", + "FA102", + "FBT001", + "FBT002", + "FLY002", + "FURB105", + "FURB113", + "FURB131", + "FURB132", + "FURB145", + "FURB148", + "FURB168", + "FURB171", + "FURB177", + "G001", + "G002", + "G003", + "G004", + "G010", + "G101", + "G201", + "G202", + "I001", + "I002", + "ICN001", + "ICN002", + "ICN003", + "INP001", + "INT001", + "INT002", + "INT003", + "ISC003", + "LOG001", + "LOG002", + "LOG007", + "LOG009", + "N801", + "N802", + "N803", + "N804", + "N805", + "N806", + "N807", + "N811", + "N812", + "N813", + "N814", + "N815", + "N816", + "N817", + "N818", + "N999", + "PERF101", + "PERF102", + "PERF401", + "PERF402", + "PERF403", + "PGH001", + "PGH002", + "PGH005", + "PIE790", + "PIE794", + "PIE796", + "PIE800", + "PIE804", + "PIE807", + "PIE808", + "PIE810", + "PLC0105", + "PLC0131", + "PLC0132", + "PLC0205", + "PLC0208", + "PLC0414", + "PLC1901", + "PLC2401", + "PLC2403", + "PLC3002", + "PLE0100", + "PLE0101", + "PLE0116", + "PLE0117", + "PLE0118", + "PLE0241", + "PLE0302", + "PLE0307", + "PLE0604", + "PLE0605", + "PLE0704", + "PLE1205", + "PLE1206", + "PLE1300", + "PLE1307", + "PLE1310", + "PLE1507", + "PLE1700", + "PLE2502", + "PLE2510", + "PLE2512", + "PLE2513", + "PLE2514", + "PLE2515", + "PLR0124", + "PLR0133", + "PLR0206", + "PLR0402", + "PLR1701", + "PLR1706", + "PLR1711", + "PLR1714", + "PLR1722", + "PLR2004", + "PLR5501", + "PLR6201", + "PLR6301", + "PLW0108", + "PLW0120", + "PLW0127", + "PLW0129", + "PLW0131", + "PLW0406", + "PLW0602", + "PLW0603", + "PLW0604", + "PLW0711", + "PLW1501", + "PLW1508", + "PLW1509", + "PLW1510", + "PLW1514", + "PLW1641", + "PLW2101", + "PLW2901", + "PLW3201", + "PLW3301", + "PT001", + "PT002", + "PT003", + "PT004", + "PT005", + "PT006", + "PT007", + "PT008", + "PT009", + "PT010", + "PT011", + "PT012", + "PT013", + "PT014", + "PT015", + "PT016", + "PT017", + "PT018", + "PT019", + "PT020", + "PT021", + "PT022", + "PT023", + "PT024", + "PT025", + "PT026", + "PT027", + "PYI001", + "PYI002", + "PYI003", + "PYI004", + "PYI005", + "PYI006", + "PYI007", + "PYI008", + "PYI009", + "PYI010", + "PYI011", + "PYI012", + "PYI013", + "PYI014", + "PYI015", + "PYI016", + "PYI017", + "PYI018", + "PYI019", + "PYI020", + "PYI021", + "PYI024", + "PYI025", + "PYI026", + "PYI029", + "PYI030", + "PYI032", + "PYI033", + "PYI034", + "PYI035", + "PYI036", + "PYI041", + "PYI042", + "PYI043", + "PYI044", + "PYI045", + "PYI046", + "PYI047", + "PYI048", + "PYI049", + "PYI050", + "PYI051", + "PYI052", + "PYI053", + "PYI054", + "PYI055", + "PYI056", + "RET503", + "RET504", + "RET505", + "RET506", + "RET507", + "RET508", + "RSE102", + "RUF001", + "RUF002", + "RUF003", + "RUF005", + "RUF006", + "RUF007", + "RUF008", + "RUF009", + "RUF010", + "RUF011", + "RUF012", + "RUF013", + "RUF015", + "RUF016", + "RUF017", + "RUF018", + "RUF019", + "RUF100", + "RUF200", + "S101", + "S102", + "S103", + "S104", + "S105", + "S106", + "S107", + "S108", + "S110", + "S112", + "S113", + "S201", + "S301", + "S302", + "S303", + "S304", + "S305", + "S306", + "S307", + "S308", + "S310", + "S311", + "S312", + "S313", + "S314", + "S315", + "S316", + "S317", + "S318", + "S319", + "S320", + "S321", + "S323", + "S324", + "S501", + "S505", + "S506", + "S507", + "S508", + "S509", + "S601", + "S602", + "S604", + "S605", + "S606", + "S607", + "S608", + "S609", + "S612", + "S701", + "SIM101", + "SIM102", + "SIM103", + "SIM105", + "SIM107", + "SIM108", + "SIM109", + "SIM110", + "SIM112", + "SIM114", + "SIM115", + "SIM116", + "SIM117", + "SIM118", + "SIM201", + "SIM202", + "SIM208", + "SIM210", + "SIM211", + "SIM212", + "SIM220", + "SIM221", + "SIM222", + "SIM223", + "SIM300", + "SIM910", + "SLF001", + "SLOT000", + "SLOT001", + "SLOT002", + "T100", + "T201", + "T203", + "TCH001", + "TCH002", + "TCH003", + "TCH004", + "TCH005", + "TRIO100", + "TRY002", + "TRY003", + "TRY004", + "TRY200", + "TRY201", + "TRY300", + "TRY301", + "TRY302", + "TRY400", + "TRY401", + "UP001", + "UP003", + "UP004", + "UP005", + "UP006", + "UP007", + "UP008", + "UP009", + "UP010", + "UP011", + "UP012", + "UP013", + "UP014", + "UP015", + "UP017", + "UP018", + "UP019", + "UP020", + "UP021", + "UP022", + "UP023", + "UP024", + "UP025", + "UP026", + "UP027", + "UP028", + "UP029", + "UP030", + "UP031", + "UP032", + "UP033", + "UP034", + "UP035", + "UP036", + "UP037", + "UP038", + "UP039", + "UP040", + "UP041", + "W291", + "W292", + "W293", + "W505", + "W605", + "YTT101", + "YTT102", + "YTT103", + "YTT201", + "YTT202", + "YTT203", + "YTT204", + "YTT301", + "YTT302", + "YTT303", ] [isort] @@ -578,16 +576,13 @@ inline-quotes = "single" ban-relative-imports = "all" [per-file-ignores] -# Allow print/pprint "backend/src/hatchling/bridge/app.py" = ["T201"] "backend/tests/downstream/integrate.py" = ["INP001", "T201"] "docs/.hooks/*" = ["INP001", "T201"] "release/macos/build_pkg.py" = ["INP001"] -"scripts/*" = ["INP001", "T201"] "**/scripts/*" = ["INP001", "T201"] -# Tests can use empty string comparisons, magic values, assertions, and relative imports -"tests/**/*" = ["PLC1901", "PLR2004", "PLR6301", "S", "TID252"] -"backend/tests/**/*" = ["S"] +"**/tests/**/*" = ["PLC1901", "PLR2004", "PLR6301", "S", "TID252"] [format] +preview = true quote-style = "single" diff --git a/scripts/update_distributions.py b/scripts/update_distributions.py index 3963258ff..0767d16c0 100644 --- a/scripts/update_distributions.py +++ b/scripts/update_distributions.py @@ -74,7 +74,7 @@ def main(): output.extend(('}', '')) output = '\n'.join(output) - with open(OUTPUT_FILE, 'w') as f: + with open(OUTPUT_FILE, 'w', encoding='utf-8') as f: f.write(output) diff --git a/src/hatch/cli/run/__init__.py b/src/hatch/cli/run/__init__.py index fc539655d..076683f04 100644 --- a/src/hatch/cli/run/__init__.py +++ b/src/hatch/cli/run/__init__.py @@ -45,7 +45,7 @@ def run(ctx, app, args): would execute `pytest` in the environments `test.py3.10-42` and `test.py3.10-3.14`. Note that `py` may be used as an alias for `python`. """ - if args[0] in ('-h', '--help'): + if args[0] in {'-h', '--help'}: app.display_info(ctx.get_help()) return diff --git a/src/hatch/cli/terminal.py b/src/hatch/cli/terminal.py index e6bf95673..66cfb0add 100644 --- a/src/hatch/cli/terminal.py +++ b/src/hatch/cli/terminal.py @@ -18,15 +18,13 @@ class TerminalStatus(ABC): @abstractmethod - def stop(self) -> None: - ... + def stop(self) -> None: ... def __enter__(self) -> TerminalStatus: # noqa: PYI034 return self @abstractmethod - def __exit__(self, exc_type, exc_val, exc_tb): - ... + def __exit__(self, exc_type, exc_val, exc_tb): ... class NullStatus(TerminalStatus): diff --git a/src/hatch/env/internal/interface.py b/src/hatch/env/internal/interface.py index 6379aac64..53b4a432f 100644 --- a/src/hatch/env/internal/interface.py +++ b/src/hatch/env/internal/interface.py @@ -15,5 +15,4 @@ def config(self) -> dict: return config @abstractmethod - def get_base_config(self) -> dict: - ... + def get_base_config(self) -> dict: ... diff --git a/src/hatch/env/plugin/interface.py b/src/hatch/env/plugin/interface.py index d0d8f39e0..344ba6aa8 100644 --- a/src/hatch/env/plugin/interface.py +++ b/src/hatch/env/plugin/interface.py @@ -760,7 +760,7 @@ def resolve_commands(self, commands: list[str]): yield from self.expand_command(command) def expand_command(self, command): - possible_script, args, ignore_exit_code = parse_script_command(command) + possible_script, args, _ignore_exit_code = parse_script_command(command) # Indicate undefined if not args: diff --git a/src/hatch/utils/ci.py b/src/hatch/utils/ci.py index 7080f070a..b58ae900b 100644 --- a/src/hatch/utils/ci.py +++ b/src/hatch/utils/ci.py @@ -2,4 +2,4 @@ def running_in_ci() -> bool: - return any(os.environ.get(env_var) in ('true', '1') for env_var in ('CI', 'GITHUB_ACTIONS')) + return any(os.environ.get(env_var) in {'true', '1'} for env_var in ('CI', 'GITHUB_ACTIONS')) diff --git a/tests/conftest.py b/tests/conftest.py index b17db4179..f8fc6a208 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -235,7 +235,7 @@ def devpi(tmp_path_factory, worker_id): server_key = str(server_config_dir / 'server.key') server_cert = str(server_config_dir / 'server.pem') cert.private_key_pem.write_to_path(path=server_key) - with open(server_cert, mode='w') as f: + with open(server_cert, mode='w', encoding='utf-8') as f: f.truncate() for blob in cert.cert_chain_pems: blob.write_to_path(path=server_cert, append=True) diff --git a/tests/helpers/templates/sdist/standard_include.py b/tests/helpers/templates/sdist/standard_include.py index 8bb9fa6dc..c26f679e3 100644 --- a/tests/helpers/templates/sdist/standard_include.py +++ b/tests/helpers/templates/sdist/standard_include.py @@ -11,7 +11,7 @@ def get_files(**kwargs): files = [] for f in get_template_files(**kwargs): part = f.path.parts[0] - if part in ('my_app', 'pyproject.toml', 'README.md', 'LICENSE.txt'): + if part in {'my_app', 'pyproject.toml', 'README.md', 'LICENSE.txt'}: files.append(File(Path(relative_root, f.path), f.contents)) files.append( diff --git a/tests/helpers/templates/sdist/standard_include_config_file.py b/tests/helpers/templates/sdist/standard_include_config_file.py index 2143fea2c..03940d5dc 100644 --- a/tests/helpers/templates/sdist/standard_include_config_file.py +++ b/tests/helpers/templates/sdist/standard_include_config_file.py @@ -11,7 +11,7 @@ def get_files(**kwargs): files = [] for f in get_template_files(**kwargs): part = f.path.parts[0] - if part in ('my_app', 'pyproject.toml', 'README.md', 'LICENSE.txt'): + if part in {'my_app', 'pyproject.toml', 'README.md', 'LICENSE.txt'}: files.append(File(Path(relative_root, f.path), f.contents)) files.extend( diff --git a/tests/helpers/templates/wheel/standard_only_packages_artifact_override.py b/tests/helpers/templates/wheel/standard_only_packages_artifact_override.py index 50ea893c7..5633d2d3b 100644 --- a/tests/helpers/templates/wheel/standard_only_packages_artifact_override.py +++ b/tests/helpers/templates/wheel/standard_only_packages_artifact_override.py @@ -15,7 +15,7 @@ def get_files(**kwargs): if str(f.path) == 'LICENSE.txt': files.append(File(Path(metadata_directory, 'licenses', f.path), f.contents)) - if f.path.parts[0] not in (kwargs['package_name'], 'tests'): + if f.path.parts[0] not in {kwargs['package_name'], 'tests'}: continue if f.path == Path('tests', '__init__.py'): diff --git a/tests/helpers/templates/wheel/standard_tests.py b/tests/helpers/templates/wheel/standard_tests.py index ea015e4a0..ceb630ee6 100644 --- a/tests/helpers/templates/wheel/standard_tests.py +++ b/tests/helpers/templates/wheel/standard_tests.py @@ -15,7 +15,7 @@ def get_files(**kwargs): if str(f.path) == 'LICENSE.txt': files.append(File(Path(metadata_directory, 'licenses', f.path), f.contents)) - if f.path.parts[0] not in (kwargs['package_name'], 'tests'): + if f.path.parts[0] not in {kwargs['package_name'], 'tests'}: continue files.append(f)