python项目包管理及github配置

1. python包管理

pip + requirements.txt
pipenv + pipfile
poetry + pyproject.yml

2. pip方式

参考文档1:https://blog.csdn.net/qq_25672165/article/details/104945587
参考文档2:https://blog.csdn.net/qq_25672165/article/details/107701935

3. pipenv方式

pipenv发布于2017年1月,它是一种Python依赖管理工具,你可以把它看做是pip和virtualenv的组合体,它基于Pipfile的依赖记录方式,用于替代旧的记录方式requirements.txt。
官方文档:https://pipenv.pypa.io/en/latest/
virtualenv相关:https://blog.csdn.net/qq_25672165/article/details/106030243

安装

pip install pipenv
pipenv --version   # 检测

命令

创建/删除虚拟环境

cd pipenv & pipenv install 
# 在pipenv目录下生成Pipfile和Pipfile.lock,并生成一个随机的虚拟环境目录名

pipenv --rm 

查看项目根目录

pipenv --where 
# pipenv文件目录即为项目跟目录

查看虚拟环境

pipenv --venv
# /Users/whtest/.virtualenvs/pipenv-QiSG3PyN    随机虚拟环境名和路径

虚拟环境操作

pipenv shell  # 进入虚拟环境

pipenv graph   # 查看已安装模块

pipenv install requests   # 安装包

pipenv uninstall requests   # 卸载包

exit    # 推出虚拟环境

requirements.txt文件

生成 requirements.txt
pipenv lock -r > requirements.txt

通过 requirements.txt安装依赖
pipenv install -r requirements.txt

4. poetry

安装配置

安装命令如下,安装完成后自动配置环境变量,位置为:/Users/xx/.poetry/bin。且需要执行source .bash_profilesource .zshrc

curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python3

常用命令

init:项目依赖初始化 ,在项目目录下生成pyproject.toml文件,需要输入常用配置项,其他默认点击enter即可。

poetry init
# 配置项
License []: apache-2.0
Compatible Python versions [^2.7]: ^3.5

add:依赖包添加到pyproject.toml文件中,同时会安装它们

poetry add pytest requests

remove :删除已经安装的依赖包

poetry remove pytest requests

run:会将run之后的命令放到python环境执行

poetry run pytest -v

-h: 帮助文档,查看命令

5. github相关配置

配置travel-ci

官网地址:https://travis-ci.org/,使用github账号登陆后,同步数据开启开关即可

配置单测覆盖率检查

官方网站:https://coveralls.io/,使用github账号登陆后,同步数据开启开关即可

配置徽章

在这里插入图片描述

[![](https://img.shields.io/badge/license-Apache2.0-green.svg?style=flat)](https://github.com/zyanwei2011/ApiFrame)
[![](https://img.shields.io/badge/language-python-blue.svg?style=flat)](https://github.com/zyanwei2011/ApiFrame)

标准项目目录结构

readme: 项目整体介绍及使用手册,一般为README.md或README.rst
LICENCE: 阐述项目的许可和说明
setup.py: 通过setup把核心代码打包发布
sample: 存放项目核心代码
requirements.txt: 存放项目依赖
docs: 包的参考文档
tests: 项目测试代码存放目录
makefile: 用于项目的命令管理(开源项目广泛使用)

猜你喜欢

转载自blog.csdn.net/qq_25672165/article/details/110122217
今日推荐