Skip to content
This repository has been archived by the owner on Oct 12, 2024. It is now read-only.

Commit

Permalink
refactor: ♻️ Apply rebase from main
Browse files Browse the repository at this point in the history
  • Loading branch information
Anselmoo committed Jul 11, 2023
1 parent dbd4170 commit f137d84
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions poetry_version_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,26 @@ def activate(self, poetry: Poetry, io: IO) -> None:
)
tree = ast.parse(init_path.read_text())
for el in tree.body:
if isinstance(el, ast.Assign):
if len(el.targets) == 1:
target = el.targets[0]
if isinstance(target, ast.Name):
if target.id == "__version__":
value_node = el.value
if isinstance(value_node, ast.Constant):
version = value_node.value
elif isinstance(value_node, ast.Str):
version = value_node.s
else: # pragma: nocover
# This is actually covered by tests, but can't be
# reported by Coverage
# Ref: https://github.com/nedbat/coveragepy/issues/198
continue
io.write_line(
"<b>poetry-version-plugin</b>: Setting package "
"dynamic version to __version__ "
f"variable from __init__.py: <b>{version}</b>"
)
poetry.package._set_version(version)
return
if isinstance(el, ast.Assign) and len(el.targets) == 1:
target = el.targets[0]
if isinstance(target, ast.Name) and target.id == "__version__":
value_node = el.value
if isinstance(value_node, ast.Constant):
version = value_node.value
elif isinstance(value_node, ast.Str):
version = value_node.s
else: # pragma: nocover
# This is actually covered by tests, but can't be
# reported by Coverage
# Ref: https://github.com/nedbat/coveragepy/issues/198
continue
io.write_line(
"<b>poetry-version-plugin</b>: Setting package "
"dynamic version to __version__ "
f"variable from __init__.py: <b>{version}</b>"
)
poetry.package._set_version(version)
return
message = (
"<b>poetry-version-plugin</b>: No valid __version__ variable found "
"in __init__.py, cannot extract dynamic version"
Expand Down

0 comments on commit f137d84

Please sign in to comment.