Skip to content

Commit c94a84b

Browse files
Merge pull request #29 from pescheckit/hotfix_fixed-issue-better-withclaudesleef
Fixed get_verions
2 parents b48efc1 + a99a510 commit c94a84b

File tree

7 files changed

+93
-36
lines changed

7 files changed

+93
-36
lines changed

.github/workflows/ci-cd.yml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ jobs:
100100
restore-keys: |
101101
${{ runner.os }}-buildx-
102102
103+
- name: Get Version for Docker Build
104+
id: get_version
105+
run: |
106+
# Ensure we have tags
107+
git fetch --tags --force
108+
109+
# For tagged builds, use the exact tag without v prefix for PACKAGE_VERSION
110+
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
111+
TAG=${GITHUB_REF#refs/tags/}
112+
VERSION="${TAG#v}"
113+
echo "Using tag version: $VERSION"
114+
else
115+
# Use git version without v prefix
116+
VERSION=$(git describe --tags --always 2>/dev/null | sed 's/^v//' || echo "0.1.0")
117+
echo "Using git version: $VERSION"
118+
fi
119+
120+
# Output for GitHub Actions
121+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
122+
103123
- name: Build Docker Image - Python ${{ matrix.python-version }}
104124
uses: docker/build-push-action@v5
105125
with:
@@ -108,6 +128,7 @@ jobs:
108128
tags: gpt-po-translator:py${{ matrix.python-version }}
109129
build-args: |
110130
PYTHON_VERSION=${{ matrix.python-version }}
131+
VERSION=${{ steps.get_version.outputs.VERSION }}
111132
cache-from: type=gha
112133
cache-to: type=gha,mode=max
113134

@@ -164,6 +185,17 @@ jobs:
164185
uses: actions/setup-python@v5
165186
with:
166187
python-version: '3.x'
188+
189+
- name: Set Package Version for PyPI
190+
if: matrix.python-version == '3.11'
191+
run: |
192+
# Get tag name without 'refs/tags/' prefix
193+
TAG=${GITHUB_REF#refs/tags/}
194+
# Remove 'v' prefix if present
195+
VERSION="${TAG#v}"
196+
# Set as environment variable
197+
echo "PACKAGE_VERSION=$VERSION" >> $GITHUB_ENV
198+
echo "Using version $VERSION for PyPI package"
167199
168200
- name: Install dependencies
169201
if: matrix.python-version == '3.11'
@@ -227,12 +259,12 @@ jobs:
227259
# For tagged builds, use the exact tag
228260
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
229261
TAG=${GITHUB_REF#refs/tags/}
230-
# Keep the v prefix for git tags
231-
VERSION="$TAG"
262+
# Remove v prefix if present for Docker build arg
263+
VERSION="${TAG#v}"
232264
echo "Using tag version: $VERSION"
233265
else
234-
# Use git version with v prefix
235-
VERSION=$(git describe --tags --always 2>/dev/null || echo "v0.1.0")
266+
# Use git version without v prefix
267+
VERSION=$(git describe --tags --always 2>/dev/null | sed 's/^v//' || echo "0.1.0")
236268
echo "Using git version: $VERSION"
237269
fi
238270
@@ -250,4 +282,4 @@ jobs:
250282
PYTHON_VERSION=${{ matrix.python-version }}
251283
VERSION=${{ steps.get_version.outputs.VERSION }}
252284
cache-from: type=gha
253-
cache-to: type=gha,mode=max
285+
cache-to: type=gha,mode=max

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ dist/
55
__pycache__
66
build/
77
db.sqlite3
8-
.venv
8+
.venv
9+
python_gpt_po/version.py

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ FROM python:${PYTHON_VERSION}-slim
33

44
# Accept version as build arg
55
ARG VERSION="0.1.0"
6+
# Set as environment variable for setup.py to use
7+
ENV PACKAGE_VERSION=${VERSION}
8+
ENV PYTHONPATH=/app
69

710
WORKDIR /app
811

@@ -13,11 +16,12 @@ RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib
1316
COPY requirements.txt .
1417
RUN pip install --no-cache-dir -r requirements.txt
1518

16-
# Copy source code for installation
19+
# Copy source code
1720
COPY . .
1821

19-
# Install the package
20-
RUN pip install --no-cache-dir .
22+
# Create a simple wrapper script
23+
RUN echo '#!/bin/bash\npython -m python_gpt_po.main "$@"' > /usr/local/bin/gpt-po-translator && \
24+
chmod +x /usr/local/bin/gpt-po-translator
2125

2226
# Create a wrapper script to allow more flexibility
2327
COPY docker-entrypoint.sh /usr/local/bin/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ git clone https://github.com/pescheckit/python-gpt-po.git
4343
cd python-gpt-po
4444
python3 -m venv .venv
4545
source .venv/bin/activate
46-
pip install -r requirements
46+
pip install -r requirements.txt
4747
python -m python_gpt_po.main --folder test --lang nl --bulk --provider="deepseek" --list-models
4848
```
4949

build.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

setup.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
This script is used to install the package, dependencies, and the man page.
44
"""
55

6-
import json
76
import os
7+
import subprocess
88

99
from setuptools import find_packages, setup
1010

@@ -16,17 +16,34 @@
1616

1717

1818
def get_version():
19-
"""
20-
Get version from git or version.json (for Docker builds).
21-
22-
Returns:
23-
dict or bool: Version configuration
24-
"""
25-
if os.path.exists('version.json'):
26-
# In Docker build environment, use the version file
27-
with open('version.json', encoding='utf-8') as version_file:
28-
return json.load(version_file)['version']
29-
return True # Use SCM version
19+
"""Get version from git or environment variable."""
20+
# Check for Docker environment
21+
if 'PACKAGE_VERSION' in os.environ:
22+
return os.environ.get('PACKAGE_VERSION')
23+
24+
# Check for CI/CD environment variable
25+
if 'GITHUB_REF' in os.environ and os.environ['GITHUB_REF'].startswith('refs/tags/'):
26+
# Extract version from tag (strip 'v' prefix if present)
27+
return os.environ['GITHUB_REF'].split('/')[-1].lstrip('v')
28+
29+
# Try getting from git
30+
try:
31+
# Get version from git describe, but normalize it to be PEP 440 compliant
32+
version = subprocess.check_output(['git', 'describe', '--tags', '--always']).decode('utf-8').strip()
33+
34+
# Handle version format from git describe
35+
if '-' in version:
36+
# Format like v0.3.5-5-gd9775d7, convert to 0.3.5.dev5+gd9775d7
37+
tag, commits, commit_hash = version.lstrip('v').split('-')
38+
version = f"{tag}.dev{commits}+{commit_hash}"
39+
elif version.startswith('v'):
40+
# Just a tagged version like v0.3.5
41+
version = version[1:]
42+
43+
return version
44+
except (subprocess.SubprocessError, FileNotFoundError):
45+
# Fallback version
46+
return "0.1.0"
3047

3148

3249
def install_man_pages():
@@ -44,8 +61,7 @@ def install_man_pages():
4461

4562
setup(
4663
name='gpt-po-translator',
47-
use_scm_version=get_version(),
48-
setup_requires=['setuptools-scm==8.1.0'],
64+
version=get_version(),
4965
author='Bram Mittendorff',
5066
author_email='[email protected]',
5167
description='A CLI tool for translating .po files using GPT models.',

version.sh

100644100755
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
#!/bin/bash
22
# Get version from git
33
GIT_VERSION=$(git describe --tags --always 2>/dev/null || echo "0.1.0")
4-
# Strip any leading 'v' if present
5-
VERSION="${GIT_VERSION#v}"
6-
echo $VERSION
4+
5+
# Clean up version for PEP 440 compliance
6+
if [[ "$GIT_VERSION" == *-*-* ]]; then
7+
# Format: v0.3.5-5-gd9775d7 -> 0.3.5.dev5+gd9775d7
8+
VERSION=$(echo "$GIT_VERSION" | sed -E 's/^v?([0-9]+\.[0-9]+\.[0-9]+)-([0-9]+)-g([a-f0-9]+)/\1.dev\2+\3/')
9+
else
10+
# Simple version, just remove v prefix if present
11+
VERSION="${GIT_VERSION#v}"
12+
fi
13+
14+
# If first argument is "docker", return Docker-friendly version (replace + with -)
15+
if [ "$1" = "docker" ]; then
16+
echo "${VERSION//+/-}"
17+
else
18+
echo "$VERSION"
19+
fi

0 commit comments

Comments
 (0)