Skip to content

Commit ca0deb6

Browse files
Merge pull request #33 from pescheckit/hotfix_fixed-issue-with-build
Fixed issue
2 parents fe40c33 + bdd4eb0 commit ca0deb6

File tree

4 files changed

+36
-199
lines changed

4 files changed

+36
-199
lines changed

.github/workflows/ci-cd.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,22 @@ jobs:
207207
- name: Build package
208208
if: matrix.python-version == '3.11'
209209
run: |
210+
# Remove old build artifacts if any exist
211+
rm -rf dist build *.egg-info
212+
213+
# Explicitly set the version for the build tool
214+
if [ -n "$PACKAGE_VERSION" ]; then
215+
echo "Building package with version: $PACKAGE_VERSION"
216+
else
217+
echo "WARNING: PACKAGE_VERSION not set! Using git-based version."
218+
fi
219+
220+
# Build wheel and sdist with isolated environment
210221
python -m build
222+
223+
# Verify the wheel metadata
224+
pip install twine
225+
twine check dist/*
211226
212227
- name: Publish package
213228
if: matrix.python-version == '3.11'
@@ -282,4 +297,4 @@ jobs:
282297
PYTHON_VERSION=${{ matrix.python-version }}
283298
VERSION=${{ steps.get_version.outputs.VERSION }}
284299
cache-from: type=gha
285-
cache-to: type=gha,mode=max
300+
cache-to: type=gha,mode=max

Dockerfile

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
ARG PYTHON_VERSION=3.11
22
FROM python:${PYTHON_VERSION}-slim
33

4-
# Accept version as build arg
54
ARG VERSION="0.1.0"
6-
# Set as environment variable for setup.py to use
7-
ENV PACKAGE_VERSION=${VERSION}
5+
# ENV PACKAGE_VERSION=${VERSION} # Correctly removed
6+
7+
# Keep PYTHONPATH env var if needed, might be optional after install
88
ENV PYTHONPATH=/app
99

1010
WORKDIR /app
1111

12-
# Install git for versioning
13-
RUN apt-get update && apt-get install -y git && apt-get clean && rm -rf /var/lib/apt/lists/*
12+
# Install git - NEEDED for setuptools_scm to read .git directory
13+
RUN apt-get update && apt-get install -y --no-install-recommends git && \
14+
apt-get clean && rm -rf /var/lib/apt/lists/*
1415

1516
# Copy requirements and install dependencies first
1617
COPY requirements.txt .
1718
RUN pip install --no-cache-dir -r requirements.txt
1819

19-
# Copy source code
20+
# Copy the rest of the application code INCLUDING .git
2021
COPY . .
2122

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
23+
# Install the package itself. This triggers setuptools_scm inside the container.
24+
RUN pip install . --no-cache-dir
2525

26-
# Create a wrapper script to allow more flexibility
26+
# Keep your custom entrypoint script
2727
COPY docker-entrypoint.sh /usr/local/bin/
2828
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
2929

30+
# Use your custom entrypoint
3031
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

man/gpt-po-translator.1

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

setup.py

Lines changed: 9 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,15 @@
11
"""
2-
Setup script for the gpt-po-translator package.
3-
This script is used to install the package, dependencies, and the man page.
2+
Setup script shim for the gpt-po-translator package.
3+
Metadata is defined in pyproject.toml.
4+
This script enables setuptools_scm and handles custom data_files installation.
45
"""
56

6-
import os
7-
import subprocess
8-
from typing import Optional
9-
10-
from setuptools import find_packages, setup
11-
12-
with open('README.md', encoding='utf-8') as f:
13-
long_description = f.read()
14-
15-
with open('requirements.txt', encoding='utf-8') as f:
16-
install_requires = [line.strip() for line in f if line.strip() and not line.startswith('#')]
17-
18-
19-
def get_pep440_version() -> Optional[str]:
20-
"""
21-
Get version from environment or git, ensuring it's PEP 440 compliant.
22-
23-
Returns:
24-
Optional[str]: PEP 440 compliant version string or None to defer to setuptools_scm
25-
"""
26-
27-
# First check environment variable (highest priority for containers)
28-
if 'PACKAGE_VERSION' in os.environ:
29-
raw_version = os.environ.get('PACKAGE_VERSION')
30-
# Make version PEP 440 compliant
31-
if '-' in raw_version and '+' not in raw_version:
32-
# Convert something like "1.2.3-test" to "1.2.3+test" for PEP 440
33-
version = raw_version.replace('-', '+', 1)
34-
else:
35-
version = raw_version
36-
print(f"Using version from environment: {version}")
37-
return version
38-
39-
# Then try getting from git
40-
try:
41-
# Get version from git describe, but normalize it to be PEP 440 compliant
42-
version = subprocess.check_output(
43-
['git', 'describe', '--tags', '--always'],
44-
stderr=subprocess.STDOUT,
45-
text=True
46-
).strip()
47-
48-
# Handle version format from git describe
49-
if '-' in version:
50-
# Format like v0.3.5-5-gd9775d7, convert to 0.3.5.dev5+gd9775d7
51-
tag, commits, commit_hash = version.lstrip('v').split('-')
52-
version = f"{tag}.dev{commits}+{commit_hash}"
53-
elif version.startswith('v'):
54-
# Just a tagged version like v0.3.5
55-
version = version[1:]
56-
57-
print(f"Using git version: {version}")
58-
return version
59-
except (subprocess.SubprocessError, FileNotFoundError):
60-
# Defer to setuptools_scm
61-
print("Deferring to setuptools_scm for version")
62-
return None
63-
64-
65-
# Get version using our custom function
66-
package_version = get_pep440_version()
67-
68-
69-
def install_man_pages():
70-
"""
71-
Locate the man page and include it in the installation if it exists.
72-
73-
Returns:
74-
list: A list containing the path to the man page for installation.
75-
"""
76-
man_page = "man/gpt-po-translator.1"
77-
if os.path.exists(man_page):
78-
return [("share/man/man1", [man_page])]
79-
return []
80-
7+
from setuptools import setup
818

9+
# Most metadata is defined in pyproject.toml.
10+
# This file primarily enables setuptools_scm and handles non-declarative steps.
8211
setup(
83-
name='gpt-po-translator',
84-
version=package_version, # Will be None if PACKAGE_VERSION is not set, triggering setuptools_scm
85-
author='Bram Mittendorff',
86-
author_email='[email protected]',
87-
description='A CLI tool for translating .po files using GPT models.',
88-
long_description=long_description,
89-
long_description_content_type='text/markdown',
90-
url='https://github.com/pescheckit/python-gpt-po',
91-
license='MIT',
92-
packages=find_packages(exclude=["*.tests", "*.tests.*", "*.__pycache__", "*.__pycache__.*"]),
93-
include_package_data=True,
94-
install_requires=install_requires,
95-
entry_points={
96-
'console_scripts': [
97-
'gpt-po-translator=python_gpt_po.main:main',
98-
],
99-
},
100-
classifiers=[
101-
'Development Status :: 4 - Beta',
102-
'Intended Audience :: Developers',
103-
'Intended Audience :: System Administrators',
104-
'Topic :: Software Development :: Internationalization',
105-
'Topic :: Software Development :: Localization',
106-
'Topic :: Text Processing :: Linguistic',
107-
'Operating System :: OS Independent',
108-
'License :: OSI Approved :: MIT License',
109-
'Programming Language :: Python :: 3',
110-
'Programming Language :: Python :: 3.8',
111-
'Programming Language :: Python :: 3.9',
112-
'Programming Language :: Python :: 3.10',
113-
'Programming Language :: Python :: 3.11',
114-
'Programming Language :: Python :: 3.12',
115-
'Programming Language :: Python :: 3 :: Only',
116-
'Natural Language :: English',
117-
'Natural Language :: Dutch',
118-
'Environment :: Console',
119-
'Typing :: Typed'
120-
],
121-
python_requires='>=3.8',
122-
data_files=install_man_pages(),
12+
setup_requires=['setuptools_scm'],
13+
use_scm_version=True,
14+
# include_package_data=True, # Keep this if needed and not configured elsewhere
12315
)

0 commit comments

Comments
 (0)