Skip to content

Commit 4ef3594

Browse files
Merge pull request #31 from pescheckit/hotfix_fixed-all-issues-and-tested
Fixed linting and building
2 parents 7eba005 + 1e23cc1 commit 4ef3594

File tree

16 files changed

+290
-246
lines changed

16 files changed

+290
-246
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ __pycache__
66
build/
77
db.sqlite3
88
.venv
9-
python_gpt_po/version.py
9+
python_gpt_po/_version.py
10+
CLAUDE.md

CLAUDE.md

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

docker-entrypoint.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e
33

44
# Display help information if no arguments are provided
55
if [ $# -eq 0 ]; then
6-
VERSION=$(gpt-po-translator --version | cut -d' ' -f2)
6+
VERSION=$(python -m python_gpt_po.main --version)
77
echo "GPT PO Translator Docker Container v$VERSION"
88
echo "==========================================="
99
echo
@@ -33,15 +33,15 @@ fi
3333

3434
# Check if we need to display version
3535
if [ "$1" = "--version" ]; then
36-
gpt-po-translator --version
36+
python -m python_gpt_po.main --version
3737
exit 0
3838
fi
3939

4040
# Check if we need to display help
4141
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
42-
gpt-po-translator --help
42+
python -m python_gpt_po.main --help
4343
exit 0
4444
fi
4545

4646
# Execute command with args
47-
exec gpt-po-translator "$@"
47+
exec python -m python_gpt_po.main "$@"

pyproject.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
[build-system]
2-
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]==8.1.0"]
2+
requires = ["setuptools>=61.0", "wheel", "setuptools_scm>=6.2"]
33
build-backend = "setuptools.build_meta"
44

5+
[tool.setuptools]
6+
# Use find with namespaces=True to handle nested packages
7+
packages = { find = { exclude = ["*.__pycache__", "*.__pycache__.*"], namespaces = true } }
8+
59
[tool.setuptools_scm]
610
fallback_version = "0.1.0"
711
write_to = "python_gpt_po/_version.py"
812

913
[project]
10-
name = "gpt_po_translator"
14+
name = "gpt-po-translator"
1115
dynamic = ["version"]
1216
authors = [
1317
{name = "Bram Mittendorff", email = "[email protected]"},
@@ -36,7 +40,6 @@ classifiers = [
3640
"Topic :: Software Development :: Localization",
3741
"Topic :: Text Processing :: Linguistic",
3842
"Operating System :: OS Independent",
39-
"License :: OSI Approved :: MIT License",
4043
"Programming Language :: Python :: 3",
4144
"Programming Language :: Python :: 3.8",
4245
"Programming Language :: Python :: 3.9",
@@ -57,4 +60,4 @@ gpt-po-translator = "python_gpt_po.main:main"
5760
max-line-length = 120
5861

5962
[tool.isort]
60-
line_length = 120
63+
line_length = 120

python_gpt_po/__init__.py

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,52 @@
44
with support for multiple AI providers including OpenAI and Anthropic.
55
"""
66

7-
try:
8-
from ._version import version as __version__
9-
except ImportError:
10-
__version__ = "0.1.0"
7+
import os
8+
import subprocess
9+
from typing import Optional
10+
11+
12+
def _get_version_from_git() -> Optional[str]:
13+
"""
14+
Try to get version from git.
15+
16+
Returns:
17+
Optional[str]: Git version or None if not available
18+
"""
19+
try:
20+
# Check if we're in a git repo
21+
is_git_repo = subprocess.run(
22+
["git", "rev-parse", "--is-inside-work-tree"],
23+
stdout=subprocess.PIPE,
24+
stderr=subprocess.PIPE,
25+
text=True,
26+
check=False
27+
).returncode == 0
28+
if is_git_repo:
29+
# Get version from git describe
30+
return subprocess.check_output(
31+
["git", "describe", "--tags"],
32+
stderr=subprocess.STDOUT,
33+
text=True
34+
).strip()
35+
except (subprocess.SubprocessError, FileNotFoundError):
36+
pass
37+
return None
38+
39+
40+
# Version priority:
41+
# 1. Environment variable PACKAGE_VERSION (for Docker/CI environments)
42+
# 2. _version.py from setuptools_scm (for installed packages)
43+
# 3. Git describe (for development environments)
44+
# 4. Fallback to "0.1.0"
45+
if 'PACKAGE_VERSION' in os.environ:
46+
__version__ = os.environ.get('PACKAGE_VERSION')
47+
else:
48+
try:
49+
from ._version import version as __version__ # noqa
50+
except ImportError:
51+
git_version = _get_version_from_git()
52+
if git_version:
53+
__version__ = git_version
54+
else:
55+
__version__ = "0.1.0"

python_gpt_po/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ def setup_logging():
3333
def initialize_provider(args) -> tuple[ProviderClients, ModelProvider, str]:
3434
"""
3535
Initialize the provider client and determine the appropriate model.
36-
36+
3737
Args:
3838
args: Command line arguments from argparse
39-
39+
4040
Returns:
4141
tuple: (provider_clients, provider, model)
42-
42+
4343
Raises:
4444
SystemExit: If no valid provider can be found or initialized
4545
"""
@@ -87,13 +87,13 @@ def get_appropriate_model(
8787
) -> str:
8888
"""
8989
Get the appropriate model for the provider.
90-
90+
9191
Args:
9292
provider (ModelProvider): The selected provider
9393
provider_clients (ProviderClients): The initialized provider clients
9494
model_manager (ModelManager): The model manager instance
9595
requested_model (Optional[str]): Model requested by the user
96-
96+
9797
Returns:
9898
str: The appropriate model ID
9999
"""
@@ -125,7 +125,7 @@ def process_translations(config: TranslationConfig, folder: str,
125125
batch_size: int):
126126
"""
127127
Process translations for the given languages and directory.
128-
128+
129129
Args:
130130
config (TranslationConfig): The translation configuration
131131
folder (str): Directory containing .po files

python_gpt_po/models/provider_clients.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self):
1919

2020
def initialize_clients(self, api_keys: Dict[str, str]):
2121
"""Initialize API clients for all providers with available keys.
22-
22+
2323
Args:
2424
api_keys (Dict[str, str]): Dictionary of provider names to API keys
2525
"""

python_gpt_po/services/model_manager.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ def validate_model(provider_clients: ProviderClients, provider: ModelProvider, m
8181
"""
8282
Validates whether the specified model is available for the given provider.
8383
Uses prefix matching so that a shorthand (e.g. "claude") will match a full model name.
84-
84+
8585
Args:
8686
provider_clients (ProviderClients): The initialized provider clients
8787
provider (ModelProvider): The provider to check against
8888
model (str): The model name/ID to validate
89-
89+
9090
Returns:
9191
bool: True if the model is valid, False otherwise
9292
"""
@@ -99,10 +99,10 @@ def validate_model(provider_clients: ProviderClients, provider: ModelProvider, m
9999
def get_default_model(provider: ModelProvider) -> str:
100100
"""
101101
Returns the default model for a given provider.
102-
102+
103103
Args:
104104
provider (ModelProvider): The provider to get the default model for
105-
105+
106106
Returns:
107107
str: The default model ID
108108
"""
@@ -128,7 +128,7 @@ def verify_model_capabilities(
128128
provider (ModelProvider): The provider to check against
129129
model (str): The model to verify
130130
required_capability (str): The capability to check for
131-
131+
132132
Returns:
133133
bool: True if the model has the required capability, False otherwise
134134
"""
@@ -147,12 +147,12 @@ def suggest_model(provider_clients: ProviderClients, provider: ModelProvider,
147147
task: str = "translation") -> str:
148148
"""
149149
Suggests the best model for a given task and provider.
150-
150+
151151
Args:
152152
provider_clients (ProviderClients): The initialized provider clients
153153
provider (ModelProvider): The provider to use
154154
task (str): The task the model will be used for
155-
155+
156156
Returns:
157157
str: The suggested model ID
158158
"""

python_gpt_po/services/po_file_handler.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ def disable_fuzzy_translations(po_file_path):
4848
@staticmethod
4949
def get_file_language(po_file_path, po_file, languages, folder_language):
5050
"""Determines the language for a .po file.
51-
51+
5252
Args:
5353
po_file_path (str): Path to the .po file
5454
po_file (polib.POFile): Loaded PO file object
5555
languages (List[str]): List of valid language codes
5656
folder_language (bool): Whether to infer language from folder structure
57-
57+
5858
Returns:
5959
str or None: The normalized language code or None if not found
6060
"""
@@ -76,10 +76,10 @@ def get_file_language(po_file_path, po_file, languages, folder_language):
7676
@staticmethod
7777
def normalize_language_code(lang):
7878
"""Convert language name or code to ISO 639-1 code.
79-
79+
8080
Args:
8181
lang (str): Language name or code to normalize
82-
82+
8383
Returns:
8484
str or None: The normalized ISO 639-1 language code or None if not found
8585
"""
@@ -109,7 +109,7 @@ def normalize_language_code(lang):
109109
@staticmethod
110110
def log_translation_status(po_file_path, original_texts, translations):
111111
"""Logs the status of translations for a .po file.
112-
112+
113113
Args:
114114
po_file_path (str): Path to the .po file
115115
original_texts (List[str]): List of original texts to translate
@@ -133,7 +133,7 @@ def log_translation_status(po_file_path, original_texts, translations):
133133
@staticmethod
134134
def update_po_entry(po_file, original_text, translated_text):
135135
"""Updates a .po file entry with the translated text.
136-
136+
137137
Args:
138138
po_file (polib.POFile): The PO file object
139139
original_text (str): The original text to find
@@ -149,10 +149,10 @@ def update_po_entry(po_file, original_text, translated_text):
149149
@staticmethod
150150
def read_po_file(po_file_path):
151151
"""Reads a .po file and returns the PO file object.
152-
152+
153153
Args:
154154
po_file_path (str): Path to the .po file
155-
155+
156156
Returns:
157157
polib.POFile: The loaded PO file object
158158
"""
@@ -165,11 +165,11 @@ def read_po_file(po_file_path):
165165
@staticmethod
166166
def save_po_file(po_file, po_file_path):
167167
"""Saves changes to a .po file.
168-
168+
169169
Args:
170170
po_file (polib.POFile): The PO file object to save
171171
po_file_path (str): Path where the file should be saved
172-
172+
173173
Returns:
174174
bool: True if successful, False otherwise
175175
"""
@@ -184,10 +184,10 @@ def save_po_file(po_file, po_file_path):
184184
@staticmethod
185185
def get_untranslated_entries(po_file):
186186
"""Gets all untranslated entries from a PO file.
187-
187+
188188
Args:
189189
po_file (polib.POFile): The PO file object
190-
190+
191191
Returns:
192192
List[polib.POEntry]: List of untranslated entries
193193
"""
@@ -196,10 +196,10 @@ def get_untranslated_entries(po_file):
196196
@staticmethod
197197
def extract_metadata(po_file):
198198
"""Extracts and returns metadata from a PO file.
199-
199+
200200
Args:
201201
po_file (polib.POFile): The PO file object
202-
202+
203203
Returns:
204204
dict: Dictionary containing metadata
205205
"""

python_gpt_po/services/translation_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TranslationService:
2424

2525
def __init__(self, config: TranslationConfig, batch_size: int = 40):
2626
"""Initialize the translation service.
27-
27+
2828
Args:
2929
config (TranslationConfig): Configuration for the translation service
3030
batch_size (int): Size of batches for bulk translation

0 commit comments

Comments
 (0)