在您的需求及其底层库中查找已弃用功能
项目描述
Wardoff
Wardoff(发音为ward off
)旨在通过主动收集有关您的堆栈中所有底层库的信息,帮助您保持代码库干净和最新。
Wardoff会为您抓取有关堆栈的许多信息,它可以用于
- 查找项目需求及其底层库中的已弃用内容
- 抓取需求信息(详细或不详细)(参见
infos
部分中的示例) - 将源代码转换为Python令牌
对于每个分析,都会构建一个专门的Python虚拟环境,并在其中安装项目需求。然后逐个分析安装的项目需求中的源代码文件。
需求代码分析基于AST和python tokens。以这种方式逐个分析每个底层库的每个源代码文件。
您可以传递一个约束列表来应用于您的分析,以确保匹配正确的底层库版本。
传统上,项目维护者通过阅读文档或观察日志中的弃用警告来了解函数将变得已弃用或被删除。当您的堆栈增长且堆栈中的需求数量增加时,保持最新状态可能会很痛苦。wardoff旨在通过仅使用一个命令来为您收集所有这些信息,而无需设置任何运行时环境。
安装
仍在开发中且非常不稳定,但是您可以使用以下方法安装不稳定的开发版本
$ python3 -m pip install --user wardoff
需求
- python3.8+
- git
用法
查找堆栈中的已弃用内容
此处的目标是分析给定项目的所有需求,以从它们的代码中提取已弃用内容。
从命名包中
从命名包(直接从pypi)中找到已弃用内容
$ wardoff niet # will list all deprecations founds in niet is requirements
$ wardoff oslo.messaging # will list all deprecations founds in oslo.messaging is requirements
$ wardoff oslo.messaging==12.2.2 # will list all deprecations founds in oslo.messaging 12.2.2 is requirements
$ wardoff oslo.messaging==1.3.0 # will list all deprecations founds in oslo.messaging 1.3.0 is requirements
从当前目录中
从当前工作目录检索已弃用内容。
从以下内容检索需求
requirements.txt
测试-requirements.txt
*-requirements.txt
**/*requirements.txt
示例
$ wardoff # will list all deprecations founds in requirements founds in current directory
从本地仓库
从distgit仓库检索已弃用的事物。
从以下内容检索需求
requirements.txt
测试-requirements.txt
*-requirements.txt
**/*requirements.txt
示例
$ wardoff ~/dev/nova # from a local clone of openstack/nova
从远程仓库
(即将推出 - 尚未实现)
从distgit仓库检索已弃用的事物。
示例
$ wardoff https://opendev.org/openstack/nova/ # from opendev.org
$ wardoff https://github.com/openstack/nova # from github.com
$ wardoff git@github.com:openstack/nova # by using git format
tokenizer
Wardoff提供了一个CLI tokenizer,可用于针对通过CLI传递的代码或通过传递文件路径和特定行进行读取。
通过CLI传递原始代码的示例
$ wardoff-tokenizer "def person(name, age):"
TokenInfo(type=62 (ENCODING), string='utf-8', start=(0, 0), end=(0, 0), line='')
TokenInfo(type=1 (NAME), string='def', start=(1, 0), end=(1, 3), line='def person(name, age):')
TokenInfo(type=1 (NAME), string='person', start=(1, 4), end=(1, 10), line='def person(name, age):')
TokenInfo(type=54 (OP), string='(', start=(1, 10), end=(1, 11), line='def person(name, age):')
TokenInfo(type=1 (NAME), string='name', start=(1, 11), end=(1, 15), line='def person(name, age):')
TokenInfo(type=54 (OP), string=',', start=(1, 15), end=(1, 16), line='def person(name, age):')
TokenInfo(type=1 (NAME), string='age', start=(1, 17), end=(1, 20), line='def person(name, age):')
TokenInfo(type=54 (OP), string=')', start=(1, 20), end=(1, 21), line='def person(name, age):')
TokenInfo(type=54 (OP), string=':', start=(1, 21), end=(1, 22), line='def person(name, age):')
TokenInfo(type=4 (NEWLINE), string='', start=(1, 22), end=(1, 23), line='')
TokenInfo(type=0 (ENDMARKER), string='', start=(2, 0), end=(2, 0), line='')
通过传递文件行进行标记化的另一个示例
wardoff-tokenizer ~/dev/wardoff/wardoff/tokenizer.py+12
它将标记文件~/dev/wardoff/wardoff/tokenizer.py
的第12行
有关此命令的更多选项
$ wardoff-tokenizer -h
infos
Wardoff允许您检索所有依赖项的信息。它将提供类似于pip show
的输出,但它将打印与给定包相关的所有依赖项。返回的输出还包含pypi分类器和一些有用的信息,这些信息不是由pip show
返回的。您可以将此命令视为一个高级pip show
,其中您可以应用不同类型的过滤器(请参阅下面的示例)
示例
$ wardoff-infos oslo.cache
-----
name: certifi
version: 2020.6.20
sources_path: /tmp/wardoff-25781/lib/python3.8/site-packages/certifi
summary: Python package for providing Mozilla's CA Bundle.
home-page: https//certifiio.readthedocs.io/en/latest/
author: Kenneth Reitz
author-email: me@kennethreitz.com
license: MPL-2.0
location: /tmp/wardoff-25781/lib/python3.8/site-packages
requires:
required-by: requests
Development Status :: 5 - Production/Stable
Intended Audience :: Developers
License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
Natural Language :: English
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
-----
name: chardet
version: 3.0.4
sources_path: /tmp/wardoff-25781/lib/python3.8/site-packages/chardet
summary: Universal encoding detector for Python 2 and 3
home-page: https//github.com/chardet/chardet
author: Daniel Blanchard
author-email: dan.blanchard@gmail.com
license: LGPL
location: /tmp/wardoff-25781/lib/python3.8/site-packages
requires:
required-by: requests
Development Status :: 4 - Beta
Intended Audience :: Developers
License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.6
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Topic :: Software Development :: Libraries :: Python Modules
Topic :: Text Processing :: Linguistic
-----
...
以前,已显示包信息和分类器,例如,这可以允许您找到不支持特定Python版本的包。
此外,您可以使用wardoff-infos
获取更多信息,例如,您可以检索堆栈中所有项目的首页
$ wardoff-infos oslo.cache --keep-env --filter home-page --no-separator --no-key
https//certifiio.readthedocs.io/en/latest/
https//github.com/chardet/chardet
https//docs.openstack.org/debtcollector/latest
https//github.com/micheles/decorator
https//github.com/sqlalchemy/dogpile.cache
https//github.com/kjd/idna
https//bitbucket.org/micktwomey/pyiso8601
https//msgpack.org/
https//github.com/drkjam/netaddr/
https//github.com/al45tair/netifaces
https//docs.openstack.org/oslo.config/latest/
https//docs.openstack.org/oslo.context/latest/
https//docs.openstack.org/oslo.i18n/latest
https//docs.openstack.org/oslo.log/latest
https//docs.openstack.org/oslo.serialization/latest/
https//docs.openstack.org/oslo.utils/latest/
https//github.com/pypa/packaging
https//docs.openstack.org/pbr/latest/
http//github.com/seb-m/pyinotify
https//github.com/pyparsing/pyparsing/
https//dateutil.readthedocs.io
http//pythonhosted.org/pytz
https//github.com/yaml/pyyaml
https//requests.pythonlang.cn
http//rfc3986.readthedocs.io
https//github.com/benjaminp/six
https//docs.openstack.org/stevedore/latest/
https//urllib3.readthedocs.io/
https//github.com/GrahamDumpleton/wrapt
或检索分析堆栈的主要维护者(此处为oslo.cache)
$ wardoff-infos oslo.cache --filter author --no-separator --no-key | sort | uniq
Alastair Houghton
Andrey Petrov
Benjamin Peterson
Daniel Blanchard
David P. D. Moss, Stefan Nordhausen et al
Donald Stufft and individual contributors
Graham Dumpleton
Gustavo Niemeyer
Ian Stapleton Cordasco
Inada Naoki
Kenneth Reitz
Kim Davies
Kirill Simonov
Michael Twomey
Michele Simionato
Mike Bayer
OpenStack
Paul McGuire
Sebastien Martini
Stuart Bishop
另一个有用的选项是--support
选项,它允许您检索仅支持特定Python版本的项目。您可以混合支持的版本,例如,检索支持给定版本的项目的要求,示例
$ wardoff-infos oslo.cache --no-separator --support 2.7,3.4 --filter name --no-key
chardet
decorator
idna
netifaces
packaging
pyinotify
pyparsing
pytz
rfc3986
wrapt
前面的示例正在寻找同时支持Python 2.7和3.4的要求,显示的结果符合此条件。
这里还有一个例子
$ wardoff-infos oslo.cache --no-separator --support 3.7,3.8 --filter name --no-key
certifi
idna
msgpack
netaddr
oslo.config
oslo.context
oslo.i18n
oslo.log
oslo.serialization
packaging
pyparsing
PyYAML
requests
urllib3
wrapt
此类过滤器可用于关注您的某些开发或工作在特定的Python版本上。
freeze
Wardoff允许您冻结已安装的依赖项。它将提供类似于pip freeze
的输出,但它只会打印与给定包相关的依赖项。
示例
$ wardoff-freeze oslo.messaging==1.3.0
amqp==2.6.0
Babel==2.8.0
certifi==2020.6.20
chardet==3.0.4
debtcollector==2.2.0
dnspython==2.0.0
eventlet==0.25.2
greenlet==0.4.16
idna==2.10
iso8601==0.1.12
kombu==4.6.11
monotonic==1.5
netaddr==0.8.0
oslo.config==8.3.1
oslo.i18n==5.0.0
pbr==5.4.5
pytz==2020.1
PyYAML==5.3.1
requests==2.24.0
rfc3986==1.4.0
six==1.15.0
stevedore==3.2.0
urllib3==1.25.10
vine==1.3.0
wrapt==1.12.1
Wardoff的环境
要在您的笔记本电脑上运行wardoff,您可以命名并重复使用它们。所有生成的环境都可以通过传递--keep-env
来保留,或销毁(默认情况下,在每次执行后销毁当前生成的环境)。
您可以使用wardoff-list-env
列出您的环境,或使用--wardoff-rm-env
删除所有环境。
如果您在命令中传递了一个名称,并且该环境已存在,则将重新使用该环境,例如
$ wardoff-freeze ~/dev/redhat/upstream/openstack/oslo/oslo.cache --ignore-extra-req --keep-env --env oslo-cache -vvv
INFO: Reusing an existing environment /tmp/wardoff-oslo-cache
certifi==2020.6.20
chardet==3.0.4
debtcollector==2.2.0
decorator==4.4.2
dogpile.cache==1.0.1
idna==2.10
iso8601==0.1.12
msgpack==1.0.0
netaddr==0.8.0
netifaces==0.10.9
oslo.config==8.3.1
oslo.context==3.1.0
oslo.i18n==5.0.0
oslo.log==4.3.0
oslo.serialization==4.0.0
oslo.utils==4.4.0
packaging==20.4
pbr==5.4.5
pyinotify==0.9.6
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2020.1
PyYAML==5.3.1
requests==2.24.0
rfc3986==1.4.0
six==1.15.0
stevedore==3.2.0
urllib3==1.25.10
wrapt==1.12.1
在上面的命令中,我们重新使用了一个名为oslo-cache
的现有环境,并在命令末尾要求保留此环境以再次重复使用。如果该环境不存在,则将自动创建。
输出的详细程度
您可以通过传递-v
选项来增加所有命令的输出详细程度。您传递的v越多,详细程度就越高。例如,-vvv
将显示错误、警告、信息和调试日志。
此选项可能有助于调试某些情况并观察正在发生的事情。
wardoff的未来
我们计划引入更多功能,如问题、拉取请求或补丁收集。
项目详情
wardoff-0.7.1.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a155f108010e699705992c2ea5c076f58501424a9ae171307dce95607320546f |
|
MD5 | e4e5e35fd6916fe27114fcae39dda739 |
|
BLAKE2b-256 | f2973f47148a16f5641a1aadb144f5daeb9fcd0a675b79a2094441c8c4979600 |