惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Palo Alto Networks Blog
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Schneier on Security
Engineering at Meta
Engineering at Meta
I
InfoQ
L
LangChain Blog
Cyberwarzone
Cyberwarzone
T
Tenable Blog
WordPress大学
WordPress大学
P
Privacy & Cybersecurity Law Blog
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Jina AI
Jina AI
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
博客园 - 三生石上(FineUI控件)
酷 壳 – CoolShell
酷 壳 – CoolShell
Know Your Adversary
Know Your Adversary
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Last Watchdog
The Last Watchdog
Last Week in AI
Last Week in AI
Cloudbric
Cloudbric
S
SegmentFault 最新的问题
爱范儿
爱范儿
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
AI
AI
T
Tor Project blog
I
Intezer
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
N
News and Events Feed by Topic
Latest news
Latest news
S
Security Affairs
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog RSS Feed
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
S
Securelist

Django - 分类 - cywhat's blog

Django操作异步任务 ValueError:invalid UnorderedObjectListWarning:Pagination May Yield Inconsistent Results With an Unordered Object_list Django删除表重建 Django的csrf防御机制 Django连接Mysql配置 RuntimeWarning:DateTimeField Session.expire_date received a naive datetime fonts.googleapis.com访问较慢[已解决] Django中的form表单校验
Python创建并上传自己的pip依赖包
cywhat · 2023-05-25 · via Django - 分类 - cywhat's blog

1、前景

写工具的过程中,发现if-else用的很频繁,如果条件很多的时候,传统的if-else不但不美观,而且效率低,网上参考了edgedb的思路后,秉承着前人栽树后人乘凉的原则于是封装了优化if-else的函数,并且萌生了上传到pypi用来服务大家

2、注册Pypi

点我注册Pypi

/img/img77.png

3、创建github项目

点我注册github

3.1、下载项目

1
git clone https://github.com/chaoyangya/conditionevaluatortool.git   # 这里的conditionevaluatortool替换为新建的工程名称

3.2、创建必要工程目录

1
2
3
4
5
6
7
8
9
conditionevaluatortool          
├── /conditionevaluator/
│  ├── __init__.py
│  ├── conditionevaluator.py
├── /test/
│  ├── __init__.py
│  ├── test.py
├── README.md
└── setup.py

3.3、工程目录详解

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# 工程名称
conditionevaluatortool

# pip_name模块名称文件夹
/conditionevaluator/

# 引入模块
__init__.py

# pip_name模块名称的函数文件
conditionevaluator.py

# 占位
/test/

# 模块设置
setup.py

# 阅读文件
README.md

3.4、模块设置文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import setuptools
import pathlib

here = pathlib.Path(__file__).parent.resolve()
long_description = (here / "README.md").read_text(encoding="utf-8")

setuptools.setup(
    # 模块名(pip install conditionevaluator)
    name="conditionevaluator",
    # 版本
    version="1.0.1",
    # 作者
    author="cy what",
    # 邮箱
    author_email="[email protected]",
    # 描述
    description="Package of modules that encapsulate the if else multi-condition judgment",
    # 长描述
    long_description=long_description,
    # 长描述格式
    long_description_content_type="text/markdown",
    # github地址
    url="https://github.com/chaoyangya/conditionevaluator",
    # 安装的包
    packages = ['conditionevaluator'],
    # License
    license="conditionevaluator",
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Intended Audience :: Developers",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.7",
        "Programming Language :: Python :: 3.8",
        "Programming Language :: Python :: 3.9",
        "Programming Language :: Python :: 3.10",
        "Programming Language :: Python :: 3 :: Only",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",

    ],
    # 搜索词
    keywords="conditionevaluator, conditionevaluator_python",
)

4、编译

4.1、编译

4.2、生成发版的压缩包

1
2
# 压缩
python3 setup.py sdist

5、发布到Pypi

1
2
3
4
5
6
7
# 安装依赖
pip3 install twine

# 发布
twine upload dist/*

#输入账号密码即可

6、更新Pypi包

1
2
3
4
5
6
7
# 1、修改版本号

# 2、重新编译打包
python3 setup.py sdist bdist

# 3、发布
twine upload dist/xxx.tar.gz    # xxx.tar.gz为最新压缩后的包名

7、验证

/img/img78.png

7.1、安装

1
2
# 安装
pip install conditionevaluator

7.2、使用

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 引入
from conditionevaluator.conditionevaluator import conditionevaluator

# 使用
@conditionevaluator
def doorType(door):
    """
    条件1
    :param door: 门类型  2  --> 双开门
    :return: bool
    """
    return "门类型错误"


@doorType.register(1)
def params_door_type_1(door):
    """
    条件2
    :param door:
    :return: False
    """
    count = 1
    return count

8、conditionevaluator使用教程

关注一下再走吧

公众号 小程序

赞赏支持

微信打赏 支付宝打赏