Skip to content

Commit 09ca42d

Browse files
authored
Adding deprecation notice (#41)
* Adding deprecation notice * Version bump * Fixing version check in CI * Fixing version logic * Changed version string format * Switched pyproject.toml to hard coded version to be modified by pre commit hook * Fix version extraction
1 parent 50fe8f1 commit 09ca42d

File tree

9 files changed

+324
-190
lines changed

9 files changed

+324
-190
lines changed

.github/workflows/pr-preview.yml

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,63 @@
11
name: PR Preview
22
on:
33
pull_request:
4-
types: [opened, synchronize]
4+
types: [opened, synchronize, ready_for_review]
55

66
jobs:
77
preview:
88
runs-on: ubuntu-latest
99
permissions:
10-
pull-requests: write
11-
issues: write
1210
id-token: write
1311
contents: read
12+
pull-requests: write
1413
steps:
1514
- uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
1617
- uses: actions/setup-python@v5
1718
with:
18-
python-version: '3.12'
19+
python-version: '3.x'
1920

2021
# Install all dependencies from pyproject.toml
2122
- name: Install dependencies
2223
run: |
2324
python -m pip install --upgrade pip
24-
pip install -e .
25+
pip install hatchling==1.27.0
26+
pip install hatch==1.14.0
2527
26-
- name: Set preview version
27-
run: |
28-
BASE_VERSION=$(python -c "from socketdev import __version__; print(__version__)")
29-
PREVIEW_VERSION="${BASE_VERSION}.dev${{ github.event.pull_request.number }}${{ github.event.pull_request.commits }}"
30-
echo "VERSION=${PREVIEW_VERSION}" >> $GITHUB_ENV
31-
32-
# Update version in version.py instead of __init__.py
33-
echo "__version__ = \"${PREVIEW_VERSION}\"" > socketdev/version.py
34-
35-
# Verify the change
36-
echo "Updated version in version.py:"
37-
cat socketdev/version.py
28+
- name: Inject full dynamic version
29+
run: python .hooks/sync_version.py --dev
3830

3931
- name: Check if version exists on Test PyPI
4032
id: version_check
41-
env:
42-
VERSION: ${{ env.VERSION }}
4333
run: |
34+
VERSION=$(hatch version | cut -d+ -f1)
35+
echo "VERSION=$VERSION" >> $GITHUB_ENV
4436
if curl -s -f https://test.pypi.org/pypi/socket-sdk-python/$VERSION/json > /dev/null; then
4537
echo "Version ${VERSION} already exists on Test PyPI"
4638
echo "exists=true" >> $GITHUB_OUTPUT
4739
else
48-
echo "Version ${VERSION} not found on Test PyPI"
40+
echo "Version ${VERSION} not found on Test PyPI - proceeding with test deployment"
4941
echo "exists=false" >> $GITHUB_OUTPUT
5042
fi
5143
52-
- name: Build package
53-
if: steps.version_check.outputs.exists != 'true'
44+
- name: Clean previous builds
45+
run: rm -rf dist/ build/ *.egg-info
46+
47+
- name: Get Hatch version
48+
id: version
5449
run: |
55-
pip install build
56-
python -m build
50+
VERSION=$(hatch version | cut -d+ -f1)
51+
echo "VERSION=$VERSION" >> $GITHUB_ENV
5752
58-
- name: Restore original version
59-
if: always()
53+
- name: Build package
54+
if: steps.version_check.outputs.exists != 'true'
6055
run: |
61-
BASE_VERSION=$(echo $VERSION | cut -d'.' -f1-3)
62-
echo "__version__ = \"${BASE_VERSION}\"" > socketdev/version.py
56+
hatch build
6357
6458
- name: Publish to Test PyPI
6559
if: steps.version_check.outputs.exists != 'true'
66-
uses: pypa/gh-action-pypi-publish@v1.8.11
60+
uses: pypa/gh-action-pypi-publish@v1.12.4
6761
with:
6862
repository-url: https://test.pypi.org/legacy/
6963
verbose: true

.github/workflows/release.yml

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
name: Release
22
on:
3-
push:
4-
tags:
5-
- 'v*'
3+
release:
4+
types: [published]
65

76
jobs:
87
release:
98
runs-on: ubuntu-latest
109
permissions:
1110
id-token: write
1211
contents: read
13-
pull-requests: write
14-
issues: write
1512
steps:
1613
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
1716
- uses: actions/setup-python@v5
1817
with:
19-
python-version: '3.12'
18+
python-version: '3.x'
2019

2120
# Install all dependencies from pyproject.toml
2221
- name: Install dependencies
2322
run: |
2423
python -m pip install --upgrade pip
25-
pip install -e .
26-
24+
pip install hatchling==1.27.0
25+
pip install hatch==1.14.0
26+
2727
- name: Get Version
2828
id: version
2929
run: |
30-
RAW_VERSION=$(python -c "from socketdev.version import __version__; print(__version__)")
30+
RAW_VERSION=$(hatch version)
3131
echo "VERSION=$RAW_VERSION" >> $GITHUB_ENV
3232
if [ "v$RAW_VERSION" != "${{ github.ref_name }}" ]; then
33-
echo "Error: Git tag (${{ github.ref_name }}) does not match package version (v$RAW_VERSION)"
33+
echo "Error: Git tag (${{ github.ref_name }}) does not match hatch version (v$RAW_VERSION)"
3434
exit 1
3535
fi
3636
@@ -50,11 +50,26 @@ jobs:
5050
- name: Build package
5151
if: steps.version_check.outputs.pypi_exists != 'true'
5252
run: |
53-
pip install build
54-
python -m build
53+
hatch build
5554
5655
- name: Publish to PyPI
5756
if: steps.version_check.outputs.pypi_exists != 'true'
58-
uses: pypa/[email protected]
59-
with:
60-
password: ${{ secrets.PYPI_TOKEN }}
57+
uses: pypa/[email protected]
58+
59+
- name: Verify package is installable
60+
id: verify_package
61+
env:
62+
VERSION: ${{ env.VERSION }}
63+
run: |
64+
for i in {1..30}; do
65+
if pip install socket-sdk-python==${VERSION}; then
66+
echo "Package ${VERSION} is now available and installable on PyPI"
67+
pip uninstall -y socket-sdk-python
68+
echo "success=true" >> $GITHUB_OUTPUT
69+
exit 0
70+
fi
71+
echo "Attempt $i: Package not yet installable, waiting 20s... (${i}/30)"
72+
sleep 20
73+
done
74+
echo "success=false" >> $GITHUB_OUTPUT
75+
exit 1

.github/workflows/version-check.yml

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Version Check
22
on:
33
pull_request:
4-
types: [opened, synchronize]
4+
types: [opened, synchronize, ready_for_review]
55
paths:
66
- 'socketdev/**'
77
- 'setup.py'
@@ -19,22 +19,13 @@ jobs:
1919
id: version_check
2020
run: |
2121
# Get version from current PR
22-
PR_VERSION=$(grep -o '__version__ = "[^"]*"' socketdev/version.py | cut -d'"' -f2)
23-
echo "Debug PR version: $PR_VERSION"
24-
echo "PR_VERSION=${PR_VERSION}" >> $GITHUB_ENV
22+
PR_VERSION=$(grep -o "__version__.*" socketdev/version.py | awk '{print $3}' | tr -d '"' | tr -d "'")
23+
echo "PR_VERSION=$PR_VERSION" >> $GITHUB_ENV
2524
26-
# Get version from main branch - try both locations
25+
# Get version from main branch
2726
git checkout origin/main
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-
36-
echo "Debug main version: $MAIN_VERSION"
37-
echo "MAIN_VERSION=${MAIN_VERSION}" >> $GITHUB_ENV
27+
MAIN_VERSION=$(grep -o "__version__.*" socketdev/version.py | awk '{print $3}' | tr -d '"' | tr -d "'")
28+
echo "MAIN_VERSION=$MAIN_VERSION" >> $GITHUB_ENV
3829
3930
# Compare versions using Python
4031
python3 -c "
@@ -85,7 +76,7 @@ jobs:
8576
owner: owner,
8677
repo: repo,
8778
comment_id: versionComment.id,
88-
body: `❌ **Version Check Failed**\n\nPlease increment the version. Current version in main: ${process.env.MAIN_VERSION}, PR version: ${process.env.PR_VERSION}`
79+
body: `❌ **Version Check Failed**\n\nPlease increment...`
8980
});
9081
}
9182
} else if (!success) {
@@ -94,6 +85,6 @@ jobs:
9485
owner: owner,
9586
repo: repo,
9687
issue_number: prNumber,
97-
body: `❌ **Version Check Failed**\n\nPlease increment the version. Current version in main: ${process.env.MAIN_VERSION}, PR version: ${process.env.PR_VERSION}`
88+
body: `❌ **Version Check Failed**\n\nPlease increment...`
9889
});
9990
}

.hooks/sync_version.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env python3
2+
import subprocess
3+
import pathlib
4+
import re
5+
import sys
6+
import urllib.request
7+
import json
8+
9+
VERSION_FILE = pathlib.Path("socketdev/version.py")
10+
PYPROJECT_FILE = pathlib.Path("pyproject.toml")
11+
12+
VERSION_PATTERN = re.compile(r"__version__\s*=\s*['\"]([^'\"]+)['\"]")
13+
PYPROJECT_PATTERN = re.compile(r'^version\s*=\s*".*"$', re.MULTILINE)
14+
PYPI_API = "https://test.pypi.org/pypi/socket-sdk-python/json"
15+
16+
def read_version_from_version_file(path: pathlib.Path) -> str:
17+
content = path.read_text()
18+
match = VERSION_PATTERN.search(content)
19+
if not match:
20+
print(f"❌ Could not find __version__ in {path}")
21+
sys.exit(1)
22+
return match.group(1)
23+
24+
def read_version_from_git(path: str) -> str:
25+
try:
26+
output = subprocess.check_output(["git", "show", f"HEAD:{path}"], text=True)
27+
match = VERSION_PATTERN.search(output)
28+
if not match:
29+
return None
30+
return match.group(1)
31+
except subprocess.CalledProcessError:
32+
return None
33+
34+
def bump_patch_version(version: str) -> str:
35+
if ".dev" in version:
36+
version = version.split(".dev")[0]
37+
parts = version.split(".")
38+
parts[-1] = str(int(parts[-1]) + 1)
39+
return ".".join(parts)
40+
41+
def fetch_existing_versions() -> set:
42+
try:
43+
with urllib.request.urlopen(PYPI_API) as response:
44+
data = json.load(response)
45+
return set(data.get("releases", {}).keys())
46+
except Exception as e:
47+
print(f"⚠️ Warning: Failed to fetch existing versions from Test PyPI: {e}")
48+
return set()
49+
50+
def find_next_available_dev_version(base_version: str) -> str:
51+
existing_versions = fetch_existing_versions()
52+
for i in range(1, 100):
53+
candidate = f"{base_version}.dev{i}"
54+
if candidate not in existing_versions:
55+
return candidate
56+
print("❌ Could not find available .devN slot after 100 attempts.")
57+
sys.exit(1)
58+
59+
def inject_version(version: str):
60+
print(f"🔁 Updating version to: {version}")
61+
62+
# Update version.py
63+
VERSION_FILE.write_text(f'__version__ = "{version}"\n')
64+
65+
# Update pyproject.toml if it has a version field (it shouldn't with hatch, but just in case)
66+
pyproject = PYPROJECT_FILE.read_text()
67+
if PYPROJECT_PATTERN.search(pyproject):
68+
new_pyproject = PYPROJECT_PATTERN.sub(f'version = "{version}"', pyproject)
69+
PYPROJECT_FILE.write_text(new_pyproject)
70+
71+
def main():
72+
dev_mode = "--dev" in sys.argv
73+
current_version = read_version_from_version_file(VERSION_FILE)
74+
previous_version = read_version_from_git("socketdev/version.py")
75+
76+
print(f"Current: {current_version}, Previous: {previous_version}")
77+
78+
if current_version == previous_version:
79+
if dev_mode:
80+
base_version = current_version.split(".dev")[0] if ".dev" in current_version else current_version
81+
new_version = find_next_available_dev_version(base_version)
82+
inject_version(new_version)
83+
print("⚠️ Version was unchanged — auto-bumped. Please git add + commit again.")
84+
sys.exit(0)
85+
else:
86+
new_version = bump_patch_version(current_version)
87+
inject_version(new_version)
88+
print("⚠️ Version was unchanged — auto-bumped. Please git add + commit again.")
89+
sys.exit(1)
90+
else:
91+
print("✅ Version already bumped — proceeding.")
92+
sys.exit(0)
93+
94+
if __name__ == "__main__":
95+
main()

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Socket Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
socket-python-sdk
33
#################
44

5+
.. warning::
6+
**DEPRECATED**: This package is deprecated. Please migrate to the new ``socketdev`` package:
7+
8+
.. code-block:: bash
9+
10+
pip uninstall socket-sdk-python
11+
pip install socketdev
12+
13+
The API remains exactly the same, only the package name has changed. This package will no longer receive updates.
14+
515
Purpose
616
-------
717

0 commit comments

Comments
 (0)