Skip to content

Version Definition: The version is now defined only in datafog/__abou… #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,34 @@ 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
# Extract the numeric part before 'b'
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
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 22 additions & 0 deletions test_version.py
Original file line number Diff line number Diff line change
@@ -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")
Loading