跳转到主要内容

构建CLI程序的辅助工具

项目描述

cli-base-utilities

tests codecov cli-base-utilities @ PyPi Python Versions License GPL-3.0-or-later

构建CLI程序和一些CLI程序的有用工具的辅助工具。

pip install cli-base-utilities

特性

一些特性包括

待办事项:在此处记录所有特性 ;)

开始开发

~$ git clone https://github.com/jedie/cli-base-utilities.git
~$ cd cli-base-utilities
~/cli-base-utilities$ ./dev-cli.py --help

dev CLI

usage: ./dev-cli.py [-h]
                    {check-code-style,coverage,fix-code-style,install,mypy,pip-audit,publish,test,
tox,update,update-test-snapshot-files,version}



╭─ options ──────────────────────────────────────────────────────────────────────────────────────╮
│ -h, --help        show this help message and exit                                              │
╰────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ subcommands ──────────────────────────────────────────────────────────────────────────────────╮
│ {check-code-style,coverage,fix-code-style,install,mypy,pip-audit,publish,test,tox,update,upda… │
│     check-code-style                                                                           │
│                   Check code style by calling darker + flake8                                  │
│     coverage      Run tests and show coverage report.                                          │
│     fix-code-style                                                                             │
│                   Fix code style of all cli_base source code files via darker                  │
│     install       Run pip-sync and install 'cli_base' via pip as editable.                     │
│     mypy          Run Mypy (configured in pyproject.toml)                                      │
│     pip-audit     Run pip-audit check against current requirements files                       │
│     publish       Build and upload this project to PyPi                                        │
│     test          Run unittests                                                                │
│     tox           Run tox                                                                      │
│     update        Update "requirements*.txt" dependencies files                                │
│     update-test-snapshot-files                                                                 │
│                   Update all test snapshot files (by remove and recreate all snapshot files)   │
│     version       Print version and exit                                                       │
╰────────────────────────────────────────────────────────────────────────────────────────────────╯

app CLI

usage: ./cli.py [-h] {update-readme-history,version}



╭─ options ──────────────────────────────────────────────────────────────────────────────────────╮
│ -h, --help        show this help message and exit                                              │
╰────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ subcommands ──────────────────────────────────────────────────────────────────────────────────╮
│ {update-readme-history,version}                                                                │
│     update-readme-history                                                                      │
│                   Update project history base on git commits/tags in README.md Will be exited  │
│                   with 1 if the README.md was updated otherwise with 0.                        │
│                                                                                                │
│                   Also, callable via e.g.:                                                     │
│                       python -m cli_base update-readme-history -v                              │
│     version       Print version and exit                                                       │
╰────────────────────────────────────────────────────────────────────────────────────────────────╯

DEMO app CLI

usage: ./cli.py [-h]
                {demo-endless-loop,demo-verbose-check-output-error,edit-settings,print-settings,sy
stemd-debug,systemd-remove,systemd-setup,systemd-status,systemd-stop,version}



╭─ options ──────────────────────────────────────────────────────────────────────────────────────╮
│ -h, --help                                                                                     │
│     show this help message and exit                                                            │
╰────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ subcommands ──────────────────────────────────────────────────────────────────────────────────╮
│ {demo-endless-loop,demo-verbose-check-output-error,edit-settings,print-settings,systemd-debug… │
│     demo-endless-loop                                                                          │
│     Just a useless example command, used in systemd DEMO: It just print some information in a  │
│     endless loop.                                                                              │
│     demo-verbose-check-output-error                                                            │
│     DEMO for a error calling cli_base.cli_tools.subprocess_utils.verbose_check_output()        │
│     edit-settings                                                                              │
│     Edit the settings file. On first call: Create the default one.                             │
│     print-settings                                                                             │
│     Display (anonymized) MQTT server username and password                                     │
│     systemd-debug                                                                              │
│     Print Systemd service template + context + rendered file content.                          │
│     systemd-remove                                                                             │
│     Write Systemd service file, enable it and (re-)start the service. (May need sudo)          │
│     systemd-setup                                                                              │
│     Write Systemd service file, enable it and (re-)start the service. (May need sudo)          │
│     systemd-status                                                                             │
│     Display status of systemd service. (May need sudo)                                         │
│     systemd-stop                                                                               │
│     Stops the systemd service. (May need sudo)                                                 │
│     version                                                                                    │
│     Print version and exit                                                                     │
╰────────────────────────────────────────────────────────────────────────────────────────────────╯

根据git提交/标签生成项目历史

将类似于 cli_base/tests/test_readme_history.py 的测试用例添加到您的项目中。在您的README中添加所需的 start/end 注释。

要发布新版本,请执行以下操作

  • 增加您的项目版本号
  • 运行测试以更新README
  • 提交更改
  • 创建发布

建议使用 git hookd(通过 pre-commit)来更新README。为此,请将 .pre-commit-config.yaml 添加到您的项目中。

[tool.cli_base]
version_module_name = "<your_package>" # Must provide the `__version__` attribute

.pre-commit-config.yaml 复制并粘贴到您的项目中。

pre-commit 添加到您的需求中,并通过以下方式安装git钩子

.venv/bin/pre-commit install
.venv/bin/pre-commit autoupdate

更新pre-commit钩子

.pre-commit-config.yaml 中更新版本并发布。

问题:如果“新”版本尚未标记,钩子会损坏。要创建发布,可以使用带有 --no-verify 的所有git命令(提交、推送等)以跳过钩子。

暂时卸载钩子、创建发布并再次安装钩子会更简单,例如

.../cli-base-utilities$ .venv/bin/pre-commit uninstall
# ...bump version, commit, push, merge... create release...
.../cli-base-utilities$ .venv/bin/pre-commit install

历史记录

  • v0.13.1
    • 2024-09-26 - 修复缺少click的问题。为向后兼容性添加它
  • v0.13.0
    • 2024-09-26 - 添加tyro辅助工具并用自己的CLI替换click
  • v0.12.0
    • 2024-09-25 - 在update_readme_history调用中添加调试日志
    • 2024-09-25 - 将AssertCliHelpInReadme简化为扁平函数
    • 2024-09-25 - 应用项目管理工作更新
    • 2024-09-25 - 更新要求
  • v0.11.0
    • 2024-08-30 - 应用manageprojects更新,例如:将最小Python版本设置为3.11+
    • 2024-08-30 - 新增:EncloseRuleContext
扩展较早的历史条目 ...
  • v0.10.3
    • 2024-08-05 - 修复toml设置中不可更改的布尔标志
  • v0.10.2
    • 2024-08-04 - 自动激活pre-commit钩子
    • 2024-08-04 - 更新demo CLI:始终更新pip和pip-tools
    • 2024-08-04 - 在CLI脚本中处理KeyboardInterrupt。
    • 2024-08-04 - 修复Bugfix #50 toml2dataclass(): AttributeError: 'bool'对象没有unwrap属性。
    • 2024-08-02 - 修复README.md中的文档链接
  • v0.10.1
    • 2024-08-02 - 将默认超时时间从5分钟增加到15分钟
    • 2024-08-02 - 将pre-commit钩子版本更新到cli-base-utilities v0.10.0
  • v0.10.0
    • 2024-08-02 - 在get_commit_date()中使用dateutil
    • 2024-08-02 - 将"safety"替换为"pip-audit"并添加相应的工具。
    • 2024-08-01 - 更新manageprojects更新
  • v0.9.0
    • 2024-07-16 - 更新项目
  • v0.8.0
    • 2024-03-12 - 修复发布
    • 2024-03-12 - 修复测试
    • 2024-03-12 - 将app/dev CLI拆分为具有自动发现的包
    • 2024-03-12 - 移动click默认值
    • 2024-03-12 - 应用cookiecutter模板更新
    • 2024-03-12 - 更新要求
    • 2024-01-16 - 在测试中使用typeguard
    • 2024-01-16 - manageprojects更新
    • 2024-01-16 - 更新要求 + datetimes ;)
    • 2023-12-17 - 修复Bugfix .pre-commit-config.yaml
  • v0.7.0
    • 2023-12-16 - 在README中添加"更新pre-commit钩子"
    • 2023-12-16 - 修复update_readme_history(): 使用模块中的__version__
    • 2023-12-16 - 新增:使用"pre-commit"的"update-readme-history" git钩子
    • 2023-12-16 - 修复测试
    • 2023-12-16 - 修复类型提示
    • 2023-12-16 - 将update-readme-history添加到app CLI
    • 2023-12-16 - 将DEM0移动到./cli_base/demo/
    • 2023-12-16 - 简化App CLI
    • 2023-12-16 - 从app CLI中删除PACKAGE_ROOT
    • 2023-12-16 - 更新要求
    • 2023-12-16 - 在CI上跳过test_readme_history()
  • v0.6.0
    • 2023-12-02 - 新增:代码风格工具
  • v0.5.0
    • 2023-12-01 - 修复flake8
    • 2023-12-01 - 新增:测试工具:AssertLogs()上下文管理器
    • 2023-12-01 - 修复flake8:如果SUDO_USER与当前用户相同,则修复expand_user()
    • 2023-12-01 - 将"run_coverage()"添加到"dev_tools"并润色tox、unittest
    • 2023-12-01 - 添加EraseCoverageData()的测试
    • 2023-12-01 - 应用manageprojects更新
  • v0.4.5
    • 2023-11-30 - 通过"load_tests协议"钩子配置unittests
    • 2023-11-30 - 更新要求并添加"flake8-bugbear"
    • 2023-11-30 - 删除函数参数中的函数调用
  • v0.4.4
    • 2023-11-01 - 修复Bugfix "AssertionError: Expected only one line" in Git.first_commit_info()
  • v0.4.3
    • 2023-11-01 - Git历史渲染器:折叠较旧条目
  • v0.4.2
    • 2023-11-01 - 删除重复的git提交并只保留最后一个测试提交,例如:"更新要求"
    • 2023-11-01 - 修复git历史:添加第一个标签之前的提交
  • v0.4.1
    • 2023-10-08 - 从历史中删除提交URL并处理发布新版本
    • 2023-10-08 - 新增:根据git提交/标签生成项目历史
    • 2023-10-08 - 更新要求
    • 2023-09-26 - 更新README.md
  • v0.4.0
    • 2023-09-24 - 修复测试
    • 2023-09-24 - 添加UpdateTestSnapshotFiles()上下文管理器
    • 2023-09-24 - coverage:重构设置并添加辅助工具
    • 2023-09-24 - 更新要求
  • v0.3.0
    • 2023-08-17 - 修复终端中运行的测试
    • 2023-08-17 - 更新要求
    • 2023-08-17 - 新增:cli_base.cli_tools.git和cli_base.cli_tools.version_info
  • v0.2.0
    • 2023-08-09 - 项目设置更新
    • 2023-05-22 - 更新README.md
    • 2023-05-22 - 将项目“cli-base”重命名为“cli-base-utilities”
    • 2023-05-22 - 添加github CI配置
    • 2023-05-22 - 从manageprojects添加subprocess_utils
    • 2023-05-21 - 初始化

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

cli_base_utilities-0.13.1.tar.gz (101.5 kB 查看哈希值)

上传时间 源代码

构建分发

cli_base_utilities-0.13.1-py3-none-any.whl (82.4 kB 查看哈希值)

上传时间 Python 3

由以下机构支持