Skip to content

Commit

Permalink
added new way to update version in all init files. have to add this t…
Browse files Browse the repository at this point in the history
…o github workflow or precommit hooks
  • Loading branch information
Giacomo Antonioli committed Mar 4, 2024
1 parent 696a342 commit 54cc0bb
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 5 deletions.
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/qimp/Filters/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
"""Filter subpackage for qimp."""
__version__ = "0.2.1"
1 change: 1 addition & 0 deletions src/qimp/ImageEncoding/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
"""Image subpackage for qimp."""
__version__ = "0.2.1"
Empty file.
5 changes: 5 additions & 0 deletions src/qimp/Manipulations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Top-level package for qimp."""

__author__ = """Giacomo Antonioli"""
__email__ = "giacomo.antonioli@phd.unipi.it"
__version__ = "0.2.1"
2 changes: 1 addition & 1 deletion src/qimp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = """Giacomo Antonioli"""
__email__ = "giacomo.antonioli@phd.unipi.it"
__version__ = "0.1.0"
__version__ = "0.2.1"
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
"""Unit test package for qimp."""
__version__ = "0.2.1"
51 changes: 51 additions & 0 deletions updateversions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os

import toml


def update_version(toml_file: str) -> None:
"""
Update the version in the __init__.py file based on the version specified
in the given .toml file.
Args:
toml_file (str): The path to the .toml file.
Returns: None
"""
# Parse the .toml file
data = toml.load(toml_file)
version = data.get("tool", {}).get("poetry", {}).get("version", None)

if version is None:
print(f"No version found in {toml_file}")
return

# Walk the directory structure
for root, _, files in os.walk(os.path.dirname(toml_file)):
if "__init__.py" in files and "qimp" in root.split(os.sep):
init_file = os.path.join(root, "__init__.py")
with open(init_file, "r") as f:
lines = f.readlines()

# Update the version line
for i, line in enumerate(lines):
if line.startswith("__version__"):
lines[i] = f"__version__ = '{version}'\n"
break
else:
# If no version line was found, add one
lines.append(f"__version__ = '{version}'\n")

# Write the file back out
with open(init_file, "w") as f:
f.writelines(lines)

print(f"Updated version in {init_file} to {version}")


# Start the process
for root, _, files in os.walk("."):
for file in files:
if file.endswith(".toml"):
update_version(os.path.join(root, file))

0 comments on commit 54cc0bb

Please sign in to comment.