模块中常用操作的工具
olutils的Python项目详细描述
绝对值
简介
模块olutils提供了简化项目创建的通用工具它包括:
- 使用logger类
- 参数管理
- 对象管理(复制、保存、加载)
安装
可以使用pip install命令安装olutils:
pip install olutils
用法
使用时间转换器和deep defaultdict:
importolutils# Building a deep default dict with datetimes as valuesflights=olutils.deepdefaultdict(lambdax:None,depth=2)# Filling itflights['Paris-NY']['departure']=olutils.str2dt("2019-01-15 08:00+01:00")flights['Paris-NY']['arrival']=olutils.str2dt("2019-01-15 10:30-05:00")flights['NY-Paris']['departure']=olutils.str2dt("2019-01-17 23:00-05:00")flights['NY-Paris']['arrival']=olutils.str2dt("2019-01-15 11:00+01:00")flights.pprint()
文件读取和对象存储:
importolutilsmy_dict={'key_1':"value_1",'key_2':2}my_rows=[{'col_1':11,'col_2':21},{'col_1':21,'col_2':22}]olutils.save(my_dict,"output/my_dict.json")olutils.save(my_rows,"output/my_rows.csv")olutils.save(my_rows,"output/my_rows.unknown",mthd="json")my_loaded_dict=olutils.load("output/my_dict.json")my_loaded_rows=olutils.load("output/my_rows.csv")my_loaded_rows_=olutils.load("output/my_rows.unknown",mthd="json")
对于开发人员
下载项目
使用代码克隆它:
git clone https://github.com/OctaveLauby/olutils.git
cd olutils
可以进行可编辑的代码安装:
pip install -e .
虚拟环境
使用新的pipenv功能(pip install pipenv
)
pipenv install
pipenv shell
...
exit
注释:
不必导入Matplotlib:在这种情况下不加载打印子模块
也可以使用经典的虚拟环境:
python -m venv venv
source venv/Scripts/activate
python -m pip install -r requirements.txt
...
deactivate
分布
- 生成清单文件:
check-manifest --create
- 制造轮子:
python setup.py bdist_wheel
- 构建源分布:
python setup.py sdist
- 发布:
python setup.py bdist_wheel sdist twine upload dist/*
For TestPyPi publication:
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Not working on Git terminal for some reason
测试
python -m pytest olutils -vv
python -m pylint olutils --ignore-patterns=test*