Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePromidius committed Feb 22, 2024
1 parent 76944d0 commit b6e2098
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
Empty file added extensions/__init__.py
Empty file.
14 changes: 9 additions & 5 deletions updater/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def main():


sources_data = load_sources_data()

bumped = {}
for generic_extension_path in filter(os.path.isdir, {dir for dir in Path("extensions").iterdir() if "__pycache__" not in str(dir)}):
generic_extension = generic_extension_path.name

bumped[generic_extension] = []
print(f"scanning {generic_extension} extensions")
extension_path = f"extensions/{generic_extension}"
output_folder = Path(f"output/{generic_extension}")
Expand All @@ -36,18 +36,22 @@ def main():
print(f"Changes detected in extension '{module_name}'.")

if run_tests(f"extensions/{generic_extension}",module_name):
bump_version(module_name, extension_path)
bump_version(module)
sources_data[generic_extension][module_id] = {
"name": module_name,
'commit_hash': get_latest_commit_hash(module_name, extension_path),
"version": parse_version(module_path,module_name).base_version
'commit_hash': get_latest_commit_hash(module),
"version": parse_version(module).base_version
}

zip_extension(module_id, module_name, extension_path, output_folder)
bumped[generic_extension].append(module_name)
else:
print(f"No changes detected in extension '{module_name}'.")
save_sources_data(sources_data)

print("Bumped:")
print(bumped)


if __name__ == "__main__":
main()
14 changes: 8 additions & 6 deletions updater/hash_utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import os
import subprocess

from updater.CONSTANTS import SOURCES_PATH
from updater.versioning import parse_version, bump_version
def get_latest_commit_hash(module_path):
"""

def get_latest_commit_hash(module_name, source_folder):
:param module_name:
:param module_path: The path to the Module. ie: extensions/enrichers/<Module_name>
:return:
"""
try:
# get latest commit where the module was changed excluding the __version__.py file
git_command = f'git log -1 --pretty=format:%H -- {SOURCES_PATH}/{module_name} ":^{SOURCES_PATH}/{module_name}/__version__.py"'
git_command = f'git log -1 --pretty=format:%H -- {module_path} ":^{module_path}/__version__.py"'
result = subprocess.run(git_command, shell=True, capture_output=True, text=True, check=True)
print(git_command)
print(result_ := result.stdout.split("\n")[0].strip())
Expand All @@ -22,7 +24,7 @@ def get_latest_commit_hash(module_name, source_folder):


def has_code_changed(module_id, module_name, source_folder, sources_data):
latest_commit_hash = get_latest_commit_hash(module_name, source_folder)
latest_commit_hash = get_latest_commit_hash(f"{source_folder}/{module_name}")

latest_hash = sources_data.get(module_id, {}).get('commit_hash')
bump_type = os.getenv("BUMP_TYPE", "patch")
Expand Down
4 changes: 2 additions & 2 deletions updater/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def run_tests(module_path,module_name):
try:
tests = unittest.defaultTestLoader.discover(f"{module_name}.tests", top_level_dir=module_path)
tests = unittest.defaultTestLoader.discover(f"{module_name}", top_level_dir=module_path)
result = unittest.TextTestRunner().run(tests)
return result.wasSuccessful()
except Exception as e:
Expand All @@ -15,7 +15,7 @@ def run_tests(module_path,module_name):
def zip_extension(module_id,module_name, source_folder, output_folder):
extension_folder = os.path.join(source_folder, module_name)
zip_filename = os.path.join(output_folder, f"{module_id}.zip")

print(f"Zipping files to {zip_filename}")
try:
with zipfile.ZipFile(zip_filename, 'w') as zip_ref:
for root, _, files in os.walk(extension_folder):
Expand Down
12 changes: 6 additions & 6 deletions updater/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from packaging.version import Version


def bump_version(module_name, source_folder, level='patch'):
v = parse_version(module_name=module_name, module_path= source_folder)
def bump_version(module_folder, level='patch'):
v = parse_version(module_folder)
level = "patch" # Forcing it for now. Confused if it should be implemented this way or not.
if v:
if level == 'major':
Expand All @@ -16,14 +16,14 @@ def bump_version(module_name, source_folder, level='patch'):
v = version.Version(f"{v.release[0]}.{v.release[1]}.{v.release[2] + 1}")

# Save the bumped version back to __version__.py
version_file_path = os.path.join(source_folder, module_name, "__version__.py")
version_file_path = os.path.join(module_folder, "__version__.py")
with open(version_file_path, 'w') as version_file:
version_file.write(f"__version__ = '{v}'\n")

print(f"Version bumped to {v}")


def parse_version(module_path,module_name) -> Version:
def parse_version(module_path) -> Version:
version_file_path = os.path.join(module_path, "__version__.py")

try:
Expand All @@ -37,9 +37,9 @@ def parse_version(module_path,module_name) -> Version:
# Validate the version using the packaging library
return version.parse(raw_version)
except version.InvalidVersion:
print(f"Warning: Invalid version '{raw_version}' in '{module_name}'.")
print(f"Warning: Invalid version '{raw_version}' in '{module_path}'.")

return None
except FileNotFoundError:
print(f"Warning: Version file not found for '{module_name}'.")
print(f"Warning: Version file not found in '{module_path}'.")
return None

0 comments on commit b6e2098

Please sign in to comment.