Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit 20526d4

Browse files
committed
modified: setup.py
modified: simpletool/__init__.py
1 parent afb73a1 commit 20526d4

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

setup.py

+60-11
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,77 @@ def get_version():
1515

1616
# Update version in __init__.py
1717
init_path = os.path.join('simpletool', '__init__.py')
18-
with open(init_path, 'r', encoding='utf-8') as init_file:
19-
init_content = init_file.read()
18+
try:
19+
with open(init_path, 'r', encoding='utf-8') as init_file:
20+
init_content = init_file.read()
2021

21-
# Replace version in the header
22-
updated_init_content = re.sub(
23-
r'(version:)\s*',
24-
r'\1 ' + version,
25-
init_content
26-
)
22+
# Replace version in the header
23+
updated_init_content = re.sub(
24+
r'version:\s*\d+\.\d+\.\d+',
25+
f'version: {version}',
26+
init_content
27+
)
2728

28-
with open(init_path, 'w', encoding='utf-8') as init_file:
29-
init_file.write(updated_init_content)
29+
with open(init_path, 'w', encoding='utf-8') as init_file:
30+
init_file.write(updated_init_content)
3031

32+
except Exception as e:
33+
print(f"Error updating __init__.py: {e}")
34+
35+
print(f"Found version: {version}")
3136
return version
37+
print("No version found in CHANGELOG.md")
3238
return '0.0.0' # fallback version if not found
3339
except FileNotFoundError:
3440
print("CHANGELOG.md not found!")
3541
return '0.0.0'
3642

43+
def read_version_from_init():
44+
"""Read version from __init__.py as a fallback"""
45+
try:
46+
init_path = os.path.join('simpletool', '__init__.py')
47+
with open(init_path, 'r', encoding='utf-8') as init_file:
48+
init_content = init_file.read()
49+
match = re.search(r'version:\s*(\d+\.\d+\.\d+)', init_content)
50+
if match:
51+
version = match.group(1)
52+
print(f"Version from __init__.py: {version}")
53+
return version
54+
except Exception as e:
55+
print(f"Error reading version from __init__.py: {e}")
56+
return '0.0.0'
57+
58+
def write_version_to_metadata(version):
59+
"""Write version to PKG-INFO metadata file"""
60+
try:
61+
with open('simpletool.egg-info/PKG-INFO', 'r') as f:
62+
content = f.read()
63+
64+
# Replace or add Version
65+
if 'Version:' in content:
66+
content = re.sub(r'Version:.*', f'Version: {version}', content)
67+
else:
68+
content += f'\nVersion: {version}\n'
69+
70+
with open('simpletool.egg-info/PKG-INFO', 'w') as f:
71+
f.write(content)
72+
73+
print(f"Updated PKG-INFO with version: {version}")
74+
except Exception as e:
75+
print(f"Error writing version to metadata: {e}")
76+
77+
# First try to get version from CHANGELOG.md
78+
version = get_version()
79+
80+
# If that fails, try reading from __init__.py
81+
if version == '0.0.0':
82+
version = read_version_from_init()
83+
84+
# Write version to metadata
85+
write_version_to_metadata(version)
3786

3887
setup(name='simpletool',
39-
version=get_version(),
88+
version=version, # Use the version we found
4089
description='simpletool',
4190
url='https://github.com/nchekwa/simpletool-python/tree/master',
4291
author='Artur Zdolinski',

simpletool/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
name: SimpleTools
33
author: Artur Zdolinski
4-
version: 0.0.0
4+
version: 0.0.14
55
"""
66
import asyncio
77
import os

0 commit comments

Comments
 (0)