From bb18437cfba5faa50fae5d414dc0227b9a3f50b1 Mon Sep 17 00:00:00 2001 From: Sid Mohan Date: Tue, 6 May 2025 18:37:35 -0700 Subject: [PATCH] Version Definition: The version is now defined only in datafog/__about__.py Setup.py Integration: The setup.py file now reads the version from __about__.py without importing the package, which avoids circular dependencies during build GitHub Actions Workflow: The CI/CD workflow has been updated to only modify the version in __about__.py --- .github/workflows/publish-pypi.yml | 33 +++++++++++++++++++----------- setup.py | 9 ++++++-- test_version.py | 22 ++++++++++++++++++++ 3 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 test_version.py diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index 50b9dfaf..9ac8e016 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -82,12 +82,21 @@ jobs: - name: Generate beta version id: beta_version run: | - # Read current version from setup.py - CURRENT_VERSION=$(grep -o '__version__ = "[^"]*"' setup.py | cut -d"" -f2) + # Read current version from __about__.py (single source of truth) + CURRENT_VERSION=$(grep -o '__version__ = "[^"]*"' datafog/__about__.py | sed 's/__version__ = "\(.*\)"/\1/') echo "Current version in files: $CURRENT_VERSION" # Split version into components - IFS='.' read -r MAJOR MINOR PATCH_FULL <<< "$CURRENT_VERSION" + IFS='.' read -r MAJOR MINOR PATCH_FULL <<< "$CURRENT_VERSION" || true + + # Validate we got valid version components + if [[ -z "$MAJOR" || -z "$MINOR" || -z "$PATCH_FULL" ]]; then + echo "Error: Could not parse version components from $CURRENT_VERSION" + echo "Using default version 0.0.1b1" + MAJOR=0 + MINOR=0 + PATCH_FULL=1 + fi # Handle beta suffix if it exists if [[ $PATCH_FULL == *b* ]]; then @@ -95,7 +104,12 @@ jobs: PATCH_NUM=${PATCH_FULL%%b*} # Extract the beta number and increment it BETA_NUM=${PATCH_FULL#*b} - BETA_NUM=$((BETA_NUM + 1)) + # Ensure beta number is a valid integer + if ! [[ $BETA_NUM =~ ^[0-9]+$ ]]; then + BETA_NUM=1 + else + BETA_NUM=$((BETA_NUM + 1)) + fi else # If not already a beta, use the patch number and start with beta1 PATCH_NUM=$PATCH_FULL @@ -107,13 +121,8 @@ jobs: echo "Generated beta version: $BETA_VERSION" echo "version=$BETA_VERSION" >> $GITHUB_OUTPUT - # Update version in setup.py - sed -i "s/__version__ = \"[^\"]*\"/__version__ = \"$BETA_VERSION\"/g" setup.py - - # Update version in __about__.py if it exists - if [ -f "datafog/__about__.py" ]; then - sed -i "s/__version__ = \"[^\"]*\"/__version__ = \"$BETA_VERSION\"/g" datafog/__about__.py - fi + # Update version in __about__.py (single source of truth) + sed -i "s/__version__ = \"[^\"]*\"/__version__ = \"$BETA_VERSION\"/g" datafog/__about__.py - name: Build package run: python -m build - name: Create GitHub Pre-Release @@ -125,7 +134,7 @@ jobs: git config user.email github-actions@github.com # Commit the version changes - git add setup.py datafog/__about__.py + git add datafog/__about__.py git commit -m "Bump version to $BETA_VERSION [skip ci]" # Create and push tag diff --git a/setup.py b/setup.py index a90f4fd1..0025330c 100644 --- a/setup.py +++ b/setup.py @@ -4,8 +4,13 @@ with open("README.md", "r") as f: long_description = f.read() -# Use a single source of truth for the version -__version__ = "4.1.0b4" +# Read version from __about__.py without importing the package +# This avoids circular dependencies during build +about = {} +with open("datafog/__about__.py", "r") as f: + exec(f.read(), about) + +__version__ = about["__version__"] project_urls = { "Homepage": "https://datafog.ai", diff --git a/test_version.py b/test_version.py new file mode 100644 index 00000000..9153291c --- /dev/null +++ b/test_version.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +# Read version directly from __about__.py +with open('datafog/__about__.py', 'r') as f: + about_content = f.read().strip() + about_version = about_content.split('"')[1] # Simple string split to extract version + +print(f"Version in __about__.py: {about_version}") + +# Read version from setup.py using the same method setup.py uses +about = {} +with open("datafog/__about__.py", "r") as f: + exec(f.read(), about) + +setup_version = about['__version__'] +print(f"Version extracted by setup.py: {setup_version}") + +# Verify they match +if about_version == setup_version: + print("✅ SUCCESS: Single source of truth is working correctly!") +else: + print("❌ ERROR: Versions don't match")