Package resources

This commit is contained in:
Yax 2024-12-09 17:18:23 +01:00
parent f5fc48e909
commit 9bd8b8b594
3 changed files with 22 additions and 4 deletions

View file

@ -30,6 +30,8 @@ test:
# build # build
build: build:
# https://stackoverflow.com/questions/24347450/how-do-you-add-additional-files-to-a-wheel
rm -rf build/* dist/* *.egg-info
uv build --wheel --out-dir dist uv build --wheel --out-dir dist
docker build -t kianby/stacosys . docker build -t kianby/stacosys .

View file

@ -26,3 +26,16 @@ dev = [
"pytest>=8.3.4", "pytest>=8.3.4",
"black>=24.10.0", "black>=24.10.0",
] ]
[tool.setuptools]
package-dir = { "" = "src" } # Specify the root directory for packages
packages = ["stacosys"]
[tool.setuptools.package-data]
# Include `.properties` and `.html` files in the specified directories
"stacosys.i18n" = ["*.properties"]
"stacosys.interface.templates" = ["*.html"]
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

View file

@ -1,6 +1,6 @@
import configparser import configparser
import os import os
import importlib.resources
class Messages: class Messages:
def __init__(self): def __init__(self):
@ -8,9 +8,12 @@ class Messages:
def load_messages(self, lang): def load_messages(self, lang):
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(
os.path.join(os.path.dirname(__file__), "messages_" + lang + ".properties") # Access the resource file within the package
) with importlib.resources.open_text(
__package__, f"messages_{lang}.properties"
) as file:
config.read_file(file)
for key, value in config.items("messages"): for key, value in config.items("messages"):
self.property_dict[key] = value self.property_dict[key] = value