From 6cbe6cd2b54b55fcc7cc4016310572abdbc092df Mon Sep 17 00:00:00 2001 From: mtkennerly Date: Wed, 26 Jun 2024 23:04:48 -0400 Subject: [PATCH] Increase line length --- poetry_dynamic_versioning/__init__.py | 50 ++++++------------------ poetry_dynamic_versioning/cli.py | 4 +- poetry_dynamic_versioning/plugin.py | 16 ++------ pyproject.toml | 4 +- tests/test_integration.py | 56 +++++++-------------------- tests/test_unit.py | 4 +- 6 files changed, 34 insertions(+), 100 deletions(-) diff --git a/poetry_dynamic_versioning/__init__.py b/poetry_dynamic_versioning/__init__.py index 604a799..5c05cb3 100644 --- a/poetry_dynamic_versioning/__init__.py +++ b/poetry_dynamic_versioning/__init__.py @@ -139,9 +139,7 @@ def __init__( self.version = version self.mode = mode self.dynamic_index = dynamic_index - self.substitutions = ( - {} if substitutions is None else substitutions - ) # type: MutableMapping[Path, str] + self.substitutions = {} if substitutions is None else substitutions # type: MutableMapping[Path, str] class _State: @@ -297,9 +295,7 @@ def initialize(data, key): if isinstance(local, tomlkit.TOMLDocument): local = local.unwrap() - merged = _deep_merge_dicts(_default_config(), local)["tool"][ - "poetry-dynamic-versioning" - ] # type: _Config + merged = _deep_merge_dicts(_default_config(), local)["tool"]["poetry-dynamic-versioning"] # type: _Config # Add default values so we don't have to worry about missing keys for x in merged["files"].values(): @@ -340,9 +336,7 @@ def _validate_config(config: Optional[Mapping] = None) -> Sequence[str]: ) -def _validate_config_section( - config: Mapping, default: Mapping, path: Sequence[str] -) -> Sequence[str]: +def _validate_config_section(config: Mapping, default: Mapping, path: Sequence[str]) -> Sequence[str]: if not default: return [] @@ -370,9 +364,7 @@ def _format_timestamp(value: Optional[dt.datetime]) -> Optional[str]: return value.strftime("%Y%m%d%H%M%S") -def _render_jinja( - version: Version, template: str, config: _Config, extra: Optional[Mapping] = None -) -> str: +def _render_jinja(version: Version, template: str, config: _Config, extra: Optional[Mapping] = None) -> str: if extra is None: extra = {} @@ -417,11 +409,7 @@ def _run_cmd(command: str, codes: Sequence[int] = (0,)) -> Tuple[int, str]: ) output = result.stdout.decode().strip() if codes and result.returncode not in codes: - raise RuntimeError( - "The command '{}' returned code {}. Output:\n{}".format( - command, result.returncode, output - ) - ) + raise RuntimeError("The command '{}' returned code {}. Output:\n{}".format(command, result.returncode, output)) return (result.returncode, output) @@ -496,9 +484,7 @@ def _get_version(config: _Config, name: Optional[str] = None) -> Tuple[str, Vers vcs = Vcs(config["vcs"]) style = Style(config["style"]) if config["style"] is not None else None - pattern = ( - config["pattern"] if config["pattern"] is not None else Pattern.Default - ) # type: Union[str, Pattern] + pattern = config["pattern"] if config["pattern"] is not None else Pattern.Default # type: Union[str, Pattern] if config["fix-shallow-repository"]: # We start without strict so we can inspect the concerns. @@ -553,11 +539,7 @@ def _substitute_version(name: str, version: str, folders: Sequence[_FolderConfig files[resolved] = folder if i == 0: - _debug( - "No files found for substitution with glob '{}' in folder '{}'".format( - file_glob, folder.path - ) - ) + _debug("No files found for substitution with glob '{}' in folder '{}'".format(file_glob, folder.path)) for file, config in files.items(): original_content = file.read_bytes().decode("utf-8") @@ -592,9 +574,7 @@ def _substitute_version_in_text(version: str, content: str, patterns: Sequence[_ else: raise ValueError("Invalid substitution mode: {}".format(pattern.mode)) - new_content = re.sub( - pattern.value, r"\g<1>{}\g<2>".format(insert), new_content, flags=re.MULTILINE - ) + new_content = re.sub(pattern.value, r"\g<1>{}\g<2>".format(insert), new_content, flags=re.MULTILINE) return new_content @@ -667,11 +647,7 @@ def _get_and_apply_version( if pyproject is None: pyproject = tomlkit.parse(pyproject_path.read_bytes().decode("utf-8")) - classic = ( - "tool" in pyproject - and "poetry" in pyproject["tool"] - and "name" in pyproject["tool"]["poetry"] - ) + classic = "tool" in pyproject and "poetry" in pyproject["tool"] and "name" in pyproject["tool"]["poetry"] pep621 = ( "project" in pyproject and "name" in pyproject["project"] @@ -708,16 +684,12 @@ def _get_and_apply_version( if classic and name is not None and original is not None: mode = _Mode.Classic - _state.projects[name] = _ProjectState( - pyproject_path, original, version, mode, dynamic_index - ) + _state.projects[name] = _ProjectState(pyproject_path, original, version, mode, dynamic_index) if io: _apply_version(name, version, instance, config, pyproject_path, mode, retain) elif pep621 and name is not None: mode = _Mode.Pep621 - _state.projects[name] = _ProjectState( - pyproject_path, original, version, mode, dynamic_index - ) + _state.projects[name] = _ProjectState(pyproject_path, original, version, mode, dynamic_index) if io: _apply_version(name, version, instance, config, pyproject_path, mode, retain) diff --git a/poetry_dynamic_versioning/cli.py b/poetry_dynamic_versioning/cli.py index ce99c20..fcb582a 100644 --- a/poetry_dynamic_versioning/cli.py +++ b/poetry_dynamic_versioning/cli.py @@ -108,9 +108,7 @@ def _enable_in_doc(doc: tomlkit.TOMLDocument) -> tomlkit.TOMLDocument: doc[Key.tool][Key.pdv].update(pdv_table) # type: ignore build_system_table = ( - tomlkit.table() - .add(Key.requires, _DEFAULT_REQUIRES) - .add(Key.build_backend, _DEFAULT_BUILD_BACKEND) + tomlkit.table().add(Key.requires, _DEFAULT_REQUIRES).add(Key.build_backend, _DEFAULT_BUILD_BACKEND) ) if doc.get(Key.build_system) is None: diff --git a/poetry_dynamic_versioning/plugin.py b/poetry_dynamic_versioning/plugin.py index a46ad4c..273521b 100644 --- a/poetry_dynamic_versioning/plugin.py +++ b/poetry_dynamic_versioning/plugin.py @@ -110,9 +110,7 @@ def __init__(self, application: Application): def handle(self) -> int: _state.cli_mode = True - _apply_version_via_plugin( - self._application.poetry, retain=True, force=True, standalone=True - ) + _apply_version_via_plugin(self._application.poetry, retain=True, force=True, standalone=True) return 0 @@ -137,9 +135,7 @@ def __init__(self): def activate(self, application: Application) -> None: self._application = application - application.command_loader.register_factory( - cli.Command.dv, lambda: DynamicVersioningCommand(application) - ) + application.command_loader.register_factory(cli.Command.dv, lambda: DynamicVersioningCommand(application)) application.command_loader.register_factory( cli.Command.dv_enable, lambda: DynamicVersioningEnableCommand(application) ) @@ -161,9 +157,7 @@ def activate(self, application: Application) -> None: application.event_dispatcher.add_listener(TERMINATE, self._revert_version) application.event_dispatcher.add_listener(ERROR, self._revert_version) - def _apply_version( - self, event: ConsoleCommandEvent, kind: str, dispatcher: EventDispatcher - ) -> None: + def _apply_version(self, event: ConsoleCommandEvent, kind: str, dispatcher: EventDispatcher) -> None: if not _should_apply(event.command.name): return @@ -172,9 +166,7 @@ def _apply_version( _apply_version_via_plugin(self._application.poetry, io=io) _patch_dependency_versions(io) - def _revert_version( - self, event: ConsoleCommandEvent, kind: str, dispatcher: EventDispatcher - ) -> None: + def _revert_version(self, event: ConsoleCommandEvent, kind: str, dispatcher: EventDispatcher) -> None: if not _should_apply(event.command.name): return diff --git a/pyproject.toml b/pyproject.toml index 48d1476..dedbc70 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,13 +49,13 @@ poetry-dynamic-versioning = 'poetry_dynamic_versioning.__main__:main' poetry-dynamic-versioning = "poetry_dynamic_versioning.plugin:DynamicVersioningPlugin" [tool.black] -line-length = 100 +line-length = 120 [tool.mypy] allow_redefinition = true [tool.ruff] -line-length = 100 +line-length = 120 extend-select = ["W605", "N"] [build-system] diff --git a/tests/test_integration.py b/tests/test_integration.py index bdc0886..1c40df2 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -47,11 +47,7 @@ def run( ) output = result.stdout.decode("utf-8", errors="ignore").strip() if codes and result.returncode not in codes: - raise RuntimeError( - "The command '{}' returned code {}. Output:\n{}".format( - command, result.returncode, output - ) - ) + raise RuntimeError("The command '{}' returned code {}. Output:\n{}".format(command, result.returncode, output)) return (result.returncode, output) @@ -158,15 +154,9 @@ def test_plugin_cli_mode_and_substitution(): run("poetry dynamic-versioning", where=DUMMY) # Changes persist after the command is done: assert f'version = "{DUMMY_VERSION}"' not in DUMMY_PYPROJECT.read_bytes().decode("utf-8") - assert '__version__: str = "0.0.0"' not in ( - DUMMY / "project" / "__init__.py" - ).read_bytes().decode("utf-8") - assert '__version__ = "0.0.0"' not in (DUMMY / "project" / "__init__.py").read_bytes().decode( - "utf-8" - ) - assert "__version_tuple__ = (0, 0, 0)" not in (DUMMY / "project" / "__init__.py").read_text( - "utf8" - ) + assert '__version__: str = "0.0.0"' not in (DUMMY / "project" / "__init__.py").read_bytes().decode("utf-8") + assert '__version__ = "0.0.0"' not in (DUMMY / "project" / "__init__.py").read_bytes().decode("utf-8") + assert "__version_tuple__ = (0, 0, 0)" not in (DUMMY / "project" / "__init__.py").read_text("utf8") assert "<0.0.0>" not in (DUMMY / "project" / "__init__.py").read_bytes().decode("utf-8") @@ -174,15 +164,9 @@ def test_standalone_cli_mode_and_substitution(): run("poetry-dynamic-versioning", where=DUMMY) # Changes persist after the command is done: assert f'version = "{DUMMY_VERSION}"' not in DUMMY_PYPROJECT.read_bytes().decode("utf-8") - assert '__version__: str = "0.0.0"' not in ( - DUMMY / "project" / "__init__.py" - ).read_bytes().decode("utf-8") - assert '__version__ = "0.0.0"' not in (DUMMY / "project" / "__init__.py").read_bytes().decode( - "utf-8" - ) - assert "__version_tuple__ = (0, 0, 0)" not in (DUMMY / "project" / "__init__.py").read_text( - "utf8" - ) + assert '__version__: str = "0.0.0"' not in (DUMMY / "project" / "__init__.py").read_bytes().decode("utf-8") + assert '__version__ = "0.0.0"' not in (DUMMY / "project" / "__init__.py").read_bytes().decode("utf-8") + assert "__version_tuple__ = (0, 0, 0)" not in (DUMMY / "project" / "__init__.py").read_text("utf8") assert "<0.0.0>" not in (DUMMY / "project" / "__init__.py").read_bytes().decode("utf-8") @@ -194,15 +178,9 @@ def test_cli_mode_and_substitution_without_enable(): run("poetry dynamic-versioning", where=DUMMY) # Changes persist after the command is done: assert f'version = "{DUMMY_VERSION}"' not in DUMMY_PYPROJECT.read_bytes().decode("utf-8") - assert '__version__: str = "0.0.0"' not in ( - DUMMY / "project" / "__init__.py" - ).read_bytes().decode("utf-8") - assert '__version__ = "0.0.0"' not in (DUMMY / "project" / "__init__.py").read_bytes().decode( - "utf-8" - ) - assert "__version_tuple__ = (0, 0, 0)" not in (DUMMY / "project" / "__init__.py").read_text( - "utf8" - ) + assert '__version__: str = "0.0.0"' not in (DUMMY / "project" / "__init__.py").read_bytes().decode("utf-8") + assert '__version__ = "0.0.0"' not in (DUMMY / "project" / "__init__.py").read_bytes().decode("utf-8") + assert "__version_tuple__ = (0, 0, 0)" not in (DUMMY / "project" / "__init__.py").read_text("utf8") assert "<0.0.0>" not in (DUMMY / "project" / "__init__.py").read_bytes().decode("utf-8") @@ -286,9 +264,9 @@ def test_pep621_with_dynamic_version(): pyproject = tomlkit.parse(DUMMY_PEP621_PYPROJECT.read_bytes().decode("utf-8")) assert pyproject["project"]["version"] == version assert "version" not in pyproject["project"]["dynamic"] - assert f'__version__ = "{version}"' in ( - DUMMY_PEP621 / "project_pep621" / "__init__.py" - ).read_bytes().decode("utf-8") + assert f'__version__ = "{version}"' in (DUMMY_PEP621 / "project_pep621" / "__init__.py").read_bytes().decode( + "utf-8" + ) @pytest.mark.skipif("USE_PEP621" not in os.environ, reason="Requires Poetry with PEP-621 support") @@ -299,9 +277,7 @@ def test_pep621_with_dynamic_version_and_cleanup(): pyproject = tomlkit.parse(DUMMY_PEP621_PYPROJECT.read_bytes().decode("utf-8")) assert "version" not in pyproject["project"] assert "version" in pyproject["project"]["dynamic"] - assert '__version__ = "0.0.0"' in ( - DUMMY_PEP621 / "project_pep621" / "__init__.py" - ).read_bytes().decode("utf-8") + assert '__version__ = "0.0.0"' in (DUMMY_PEP621 / "project_pep621" / "__init__.py").read_bytes().decode("utf-8") artifact = next(DUMMY_PEP621_DIST.glob("*.whl")) assert f"-{version}-" in artifact.name @@ -316,6 +292,4 @@ def test_pep621_without_dynamic_version(): run("poetry-dynamic-versioning", codes=[1], where=DUMMY_PEP621) pyproject = tomlkit.parse(DUMMY_PEP621_PYPROJECT.read_bytes().decode("utf-8")) assert "version" not in pyproject["project"] - assert '__version__ = "0.0.0"' in ( - DUMMY_PEP621 / "project_pep621" / "__init__.py" - ).read_bytes().decode("utf-8") + assert '__version__ = "0.0.0"' in (DUMMY_PEP621 / "project_pep621" / "__init__.py").read_bytes().decode("utf-8") diff --git a/tests/test_unit.py b/tests/test_unit.py index 301c26a..74fba79 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -26,9 +26,7 @@ def test__deep_merge_dicts(): def test__find_higher_file(): assert plugin._find_higher_file("pyproject.toml", start=root) == root / "pyproject.toml" - assert ( - plugin._find_higher_file("pyproject.toml", start=root / "tests") == root / "pyproject.toml" - ) + assert plugin._find_higher_file("pyproject.toml", start=root / "tests") == root / "pyproject.toml" assert ( plugin._find_higher_file("pyproject.toml", start=root / "tests" / "project") == root / "tests" / "project" / "pyproject.toml"