Skip to main content

xy_settings

简体中文 繁體中文 English

说明

通用设置模块

源码仓库

Github Gitee GitCode

安装

# bash
pip install xy_settings

使用

python脚本
# xy_test_settings.toml
# ######################## xy_work配置 ###########################
# 默认配置文件位置为 当前工作目录下的 config/xy_work.toml


# ######################## xy_work项目配置 ###########################
[xy_work_project]

# 项目名称, 仅支持英文
name = "xy_test_settings"

# 项目标识
identifier = "xy_test_settings"

# 项目名称, 支持中英文
verbose_name = "xy_test_settings"

# 项目说明, 支持中英文
description = "xy_test_settings"

# 项目路径
path = "./"

# ######################## xy_work运行配置 ###########################

[xy_work_runner]

# 服务源码目录自动添加到sys.path 
# 默认 当前项目目录下的 source/Runner
path = "./runner_path"

# 服务入口类,根据上文的path寻找对应的类初始化即为启动,字符串,若包含模块使用module.class根据importlib引入
# 默认 Runner.Runner
runner = "xy_runner"
# main.py
from uuid import uuid4
from pathlib import Path
from xy_settings.Settings import Settings as xy_s
from xy_settings.Section.Section import Section


class Runner(Section):
    path: Path | None = Path("./Runner/")

    # 表示Runner.py中的Runner类
    runner: str | None = "Runner.xyTestRunner"

    source_path: Path | None = Path("./")

    def get_name(self) -> str | None:
        return "xy_work_runner"

    def _load(self):
        self.path = self._fetch_path("path", self.path)
        self.runner = self._sync_data("runner", self.runner)
        super()._load()


class Project(Section):
    name: str | None
    verbose_name: str | None

    identifier: str = uuid4().hex
    description: str | None

    path: Path | None

    def get_name(self) -> str | None:
        return "xy_work_project"

    def _load(self):
        try:
            ##################### fetch_path ###############

            self.path = self._fetch_path("path", self.path)  # type: ignore

            ##################### sync_data ################

            self.name = self._sync_data("name", self.name)
            self.verbose_name = self._sync_data("verbose_name", self.verbose_name)
            self.identifier = self._sync_data("identifier", self.identifier)  # type: ignore
            self.description = self._sync_data("description", self.description)
        except:
            pass
        super()._load()


class Settings(xy_s):
    project: Project | None = Project()
    runner: Runner | None = Runner()
    GLOBAL_CFG_SETTINGS_PATH_KEY = "__xy_work_cfg_path_key"
    default_cfg_relative_path: Path = Path("./xy_test_settings.toml")

    def reload(self, settings_cfg_path: Path):
        super().reload(settings_cfg_path)
        self.project = self.make_section(Project)
        self.runner = self.make_section(Runner)


if __name__ == "__main__":
    settings = Settings()
    settings.reload(Path("./xy_test_settings.toml"))
    print(settings.runner.path)
    
# bash
python main.py
# /mnt/bs-media/Workspace/project/opensource/xy-base/xy_settings/test/runner_path

许可证

xy_settings 根据 <木兰宽松许可证, 第2版> 获得许可。有关详细信息,请参阅 LICENSE 文件。

捐赠

如果小伙伴们觉得这些工具还不错的话,能否请咱喝一杯咖啡呢?

pay-total

联系方式

微信: yuyangiit
邮箱: yuyangit.0515@qq.com

Release files for xy-settings 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xy-settings 1.0.6
File Size Uploaded
xy_settings-1.0.6.tar.gz 10.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xy-settings 1.0.6
File Interpreter ABI Platform
xy_settings-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size:21.0 kB

Release files / xy_settings-1.0.6.tar.gz

Download URL xy_settings-1.0.6.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6ff944dfec709833577908de51e0fb5000146ce81fca1c313be0007e90eb38b4
BLAKE2b-256 checksum
How to use checksums
c8a7497c67c0be61a4868ea53ad3c53785335498ab2228b4bb7113671ccc7e5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.3

Release files / xy_settings-1.0.6-py3-none-any.whl

Download URL xy_settings-1.0.6-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a565eb77dc5d48e86f54c05a5deacacd408a817a32ee17f94f07359362288547
BLAKE2b-256 checksum
How to use checksums
96b5bd36620049246e1c75df9419f6fc16a75549bdeb8fb832fef6b2e335b779
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.3

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page