|
1 | 1 | """ |
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. |
4 | 5 | """ |
5 | 6 |
|
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 |
81 | 8 |
|
| 9 | +# Most metadata is defined in pyproject.toml. |
| 10 | +# This file primarily enables setuptools_scm and handles non-declarative steps. |
82 | 11 | 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 | | - |
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 |
123 | 15 | ) |
0 commit comments