Python 工程简要学习
简介
- 本文主要对github拉去的某一项目进行学习,需要包含哪些元素,以及如何去完善他。python项目代码如何简要搭建分类。
为了以后更方便功能的扩展和维护十分有必要
工程元素
requirements.txt
- 工程运行需要安装的python库
#Before you can launch , you need to install the following requirements.
pip install -r requirements.txt -i http://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com
#For example, for document operations, it is necessary to install the docx library
version.txt
- 版本说明–可用来记录版本变迁说明及当前版本号
版本控制:版本控制是开发过程中必不可少的一部分。Git是目前最流行的版本控制系统之一,可以帮助团队协作、追踪代码变更、恢复历史版本等。
README.md
文档:良好的文档可以使代码易于理解和维护。可以使用docstring来编写函数和模块级别的文档,也可以使用工具自动生成文档。
# Project Examples
## Table of Contents
- [Project Examples](#Project Examples)
- [Table of Contents](#table-of-contents)
- [Overview](#overview)
- [Folder Structure](#folder-structure)
- [Integrate Your Example With Testing](#integrate-your-example-with-testing)
## Overview
Overall and document function description
## Folder Structure
└─ examples
└─ images
└─ vit
└─ test_ci.sh
└─ train.py
└─ README.md
└─ ...
└─ ...
## Integrate Your Example With Testing
A test demo
### step1
### step2
...
setup.py
- 运行代码的主程序
sh脚本
可利用shell 脚本来执行相应的程序,附带有参数,执行各个功能要素
#!/usr/bin/env bash
set -xue
if [ -z "$PROMPT_PATH" ]; then
echo "Please set \$PROMPT_PATH to the path to prompts csv."
exit 1
fi
BASE=$(realpath $(dirname $0))
export OMP_NUM_THREADS=8
# install requirements
pip install -r ${BASE}/requirements.txt
代码架构
- 代码简单架构如下:
fun1、fun2文件夹为脚本功能的分类,相互引用。后续可以补充fun3、fun4…进行功能扩展
虚拟环境:为了避免不同项目之间的依赖冲突,通常需要使用虚拟环境来隔离每个项目的依赖项。
依赖项:Python工程可能会依赖于其他库或模块。可以使用pip等工具来管理这些依赖项。
测试代码:测试是保证代码质量的重要手段。Python提供了多种测试框架(如pytest、unittest等),可用于编写和运行测试代码。
└─ examples
└─ func1
└─ __init__
└─ 1.py
└─ 2.py
└─ README.md #文件夹功能说明
└─ func2
└─ __init__
└─ 4.py
└─ 3.py
└─ README.md #文件夹功能说明
└─ main.py
└─ README.md
└─ requirements.txt
└─ version.txt
└─ main.sh #执行python脚本--细细研究