Skip to content

Commit 84454c7

Browse files
committed
refactor: minor cleanups from code review
- Read VERSION from package metadata instead of hardcoding it in config.py - Add parentheses to clarify operator precedence in po2file - Rename `dir` parameter in find_files to avoid shadowing built-in - Run tests before publish in release workflow
1 parent 8ddb584 commit 84454c7

4 files changed

Lines changed: 9 additions & 5 deletions

File tree

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ jobs:
1414
- name: Install uv
1515
uses: astral-sh/setup-uv@v7
1616

17+
- name: Run tests
18+
run: uv run pytest
19+
1720
- name: Publish to PyPi
1821
if: startsWith(github.ref, 'refs/tags/')
1922
run: |

msg2po/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import os
33

44

5-
def find_files(dir: str, ext: str):
5+
def find_files(directory: str, ext: str):
66
"""
7-
Find files with extension ext in directory dir
7+
Find files with extension ext in directory
88
"""
99
files = []
10-
for root, _subdir_list, file_list in os.walk(dir):
10+
for root, _subdir_list, file_list in os.walk(directory):
1111
for f in file_list:
1212
if get_ext(f) == ext:
1313
files.append(os.path.join(root, f))

msg2po/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
import os
66
from dataclasses import dataclass, field
7+
from importlib.metadata import version as _pkg_version
78
from typing import Any
89

910
import ruamel.yaml
1011
from loguru import logger
1112

12-
VERSION = "1.5.0"
13+
VERSION = _pkg_version("msg2po")
1314

1415
TRANSLATION_DEFAULTS: dict[str, Any] = {
1516
"encoding": "cp1252",

msg2po/conversion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def po2file(
122122
po_index = file_trans["po_index"]
123123
entry = po[po_index]
124124

125-
if entry.msgstr == "" or "fuzzy" in entry.flags and not extract_fuzzy: # if not translated, keep msgid
125+
if entry.msgstr == "" or ("fuzzy" in entry.flags and not extract_fuzzy): # if not translated, keep msgid
126126
value = entry.msgid
127127
else:
128128
value = entry.msgstr # either translated or fuzzy+extract_fuzzy

0 commit comments

Comments
 (0)