|
1 | 1 | from os import path |
| 2 | +from types import SimpleNamespace as sns |
2 | 3 | import sys |
3 | 4 | import tomli, tomli_w |
4 | 5 |
|
5 | 6 | sys.path.insert(0, path.join(path.dirname(__file__), '../src')) |
6 | | -from translate_messages.lib import log # type: ignore |
| 7 | +from translate_messages.lib import log # type: ignore |
7 | 8 |
|
8 | 9 | pyproject_path = path.join(path.dirname(__file__), '../pyproject.toml') |
9 | | -with open(pyproject_path, 'rb') as file: |
10 | | - pkg_name = tomli.load(file)['project']['name'] |
| 10 | +log.info(f'Loading {pyproject_path}...') |
| 11 | +with open(pyproject_path, 'rb') as file : pyproject = tomli.load(file) |
| 12 | +project = sns(**pyproject['project']) |
11 | 13 |
|
12 | 14 | def update_changelog_url(): |
13 | | - |
14 | | - log.info(f'Loading {pyproject_path}...') |
15 | | - with open(pyproject_path, 'rb') as file : pyproject = tomli.load(file) |
16 | | - |
17 | | - ver_tag = f"{pkg_name}-{pyproject['project']['version']}" |
| 15 | + ver_tag = f"{project.name}-{project.version}" |
18 | 16 | changelog_url = f'https://github.com/adamlui/python-utils/releases/tag/{ver_tag}' |
19 | 17 | log.data(f'Generated changelog URL: {changelog_url}') |
20 | 18 |
|
21 | | - if 'urls' not in pyproject['project']: |
| 19 | + if not hasattr(project, 'urls'): |
22 | 20 | log.info('Creating [project.urls] section...') |
23 | | - pyproject['project']['urls'] = {} |
| 21 | + project.urls = {} |
| 22 | + |
| 23 | + log.info(f"{ 'Updating' if 'Changelog' in project.urls else 'Adding new' } Changelog URL...") |
| 24 | + project.urls['Changelog'] = changelog_url |
24 | 25 |
|
25 | | - log.info(f"{ 'Updating' if 'Changelog' in pyproject['project']['urls'] else 'Adding new' } Changelog URL...") |
26 | | - pyproject['project']['urls']['Changelog'] = changelog_url |
| 26 | + pyproject['project'] = vars(project) # convert sns back to dict for dumping |
27 | 27 | with open(pyproject_path, 'wb') as file : tomli_w.dump(pyproject, file) |
28 | 28 |
|
29 | 29 | log.success(f"Bumped changelog URL ver tag to [{ver_tag}]!") |
|
0 commit comments