首页 > 其他分享 >Poetry 的使用

Poetry 的使用

时间:2022-12-07 18:13:57浏览次数:57  
标签:package python fastapi poetry Poetry pytest 使用 yes

什么是poetry?

- 一款python 包的管理和打包工具。 

作为包的管理工具, 我们怎么在项目中 应用呢?

方法1. (适用于新项目, 从模块安装开始)

  1. poetry init.

在此过程中, poetry 会引导用户输入一些关于包的关键信息, 比如包名称, 包的dependency 模块。 参见下面详细log.

此过程会生成pyproject.toml 文件。 

D:\python_poetry2>poetry init

This command will guide you through creating your pyproject.toml config.

Package name [python_poetry2]:  pac3
Version [0.1.0]:
Description []:
Author [DESKTOP-7N9ITBC\mli <[email protected]>, n to skip]:
Invalid author string. Must be in the format: John Smith <[email protected]>
Author [DESKTOP-7N9ITBC\mli <[email protected]>, n to skip]:  n
License []:
Compatible Python versions [^3.10]:

Would you like to define your main dependencies interactively? (yes/no) [yes] yes
You can specify a package in the following forms:
  - A single name (requests): this will search for matches on PyPI
  - A name and a constraint (requests@^2.23.0)
  - A git url (git+https://github.com/python-poetry/poetry.git)
  - A git url with a revision (git+https://github.com/python-poetry/poetry.git#develop)
  - A file path (../my-package/my-package.whl)
  - A directory (../my-package/)
  - A url (https://example.com/packages/my-package-0.1.0.tar.gz)

Package to add or search for (leave blank to skip): fastapi
Found 20 packages matching fastapi
Showing the first 10 matches

Enter package # to add, or the complete package name if it is not listed []:
 [ 0] fastapi
 [ 1] aioauth-fastapi
 [ 2] fastapi-manage
 [ 3] fastapi-oracle
 [ 4] fastapi-viewsets
 [ 5] myapi-fastapi
 [ 6] fastapi-utils
 [ 7] fastapi-crud
 [ 8] fastapi-misskey
 [ 9] fastapi-analytics
 [10]
 > 0
Enter the version constraint to require (or leave blank to use the latest version):
Using version ^0.88.0 for fastapi

Add a package (leave blank to skip):

Would you like to define your development dependencies interactively? (yes/no) [yes] yes
Package to add or search for (leave blank to skip): pytest
Found 20 packages matching pytest
Showing the first 10 matches

Enter package # to add, or the complete package name if it is not listed []:
 [ 0] pytest
 [ 1] pytest123
 [ 2] 131228_pytest_1
 [ 3] pytest-pingguo-pytest-plugin
 [ 4] pytest-symbols
 [ 5] pytest-circleci
 [ 6] pytest-parallel
 [ 7] pytest-grpc
 [ 8] pytest-vnc
 [ 9] pytest-vcrpandas
 [10]
 > 0
Enter the version constraint to require (or leave blank to use the latest version):
Using version ^7.2.0 for pytest

Add a package (leave blank to skip):

Generated file

[tool.poetry]
name = "pac3"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
fastapi = "^0.88.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.2.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


Do you confirm generation? (yes/no) [yes] yes
View Code
  1. 在上面init 的过程中, poetry 并没有真正的去安装模块。 执行命令 poetry install 来创建virtualenv, 并且在virtual env 中安装模块。 

Option Step: Poetry 更改国内安装源。 (49条消息) Python 包管理工具poetry配置国内PyPI镜像源_y_bccl27的博客-CSDN博客_poetry 源

Option Step: Poetry 会创建virtualenv, 如果你想更改virtual env 的路径, 可以用下面这些命令

poetry config --list
cache-dir = "C:\\Code\\python-venv\\poetry-config"   # 此路径是virtualenv 的默认路径, 想改就改

 

标签:package,python,fastapi,poetry,Poetry,pytest,使用,yes
From: https://www.cnblogs.com/hello-pyworld/p/16963879.html

相关文章

  • vim 使用、设置笔记
    设置.vimrc(windows下通常为_vimrc)设置vim中tab的缩进setts=4(注:ts是tabstop的缩写,设TAB宽4个空格)setexpandtab(注:用4个空格代替一个TAB,不设置的话就是一个宽为4......
  • 环境(局部)变量与全局变量的使用
     postman中的变量类型环境变量:实质是局部变量,理论上只能在某个请求中使用,使用时先添加环境变量,然后在窗口右上角选择创建的环境变量,然后在接口地址中或参数值中使用{{......
  • mybatis plus中使用joda-time
    支持JodaDateTime例如Pojo/Mopackagecom.xxx.crud.eo;importcom.baomidou.mybatisplus.annotation.IdType;importcom.baomidou.mybatisplus.annotation.TableFi......
  • 如何使用 Towify 在微信小程序中配置输入必填报错?
    效果展示:   具体步骤:创建数据表创建“创建事件”添加输入框组件配置输入框组件添加按钮组件 步骤分解:创建数据表创建数据表创建......
  • pycharm的使用
    通过快捷键-鼠标滑轮调整字体的大小--待更新......
  • mybatis一级缓存和二级缓存使用详解
    文章目录​​一、概念说明​​​​1、一级缓存​​​​2、二级缓存​​​​3、比较​​​​二、mybatis缓存的生命周期​​​​三、一级缓存的使用​​​​四、二级缓存的使......
  • mybatis-plus雪花算法生成Id使用详解
    文章目录​​前言​​​​一、mybatis-plus官网​​​​二、雪花算法实战​​​​1.建表​​​​2.新建测试工程​​​​3.单元测试​​​​三、实现分析​​​​四、为什么......
  • Centos7上使用yum安装mysql8.x
    文章目录​​前言​​​​一、官方文档​​​​二、安装步骤​​​​1.安装MySQLYumRepository​​​​2.选择要安装的版本​​​​3.检查rpm的签名​​​​4.安装Mysql​......
  • 不使用EXCEPT函数下求差集
    Oracale和SQLSERVER中皆有差集函数去比较两个数据集合中的差异的数据=>EXCEPT使用如下:SELECTFASSETID,FALTERID,FCKFUNDPROVIDEDFROMKDY_T_FA_FUNDBALANCEWHERE......
  • Excel VLOOKUP 函数的使用
    需要注意的几个地方:IFERROR,第一个参数,是需要判断的值VLOOKUP,第二个参数,匹配的区域,第一列,必须是匹配的列。比如:第一个参数是订单号,那么第二个参数的那个区域的第一列......