xy-settings


Namexy-settings JSON
Version 1.0.3 PyPI version JSON
download
home_pageNone
Summary项目设置模块
upload_time2024-10-21 02:13:25
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11.3
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!--
 * @Author: yuyanget 845262968@qq.com
 * @Date: 2024-10-19 18:34:54
 * @LastEditors: yuyanget 845262968@qq.com
 * @LastEditTime: 2024-10-19 19:47:22
 * @FilePath: /xy_settings/README.md
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
# xy_settings

- [简体中文](readme/README_zh_CN.md)
- [繁体中文](readme/README_zh_TW.md)
- [English](readme/README_en.md)

## 说明

通用设置模块

## 源码仓库

- <a href="https://github.com/xy-base/xy_settings.git" target="_blank">Github地址</a>  
- <a href="https://gitee.com/xy-base/xy_settings.git" target="_blank">Gitee地址</a>

## 安装

```bash
pip install xy_settings
```

## 使用

###### python脚本

```toml
# 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"

```

```python
# 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
```



## 捐赠

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

![Pay-Total](./readme/Pay-Total.png)


## 联系方式

```
微信: yuyangiit
邮箱: 845262968@qq.com
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "xy-settings",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11.3",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "helios <yuyang.0515@qq.com>",
    "download_url": "https://files.pythonhosted.org/packages/a6/1c/abb7f5210f5e829f61273d431d7e26ffd37825c40da01ee1d7c71720334c/xy_settings-1.0.3.tar.gz",
    "platform": null,
    "description": "<!--\n * @Author: yuyanget 845262968@qq.com\n * @Date: 2024-10-19 18:34:54\n * @LastEditors: yuyanget 845262968@qq.com\n * @LastEditTime: 2024-10-19 19:47:22\n * @FilePath: /xy_settings/README.md\n * @Description: \u8fd9\u662f\u9ed8\u8ba4\u8bbe\u7f6e,\u8bf7\u8bbe\u7f6e`customMade`, \u6253\u5f00koroFileHeader\u67e5\u770b\u914d\u7f6e \u8fdb\u884c\u8bbe\u7f6e: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE\n-->\n# xy_settings\n\n- [\u7b80\u4f53\u4e2d\u6587](readme/README_zh_CN.md)\n- [\u7e41\u4f53\u4e2d\u6587](readme/README_zh_TW.md)\n- [English](readme/README_en.md)\n\n## \u8bf4\u660e\n\n\u901a\u7528\u8bbe\u7f6e\u6a21\u5757\n\n## \u6e90\u7801\u4ed3\u5e93\n\n- <a href=\"https://github.com/xy-base/xy_settings.git\" target=\"_blank\">Github\u5730\u5740</a>  \n- <a href=\"https://gitee.com/xy-base/xy_settings.git\" target=\"_blank\">Gitee\u5730\u5740</a>\n\n## \u5b89\u88c5\n\n```bash\npip install xy_settings\n```\n\n## \u4f7f\u7528\n\n###### python\u811a\u672c\n\n```toml\n# xy_test_settings.toml\n# ######################## xy_work\u914d\u7f6e ###########################\n# \u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\u4f4d\u7f6e\u4e3a \u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u4e0b\u7684 config/xy_work.toml\n\n\n# ######################## xy_work\u9879\u76ee\u914d\u7f6e ###########################\n[xy_work_project]\n\n# \u9879\u76ee\u540d\u79f0, \u4ec5\u652f\u6301\u82f1\u6587\nname = \"xy_test_settings\"\n\n# \u9879\u76ee\u6807\u8bc6\nidentifier = \"xy_test_settings\"\n\n# \u9879\u76ee\u540d\u79f0, \u652f\u6301\u4e2d\u82f1\u6587\nverbose_name = \"xy_test_settings\"\n\n# \u9879\u76ee\u8bf4\u660e, \u652f\u6301\u4e2d\u82f1\u6587\ndescription = \"xy_test_settings\"\n\n# \u9879\u76ee\u8def\u5f84\npath = \"./\"\n\n# ######################## xy_work\u8fd0\u884c\u914d\u7f6e ###########################\n\n[xy_work_runner]\n\n# \u670d\u52a1\u6e90\u7801\u76ee\u5f55\u81ea\u52a8\u6dfb\u52a0\u5230sys.path \n# \u9ed8\u8ba4 \u5f53\u524d\u9879\u76ee\u76ee\u5f55\u4e0b\u7684 source/Runner\npath = \"./runner_path\"\n\n# \u670d\u52a1\u5165\u53e3\u7c7b\uff0c\u6839\u636e\u4e0a\u6587\u7684path\u5bfb\u627e\u5bf9\u5e94\u7684\u7c7b\u521d\u59cb\u5316\u5373\u4e3a\u542f\u52a8\uff0c\u5b57\u7b26\u4e32\uff0c\u82e5\u5305\u542b\u6a21\u5757\u4f7f\u7528module.class\u6839\u636eimportlib\u5f15\u5165\n# \u9ed8\u8ba4 Runner.Runner\nrunner = \"xy_runner\"\n\n```\n\n```python\n# main.py\nfrom uuid import uuid4\nfrom pathlib import Path\nfrom xy_settings.Settings import Settings as xy_s\nfrom xy_settings.Section.Section import Section\n\n\nclass Runner(Section):\n    path: Path | None = Path(\"./Runner/\")\n\n    # \u8868\u793aRunner.py\u4e2d\u7684Runner\u7c7b\n    runner: str | None = \"Runner.xyTestRunner\"\n\n    source_path: Path | None = Path(\"./\")\n\n    def get_name(self) -> str | None:\n        return \"xy_work_runner\"\n\n    def _load(self):\n        self.path = self._fetch_path(\"path\", self.path)\n        self.runner = self._sync_data(\"runner\", self.runner)\n        super()._load()\n\n\nclass Project(Section):\n    name: str | None\n    verbose_name: str | None\n\n    identifier: str = uuid4().hex\n    description: str | None\n\n    path: Path | None\n\n    def get_name(self) -> str | None:\n        return \"xy_work_project\"\n\n    def _load(self):\n        try:\n            ##################### fetch_path ###############\n\n            self.path = self._fetch_path(\"path\", self.path)  # type: ignore\n\n            ##################### sync_data ################\n\n            self.name = self._sync_data(\"name\", self.name)\n            self.verbose_name = self._sync_data(\"verbose_name\", self.verbose_name)\n            self.identifier = self._sync_data(\"identifier\", self.identifier)  # type: ignore\n            self.description = self._sync_data(\"description\", self.description)\n        except:\n            pass\n        super()._load()\n\n\nclass Settings(xy_s):\n    project: Project | None = Project()\n    runner: Runner | None = Runner()\n    GLOBAL_CFG_SETTINGS_PATH_KEY = \"__xy_work_cfg_path_key\"\n    default_cfg_relative_path: Path = Path(\"./xy_test_settings.toml\")\n\n    def reload(self, settings_cfg_path: Path):\n        super().reload(settings_cfg_path)\n        self.project = self.__make_section(Project)\n        self.runner = self.__make_section(Runner)\n\n\nif __name__ == \"__main__\":\n    settings = Settings()\n    settings.reload(Path(\"./xy_test_settings.toml\"))\n    print(settings.runner.path)\n    \n```\n\n\n```bash\npython main.py\n# /mnt/bs-media/Workspace/project/opensource/xy-base/xy_settings/test/runner_path\n```\n\n\n\n## \u6350\u8d60\n\n\u5982\u679c\u5c0f\u4f19\u4f34\u4eec\u89c9\u5f97\u8fd9\u4e9b\u5de5\u5177\u8fd8\u4e0d\u9519\u7684\u8bdd\uff0c\u80fd\u5426\u8bf7\u54b1\u559d\u4e00\u676f\u5496\u5561\u5462?  \n\n![Pay-Total](./readme/Pay-Total.png)\n\n\n## \u8054\u7cfb\u65b9\u5f0f\n\n```\n\u5fae\u4fe1: yuyangiit\n\u90ae\u7bb1: 845262968@qq.com\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "\u9879\u76ee\u8bbe\u7f6e\u6a21\u5757",
    "version": "1.0.3",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "79ee280d4d78ab731415a2ab2a588c51118ef027cd89c344ed4198db11a9d8c7",
                "md5": "c9ef4bfa69ac85faf13838a82876a545",
                "sha256": "cc89ce2833467b8a8831399c68a6e369145db39297c1c4219d2b688ba2e9bd49"
            },
            "downloads": -1,
            "filename": "xy_settings-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c9ef4bfa69ac85faf13838a82876a545",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11.3",
            "size": 7024,
            "upload_time": "2024-10-21T02:13:23",
            "upload_time_iso_8601": "2024-10-21T02:13:23.244634Z",
            "url": "https://files.pythonhosted.org/packages/79/ee/280d4d78ab731415a2ab2a588c51118ef027cd89c344ed4198db11a9d8c7/xy_settings-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a61cabb7f5210f5e829f61273d431d7e26ffd37825c40da01ee1d7c71720334c",
                "md5": "d62beee5d84f7783cdd2e7aab0dae9fa",
                "sha256": "1321d9c0fc14abdf64b6cf8803b4538185fb3b9d99e96d4bfe8412c18f6be904"
            },
            "downloads": -1,
            "filename": "xy_settings-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "d62beee5d84f7783cdd2e7aab0dae9fa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11.3",
            "size": 7054,
            "upload_time": "2024-10-21T02:13:25",
            "upload_time_iso_8601": "2024-10-21T02:13:25.150389Z",
            "url": "https://files.pythonhosted.org/packages/a6/1c/abb7f5210f5e829f61273d431d7e26ffd37825c40da01ee1d7c71720334c/xy_settings-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-21 02:13:25",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "xy-settings"
}
        
Elapsed time: 0.50275s