Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,27 @@
```shell
pdm run python project_name/__main__.py
```

## 示例内容说明

- 针对场景:用以直接运行的`Python`项目,除了`Django`和`Python库`有各自的模板以外,一般情况都可以用。

- 用法:创建`Github`仓库时可以选择为模板,已经创建仓库的可以手动参照调整。

- 需要注意修改的:`pyproject.toml` 和 `README` 中的名称和描述;`project_name` 文件夹重命名为项目名称或史诗名称

- 包含内容:`dynaconf` 配置(`project_name/config.py`)、日志配置(`project_name/__main__.py` 与 `settings.yml`)、`pdm` 配置(`pyproject.toml`、`pdm.lock`,默认依赖 `dynaconf、pytest`)、文档结构(`README`、`CHANGELOG`、`docs`(用户文档))、代码目录结构(`tests`(单元测试)、`integrated_tests`(集成测试))、`.gitignore`

- 备注:

- `__main__.py` 是其目录下所有代码的唯一统一入口(如有需要可改名),如有其它需单独运行的简单脚本,在项目根目录下创建 `scripts` 文件夹;如有多个不能一起完成的交付目标(里程碑),在项目根目录下新创建文件夹及其自己的 `__main__.py` 等文件

- 如需跨一级目录(一级目录即项目根目录的下一级)`import` 代码,将`pyproject.toml` 中的 `[tool.pdm] distribution` 改为 `true`,重新执行 `pdm install` 后即可从任意一级目录开始 `import`

- 要指定环境时,在 `settings.yml` 同目录下创建 `.env` 文件以指定环境,内容如 `DYNACONF_STAGE=prod`

- 涉及敏感配置时(各类密码密钥、用户名、我们的服务器地址、IP等),在 `settings.yml` 同目录下创建 `.secrets.yml` 文件(`.gitignore` 末尾已添加 `.secrets.*`)以放置敏感配置

- 有测试数据文件要放时,在 `tests` 或 `integrated_tests` 目录下创建 `sample` 文件夹放置

- 用户文档有图片时,在 `docs` 目录下创建 `images` 文件夹放置
1 change: 1 addition & 0 deletions docs/images/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 用户文档的图片放置于此
1 change: 1 addition & 0 deletions integrated_tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 集成测试代码
1 change: 1 addition & 0 deletions integrated_tests/sample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 在此文件夹下放置集成测试测试数据文件
1 change: 1 addition & 0 deletions project_name/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 项目代码源代码
4 changes: 4 additions & 0 deletions project_name/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# -*- coding: utf-8 -*-
"""
程序启动入口
此文件是该目录下所有代码的唯一统一入口(如有需要可改名)
如有其它需单独运行的简单脚本,在项目根目录下创建 `scripts` 文件夹
如有多个不能一起完成的交付目标(里程碑)
在项目根目录下新创建文件夹及其自己的 `__main__.py` 等文件
"""
import logging

Expand Down
1 change: 1 addition & 0 deletions project_name/scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 在此处放置其它需单独运行的简单脚本
1 change: 1 addition & 0 deletions project_name/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ default:
dev:
test:
prod:

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ dependencies = [
file = "README.md"
content-type = "text/markdown"

# 如需跨一级目录(一级目录即项目根目录的下一级)`import` 代码,
# 将此处的 distribution 改为 true
# 重新执行 pdm install 后即可从任意一级目录开始 import
[tool.pdm]
distribution = false

Expand Down
1 change: 1 addition & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 单元测试代码
1 change: 1 addition & 0 deletions tests/sample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# 在此文件夹下放置单元测试测试数据文件