From 5ea4700fb4a55901e573ed3166df8c299c4fbea5 Mon Sep 17 00:00:00 2001 From: FamALouiz Date: Wed, 19 Mar 2025 20:50:26 +0100 Subject: [PATCH 1/3] Updated _list_files with direct root_path passing --- pydatastructs/utils/tests/test_code_quality.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pydatastructs/utils/tests/test_code_quality.py b/pydatastructs/utils/tests/test_code_quality.py index eafa80be1..be9e58311 100644 --- a/pydatastructs/utils/tests/test_code_quality.py +++ b/pydatastructs/utils/tests/test_code_quality.py @@ -1,11 +1,11 @@ import os, re, sys, pydatastructs, inspect from typing import Type -def _list_files(checker): +def _list_files(checker, root_path=None): root_path = os.path.abspath( os.path.join( os.path.split(__file__)[0], - os.pardir, os.pardir)) + os.pardir, os.pardir)) if root_path is None else root_path code_files = [] for (dirpath, _, filenames) in os.walk(root_path): for _file in filenames: From 221af24ccf63d7ee528449fd7a9e55da92610f9d Mon Sep 17 00:00:00 2001 From: FamALouiz Date: Wed, 19 Mar 2025 20:50:42 +0100 Subject: [PATCH 2/3] Added update version script --- scripts/versioning/update_version.py | 62 ++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 scripts/versioning/update_version.py diff --git a/scripts/versioning/update_version.py b/scripts/versioning/update_version.py new file mode 100644 index 000000000..2a68facde --- /dev/null +++ b/scripts/versioning/update_version.py @@ -0,0 +1,62 @@ +import sys + +from pydatastructs.utils.tests.test_code_quality import _list_files + + +def update_version_in_files(file_paths, origin_version, new_version): + """ + Updates the version number in the specified files. + + Parameters + ========== + + file_paths: list + List of file paths to be updated. + origin_version: str + The original version number to be replaced. + new_version: str + The new version number to replace the original. + + Returns + ======= + + None + """ + was_updated = False + for path in file_paths: + with open(path, 'r') as file: + data = file.read() + if origin_version in data: + was_updated = True + data = data.replace(origin_version, new_version) + with open(path, 'w') as file: + file.write(data) + + return was_updated + + +def main(): + if len(sys.argv) != 3: + print('Usage: python update_version.py ') + return + + origin_version, new_version = sys.argv[1], sys.argv[2] + print(f'Updating version number from {origin_version} to {new_version}...') + + pydatastructs_files = _list_files(lambda _file: _file.endswith('.py'), + './pydatastructs') + docs_files = _list_files(lambda _file: _file.endswith('.rst') or _file.endswith('.py'), + './docs/source') + file_paths = ['README.md', 'setup.py'] + pydatastructs_files + docs_files + + was_updated = update_version_in_files( + file_paths, origin_version, new_version) + + if was_updated: + print('Version number updated successfully!') + else: + print('WARNING: Version number not found in the specified files.') + + +if __name__ == "__main__": + main() From 501f036b03ab22056ab84c00eacb5fb0b2ce9ebb Mon Sep 17 00:00:00 2001 From: FamALouiz Date: Wed, 19 Mar 2025 20:57:14 +0100 Subject: [PATCH 3/3] Cleaned up code for easier modification of files to be scanned --- scripts/versioning/update_version.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/versioning/update_version.py b/scripts/versioning/update_version.py index 2a68facde..ef936458c 100644 --- a/scripts/versioning/update_version.py +++ b/scripts/versioning/update_version.py @@ -2,6 +2,15 @@ from pydatastructs.utils.tests.test_code_quality import _list_files +# Files to be updated with the new version number +# The first element of the tuple is the directory path +# and the second element is a lambda function that +# returns True if the file should be updated. +FILES_TO_BE_SCANNED = { + 'pydatastructs': ('./pydatastructs', lambda _file: _file.endswith('.py')), + 'docs': ('./docs/source', lambda _file: _file.endswith('.rst') or _file.endswith('.py')) +} + def update_version_in_files(file_paths, origin_version, new_version): """ @@ -43,11 +52,10 @@ def main(): origin_version, new_version = sys.argv[1], sys.argv[2] print(f'Updating version number from {origin_version} to {new_version}...') - pydatastructs_files = _list_files(lambda _file: _file.endswith('.py'), - './pydatastructs') - docs_files = _list_files(lambda _file: _file.endswith('.rst') or _file.endswith('.py'), - './docs/source') - file_paths = ['README.md', 'setup.py'] + pydatastructs_files + docs_files + file_paths = ['README.md', 'setup.py'] + + for _, (dir_path, checker) in FILES_TO_BE_SCANNED.items(): + file_paths.extend(_list_files(checker, dir_path)) was_updated = update_version_in_files( file_paths, origin_version, new_version)