向setup.py里添加自定义command
向setup.py
里添加自定义command
参考这里
继承distutils.cmd.Command
类:
class CCleanCommand(distutils.cmd.Command):
"""clean the source code and the .c file after building .so"""
# 命令的描述,会出现在`python setup.py --help`里
description = 'clean the source code and the .c file after building .so'
# 该命令的所有选项,包括需要给值的选项,以及只是当个flag用的binary选项
user_options = [
# 格式是`(长名字,短名字,描述)`,描述同样会出现在doc里
# binary选项,长名字后面没有等号,最后的值会传给`self.<长名字>`,使用形式`--restore`/`-r`
('restore', 'r', 'moving the source back to its dir'),
# 需要值的选项,长名字后面有等号,最后的值会传给`self.<长名字>`(-会用_代替),使用形式`--key-value=<val>`/`-k <val>`
('key-value=', 'k', 'example for key=value option')
]
def initialize_options(self):
"""设置选项的默认值, 每个选项都要有初始值,否则报错"""
self.restore = False
self.key_value = 123
def finalize_options(self):
"""接收到命令行传过来的值之后的处理, 也可以什么都不干"""
print("restore=", self.restore)
print("key_value=", self.key_value)
self.key_value = f'{self.key_value}'+".exe"
def run(self):
"""命令运行时的操作"""
print("======= command is running =======")
if self.restore:
print('good')
else:
print(self.key_value)
然后需要在setup
函数里设置好:
setup(
...,
cmdclass={
'cclean': CCleanCommand
}
)
然后就可以通过python setup.py cclean
来使用了:
>>> python setup.py cclean
running cclean
restore= False
key_value= 123
======= command is running =======
123.exe
>>> python setup.py cclean -r
running cclean
restore= 1
key_value= 123
======= command is running =======
good
>>> python setup.py cclean --restore
running cclean
restore= 1
key_value= 123
======= command is running =======
good
>>> python setup.py cclean --restore=1
报错
>>> python setup.py cclean --key-value=456
running cclean
restore= False
key_value= 456
======= command is running =======
456.exe
>>> python setup.py cclean -k 456
running cclean
restore= False
key_value= 456
======= command is running =======
456.exe
>>> python setup.py cclean -k=456
running cclean
restore= False
key_value= =456
======= command is running =======
=456.exe
向setup.py里添加自定义command的更多相关文章
- How To Add Custom Build Steps and Commands To setup.py
转自:https://jichu4n.com/posts/how-to-add-custom-build-steps-and-commands-to-setuppy/ A setup.py scrip ...
- python包管理(distutils、easy_install、pip、setup.py/requirements.txt、wheel)
distutils.distutils2 distutils是 python 标准库的一部分,2000年发布.使用它能够进行 python 模块的 安装 和 发布. distutils2 被设计为 d ...
- Command "python setup.py egg_info" failed with error code 10
1:今天系统重装以后,下载了新的版本的python3.6.1.然后想通过pycurl模块测试URL,突然发现windows10下我无法通过pip安装pycurl模块了,报错内容如下 Collectin ...
- Command "python setup.py egg_info" failed with error code 1一种问题的解决方法
问题描述:无论是你在pycharm中直接使用import and install命令,还是pip的时候出现了Command "python setup.py egg_info" f ...
- Command "python setup.py egg_info" failed with error code 1 in C:\Users\w5659\AppData\Local\Temp\pip-install-t7uomu4r\xa dmin\
Error msg: C:\Users\w5659>pip install xadmin Collecting xadmin Using cached https://files.pythonh ...
- pip安装mysql-python报错:Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-enRreC/mysql-python/
公司业务开发,用python开发网站;需要使用模块MySQLdb. 我直接pip install MySQLdb,当然不成功了,模块名字因该是mysql-python pip install mysq ...
- python2 使用pip安装psycopg2出现错误:Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-mvzdNj/psycopg2/
公司业务需求,开发语言python2,需要使用数据库:postgresql,需要安装模块psycopg2这个模块, 使用pip install psycopg2 报错: Command "p ...
- Command "python setup.py egg_info" failed with error code 1 in c:\users\w5659\appdata\local\temp\pip-build-fs2yzl\ipython\
Error Msg: Collecting ipython Using cached https://files.pythonhosted.org/packages/5b/e3/4b3082bd7f6 ...
- 解决Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-f8IeEI/MYSQL-python/
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-f8IeEI/MYS ...
随机推荐
- 学习java 7.15
学习内容: 进程:正在运行的程序 是系统进行资源分配和调用的独立单位 每个进程都有它自己的内存空间和系统资源 线程:是进程中的单个顺序控制流,是一条执行路径 单线程:一个进程如果只有一条执行路径,则称 ...
- day02 Linux基础
day02 Linux基础 1.什么是服务器 服务器,也称伺服器,是提供计算服务的设备.由于服务器需要响应服务请求,并进行处理,因 此一般来说服务器应具备承担服务并且保障服务的能力. windows: ...
- 从面试官的角度,聊聊java面试流程
在这篇回答里,就讲以我常规的面试流程为例,说下java方面大致会问什么问题,以及如何确认候选人达到招聘要求. 先说面试前准备,可能有些面试官是拿到简历直接问,而且是在候选人自我介绍时再草草浏览简历,但 ...
- 网口程序udp
# -*- coding: utf-8 -*- """ Created on Thu Nov 12 15:02:53 2020 @author: Administrato ...
- Oracle中的索引
1.Oracle 索引简介 在Oracle数据库中,存储的每一行数据都有一个rowID来标识.当Oracle中存储着大量的数据时,意味着有大量的rowID,此时想要快速定位指定的rowID, ...
- When should we write our own assignment operator in C++?
The answer is same as Copy Constructor. If a class doesn't contain pointers, then there is no need t ...
- CDN服务的含义
CDN的全称是Content Delivery Network,即内容分发网络.CDN的基本原理是广泛采用各种缓存服务器,将这些缓存服务器分布到用户访问相对集中的地区或网络中,在用户访问网站时,利用全 ...
- 优化器统计跟踪(SYS.EXP_HEAD$ SYS.EXP_OBJ$ SYS.EXP_STAT$不)导致表空间 SYSAUX不断增长
资料来自support文档 ID 2354960.1 环境: aws rds 19c(亚马逊云oracle 数据库) 背景: 在一次查看数据库表段的占用空间大小的时候,无意间发现其中EXP_开头的表占 ...
- Sysenter/Kifastcallentry hook 检测与恢复
关于Sysenter.Kifastcallentry.中断之类的内核入口hook技术早就烂大街了,可是对hook的检测与恢复代码却是寥寥无几,一切抛开代码将原理的行为都是耍流氓. 下面以Sysente ...
- 『学了就忘』Linux系统管理 — 86、查看系统资源相关命令
目录 1.vmstat命令 2.dmesg命令 3.free命令 4.查看CPU信息 5.查看本机登陆用户信息 (1)w命令 (2)who命令 6.uptime命令 7.查看系统与内核相关信息 1.v ...