Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #21 -> Refactoring #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading