Skip to content

Commit 389bcf6

Browse files
committed
Used sns
1 parent 56743d1 commit 389bcf6

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

remove-json-keys/utils/bump.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
from os import path
2+
from types import SimpleNamespace as sns
23
import sys
34
import tomli, tomli_w
45

56
sys.path.insert(0, path.join(path.dirname(__file__), '../src'))
6-
from remove_json_keys.lib import log # type: ignore
7+
from remove_json_keys.lib import log # type: ignore
78

89
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'])
1113

1214
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}"
1816
changelog_url = f'https://github.com/adamlui/python-utils/releases/tag/{ver_tag}'
1917
log.data(f'Generated changelog URL: {changelog_url}')
2018

21-
if 'urls' not in pyproject['project']:
19+
if not hasattr(project, 'urls'):
2220
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
2425

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
2727
with open(pyproject_path, 'wb') as file : tomli_w.dump(pyproject, file)
2828

2929
log.success(f"Bumped changelog URL ver tag to [{ver_tag}]!")

translate-messages/utils/bump.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
from os import path
2+
from types import SimpleNamespace as sns
23
import sys
34
import tomli, tomli_w
45

56
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
78

89
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'])
1113

1214
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}"
1816
changelog_url = f'https://github.com/adamlui/python-utils/releases/tag/{ver_tag}'
1917
log.data(f'Generated changelog URL: {changelog_url}')
2018

21-
if 'urls' not in pyproject['project']:
19+
if not hasattr(project, 'urls'):
2220
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
2425

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
2727
with open(pyproject_path, 'wb') as file : tomli_w.dump(pyproject, file)
2828

2929
log.success(f"Bumped changelog URL ver tag to [{ver_tag}]!")

0 commit comments

Comments
 (0)