Skip to content

Commit e5339ed

Browse files
committed
Created bump script to update project.urls.Changelog
1 parent 5473ea8 commit e5339ed

6 files changed

Lines changed: 100 additions & 0 deletions

File tree

remove-json-keys/pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ Changelog = "https://github.com/adamlui/python-utils/releases/tag/remove-json-ke
4848
[project.scripts]
4949
remove-json-keys = "remove_json_keys.__main__:main"
5050

51+
[project.optional-dependencies]
52+
dev = [
53+
"tomli>=2.0.0,<3.0.0",
54+
"tomli-w>=0.1.0,<2.0.0",
55+
]
56+
5157
[tool.setuptools.packages.find]
5258
where = [
5359
"src",

remove-json-keys/utils/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
publish.sh

remove-json-keys/utils/bump.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os, logging
2+
import tomli, tomli_w
3+
4+
pkg_name = 'remove-json-keys'
5+
6+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
7+
8+
def update_changelog_url():
9+
pyproject_path = os.path.join(os.path.dirname(__file__), '../pyproject.toml')
10+
logging.debug(f'Reading pyproject.toml from: {pyproject_path}')
11+
if not os.path.exists(pyproject_path):
12+
return logging.error(f'pyproject.toml file not found at {pyproject_path}')
13+
14+
try: # load pyproject.toml
15+
with open(pyproject_path, 'rb') as file : pyproject = tomli.load(file)
16+
logging.debug('Successfully loaded pyproject.toml!')
17+
except Exception as err:
18+
return logging.exception(f'Error loading pyproject.toml: {err}')
19+
20+
version = pyproject.get('project', {}).get('version')
21+
if not version:
22+
return logging.error('Version not found in pyproject.toml.')
23+
24+
changelog_url = f'https://github.com/adamlui/python-utils/releases/tag/{pkg_name}-{version}'
25+
logging.debug(f'Generated changelog URL: {changelog_url}')
26+
27+
if 'urls' not in pyproject['project']:
28+
logging.debug('Adding [project.urls] section to pyproject.toml...')
29+
pyproject['project']['urls'] = {}
30+
31+
if 'Changelog' in pyproject['project']['urls']:
32+
logging.debug('Replacing existing Changelog URL...')
33+
else:
34+
logging.debug('Adding new Changelog URL...')
35+
pyproject['project']['urls']['Changelog'] = changelog_url
36+
37+
try: # write to pyproject.toml
38+
with open(pyproject_path, 'wb') as file : tomli_w.dump(pyproject, file)
39+
logging.info('Updated changelog URL successfully in pyproject.toml!')
40+
except Exception as err:
41+
logging.exception(f'Error writing to pyproject.toml: {err}')
42+
43+
update_changelog_url()

translate-messages/pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ Changelog = "https://github.com/adamlui/python-utils/releases/tag/translate-mess
5757
translate-msgs = "translate_messages.__main__:main"
5858
translate-messages = "translate_messages.__main__:main"
5959

60+
[project.optional-dependencies]
61+
dev = [
62+
"tomli>=2.0.0,<3.0.0",
63+
"tomli-w>=0.1.0,<2.0.0",
64+
]
65+
6066
[tool.setuptools.packages.find]
6167
where = [
6268
"src",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
publish.sh

translate-messages/utils/bump.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os, logging
2+
import tomli, tomli_w
3+
4+
pkg_name = 'translate-messages'
5+
6+
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
7+
8+
def update_changelog_url():
9+
pyproject_path = os.path.join(os.path.dirname(__file__), '../pyproject.toml')
10+
logging.debug(f'Reading pyproject.toml from: {pyproject_path}')
11+
if not os.path.exists(pyproject_path):
12+
return logging.error(f'pyproject.toml file not found at {pyproject_path}')
13+
14+
try: # load pyproject.toml
15+
with open(pyproject_path, 'rb') as file : pyproject = tomli.load(file)
16+
logging.debug('Successfully loaded pyproject.toml!')
17+
except Exception as err:
18+
return logging.exception(f'Error loading pyproject.toml: {err}')
19+
20+
version = pyproject.get('project', {}).get('version')
21+
if not version:
22+
return logging.error('Version not found in pyproject.toml.')
23+
24+
changelog_url = f'https://github.com/adamlui/python-utils/releases/tag/{pkg_name}-{version}'
25+
logging.debug(f'Generated changelog URL: {changelog_url}')
26+
27+
if 'urls' not in pyproject['project']:
28+
logging.debug('Adding [project.urls] section to pyproject.toml...')
29+
pyproject['project']['urls'] = {}
30+
31+
if 'Changelog' in pyproject['project']['urls']:
32+
logging.debug('Replacing existing Changelog URL...')
33+
else:
34+
logging.debug('Adding new Changelog URL...')
35+
pyproject['project']['urls']['Changelog'] = changelog_url
36+
37+
try: # write to pyproject.toml
38+
with open(pyproject_path, 'wb') as file : tomli_w.dump(pyproject, file)
39+
logging.info('Updated changelog URL successfully in pyproject.toml!')
40+
except Exception as err:
41+
logging.exception(f'Error writing to pyproject.toml: {err}')
42+
43+
update_changelog_url()

0 commit comments

Comments
 (0)