Skip to content

Commit 3312c6c

Browse files
committed
version and circular import shenanigans
1 parent c508c05 commit 3312c6c

File tree

8 files changed

+22
-17
lines changed

8 files changed

+22
-17
lines changed

.github/workflows/pr-preview.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@ jobs:
2323
PREVIEW_VERSION="${BASE_VERSION}.dev${{ github.event.pull_request.number }}${{ github.event.pull_request.commits }}"
2424
echo "VERSION=${PREVIEW_VERSION}" >> $GITHUB_ENV
2525
26-
# Update version in __init__.py
27-
echo "__version__ = \"${PREVIEW_VERSION}\"" > socketdev/__init__.py.tmp
28-
cat socketdev/__init__.py | grep -v "__version__" >> socketdev/__init__.py.tmp
29-
mv socketdev/__init__.py.tmp socketdev/__init__.py
26+
# Update version in version.py instead of __init__.py
27+
echo "__version__ = \"${PREVIEW_VERSION}\"" > socketdev/version.py
3028
3129
# Verify the change
32-
echo "Updated version in __init__.py:"
33-
cat socketdev/__init__.py | grep "__version__"
30+
echo "Updated version in version.py:"
31+
cat socketdev/version.py
3432
3533
- name: Check if version exists on Test PyPI
3634
id: version_check
@@ -55,9 +53,7 @@ jobs:
5553
if: always()
5654
run: |
5755
BASE_VERSION=$(echo $VERSION | cut -d'.' -f1-3)
58-
echo "__version__ = \"${BASE_VERSION}\"" > socketdev/__init__.py.tmp
59-
cat socketdev/__init__.py | grep -v "__version__" >> socketdev/__init__.py.tmp
60-
mv socketdev/__init__.py.tmp socketdev/__init__.py
56+
echo "__version__ = \"${BASE_VERSION}\"" > socketdev/version.py
6157
6258
- name: Publish to Test PyPI
6359
if: steps.version_check.outputs.exists != 'true'

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Get Version
1717
id: version
1818
run: |
19-
RAW_VERSION=$(python -c "from socketdev import __version__; print(__version__)")
19+
RAW_VERSION=$(python -c "from socketdev.version import __version__; print(__version__)")
2020
echo "VERSION=$RAW_VERSION" >> $GITHUB_ENV
2121
if [ "v$RAW_VERSION" != "${{ github.ref_name }}" ]; then
2222
echo "Error: Git tag (${{ github.ref_name }}) does not match package version (v$RAW_VERSION)"

.github/workflows/version-check.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,20 @@ jobs:
1919
id: version_check
2020
run: |
2121
# Get version from current PR
22-
PR_VERSION=$(grep -o '__version__ = "[^"]*"' socketdev/__init__.py | cut -d'"' -f2)
22+
PR_VERSION=$(grep -o '__version__ = "[^"]*"' socketdev/version.py | cut -d'"' -f2)
2323
echo "Debug PR version: $PR_VERSION"
2424
echo "PR_VERSION=${PR_VERSION}" >> $GITHUB_ENV
2525
26-
# Get version from main branch
26+
# Get version from main branch - try both locations
2727
git checkout origin/main
28-
MAIN_VERSION=$(grep -o '__version__ = "[^"]*"' socketdev/__init__.py | cut -d'"' -f2)
28+
if [ -f socketdev/version.py ]; then
29+
MAIN_VERSION=$(grep -o '__version__ = "[^"]*"' socketdev/version.py | cut -d'"' -f2)
30+
else
31+
# Fall back to old location in __init__.py
32+
# Use more specific grep to avoid matching the imported version
33+
MAIN_VERSION=$(grep -o '^__version__ = "[^"]*"' socketdev/__init__.py | cut -d'"' -f2)
34+
fi
35+
2936
echo "Debug main version: $MAIN_VERSION"
3037
echo "MAIN_VERSION=${MAIN_VERSION}" >> $GITHUB_ENV
3138

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ include = [
6868
]
6969

7070
[tool.setuptools.dynamic]
71-
version = {attr = "socketdev.__version__"}
71+
version = {attr = "socketdev.version.__version__"}
7272

7373
[tool.ruff]
7474
# Exclude a variety of commonly ignored directories.

scripts/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
VERSION=$(grep -o "__version__.*" socketdev/__init__.py | awk '{print $3}' | sed 's/"//g' | sed "s/'//g" | tr -d '\r')
3+
VERSION=$(grep -o "__version__.*" socketdev/version.py | awk '{print $3}' | sed 's/"//g' | sed "s/'//g" | tr -d '\r')
44
ENABLE_PYPI_BUILD=$1
55

66
if [ -z $ENABLE_PYPI_BUILD ]; then

socketdev/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
from socketdev.sbom import Sbom
1616
from socketdev.settings import Settings
1717
from socketdev.utils import Utils, IntegrationType, INTEGRATION_TYPES
18+
from socketdev.version import __version__
1819

1920

2021
__author__ = "socket.dev"
21-
__version__ = "2.0.0"
22+
__version__ = __version__
2223
__all__ = ["socketdev", "Utils", "IntegrationType", "INTEGRATION_TYPES"]
2324

2425

socketdev/core/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import requests
33
from socketdev.core.classes import Response
44
from socketdev.exceptions import APIKeyMissing, APIFailure, APIAccessDenied, APIInsufficientQuota, APIResourceNotFound
5-
from socketdev import __version__
5+
from socketdev.version import __version__
66

77

88
class API:

socketdev/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "2.0.0"

0 commit comments

Comments
 (0)