Skip to content

Commit

Permalink
Increase line length
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Jun 27, 2024
1 parent 53fd127 commit 6cbe6cd
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 100 deletions.
50 changes: 11 additions & 39 deletions poetry_dynamic_versioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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 []

Expand Down Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 1 addition & 3 deletions poetry_dynamic_versioning/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 4 additions & 12 deletions poetry_dynamic_versioning/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
)
Expand All @@ -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

Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
56 changes: 15 additions & 41 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -158,31 +154,19 @@ 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")


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")


Expand All @@ -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")


Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand All @@ -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")
4 changes: 1 addition & 3 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6cbe6cd

Please sign in to comment.