-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new way to update version in all init files. have to add this t…
…o github workflow or precommit hooks
- Loading branch information
Giacomo Antonioli
committed
Mar 4, 2024
1 parent
696a342
commit 54cc0bb
Showing
8 changed files
with
64 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
"""Filter subpackage for qimp.""" | ||
__version__ = "0.2.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
"""Image subpackage for qimp.""" | ||
__version__ = "0.2.1" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
"""Unit test package for qimp.""" | ||
__version__ = "0.2.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |