From 6feadf1ea87fd1f2b641af5ddeceb659efa3b29e Mon Sep 17 00:00:00 2001 From: Deependu Jha Date: Sun, 19 Jan 2025 00:09:07 +0530 Subject: [PATCH 1/4] basic working --- .github/workflows/check_version.yml | 34 +++++++++++++++ scripts/check_version.py | 65 +++++++++++++++++++++++++++++ src/deeptensor/__init__.py | 4 +- src/deeptensor/__version__.py | 3 ++ 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/check_version.yml create mode 100644 scripts/check_version.py create mode 100644 src/deeptensor/__version__.py diff --git a/.github/workflows/check_version.yml b/.github/workflows/check_version.yml new file mode 100644 index 0000000..f14b572 --- /dev/null +++ b/.github/workflows/check_version.yml @@ -0,0 +1,34 @@ +name: CPP CI testing + +# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows +on: # Trigger the workflow on push or pull request, but only for the main branch + push: + branches: [main] + pull_request: + branches: [main] + types: [opened, reopened, ready_for_review, synchronize] + +defaults: + run: + shell: bash + +jobs: + GoogleTests: + runs-on: ubuntu-latest + + # Timeout: https://stackoverflow.com/a/59076067/4521646 + timeout-minutes: 35 + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive # Ensures submodules are initialized and updated + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Check if python version matches in pyproject.toml and src/deeptensor/__version__.py + run: | + pip install toml + python scripts/check_version.py diff --git a/scripts/check_version.py b/scripts/check_version.py new file mode 100644 index 0000000..512158d --- /dev/null +++ b/scripts/check_version.py @@ -0,0 +1,65 @@ +from __future__ import annotations + +import ast +import os +import sys +from pathlib import Path + +import toml + + +def get_pyproject_version(pyproject_path): + try: + with Path.open(pyproject_path) as file: + pyproject_data = toml.load(file) + return pyproject_data.get("project", {}).get("version") + except Exception as e: + print(f"Error reading {pyproject_path}: {e}") # noqa: T201 + return None + + +def get_version_file_version(version_file_path): + try: + with Path.open(version_file_path, "r") as file: + file_content = file.read() + # Parse the file and extract version + tree = ast.parse(file_content, filename=version_file_path) + for node in ast.walk(tree): + if isinstance(node, ast.Assign): + for target in node.targets: + if ( + isinstance(target, ast.Name) + and target.id == "version" + and isinstance(node.value, ast.Constant) + ): # For Python 3.8+ + return node.value.value + print(f"Version not found in {version_file_path}") # noqa: T201 + return None + except Exception as e: + print(f"Error reading {version_file_path}: {e}") # noqa: T201 + return None + + +def main(): + pyproject_path = "pyproject.toml" + version_file_path = os.path.join("src", "deeptensor", "__version__.py") # noqa: PTH118 + + pyproject_version = get_pyproject_version(pyproject_path) + version_file_version = get_version_file_version(version_file_path) + + if pyproject_version is None or version_file_version is None: + print("Error: Unable to fetch version(s).") # noqa: T201 + sys.exit(1) + + if pyproject_version == version_file_version: + print("Version check passed!") # noqa: T201 + sys.exit(0) + else: + print( # noqa: T201 + f"Version mismatch: pyproject.toml ({pyproject_version}) != __version__.py ({version_file_version})" + ) + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/src/deeptensor/__init__.py b/src/deeptensor/__init__.py index daa1778..214a85a 100644 --- a/src/deeptensor/__init__.py +++ b/src/deeptensor/__init__.py @@ -1,6 +1,7 @@ from __future__ import annotations -from ._core import ( +from .__version__ import version +from ._core import ( # type: ignore # noqa: PGH003 SGD, AdaGrad, Adam, @@ -40,4 +41,5 @@ "__doc__", "cross_entropy", "mean_squared_error", + "version", ] diff --git a/src/deeptensor/__version__.py b/src/deeptensor/__version__.py new file mode 100644 index 0000000..3bafd58 --- /dev/null +++ b/src/deeptensor/__version__.py @@ -0,0 +1,3 @@ +from __future__ import annotations + +version = "0.3.1" From be2ff107aa78aec7a97948e186f94bfb603b93c2 Mon Sep 17 00:00:00 2001 From: Deependu Jha Date: Sun, 19 Jan 2025 00:11:09 +0530 Subject: [PATCH 2/4] update --- .github/workflows/check_version.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check_version.yml b/.github/workflows/check_version.yml index f14b572..016836b 100644 --- a/.github/workflows/check_version.yml +++ b/.github/workflows/check_version.yml @@ -1,4 +1,4 @@ -name: CPP CI testing +name: Check Version # see: https://help.github.com/en/actions/reference/events-that-trigger-workflows on: # Trigger the workflow on push or pull request, but only for the main branch @@ -21,8 +21,8 @@ jobs: steps: - uses: actions/checkout@v4 - with: - submodules: recursive # Ensures submodules are initialized and updated + # we don't need to clone recursively. + # As we only need to check if two values are same. - name: Set up Python 3.10 uses: actions/setup-python@v5 with: From a285f5a23f246dbde2d74ef013c8e6dd9db5a1de Mon Sep 17 00:00:00 2001 From: Deependu Jha Date: Sun, 19 Jan 2025 00:11:30 +0530 Subject: [PATCH 3/4] update --- src/deeptensor/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deeptensor/__version__.py b/src/deeptensor/__version__.py index 3bafd58..5117fb3 100644 --- a/src/deeptensor/__version__.py +++ b/src/deeptensor/__version__.py @@ -1,3 +1,3 @@ from __future__ import annotations -version = "0.3.1" +version = "0.3.0" From 13fc0e5f91a4788712c9f15dbc36225aec85d002 Mon Sep 17 00:00:00 2001 From: Deependu Jha Date: Sun, 19 Jan 2025 00:12:23 +0530 Subject: [PATCH 4/4] update --- .github/workflows/check_version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check_version.yml b/.github/workflows/check_version.yml index 016836b..0e5aa5c 100644 --- a/.github/workflows/check_version.yml +++ b/.github/workflows/check_version.yml @@ -13,7 +13,7 @@ defaults: shell: bash jobs: - GoogleTests: + DeepTensor_Version: runs-on: ubuntu-latest # Timeout: https://stackoverflow.com/a/59076067/4521646