一些有助于构建python2/3源代码和轮子库的工具
build-utils的Python项目详细描述
构建实用程序
有很多锅炉板代码我会一遍又一遍地为我的
项目,尤其是当我试图同时支持python2
和python3
时。
这个项目的目的是简化它,让我可以很容易地添加
立即更新/改进我的所有项目。
安装
大多数系统都安装了python2
,但是如果您打算这样做
python3
开发然后您应该为您的平台安装它。
对于MacOS:
brew install python3
PIP
建议使用pip
:
pip install build_utils
发展
如果您希望开发并提交git拉取,可以执行以下操作:
git clone https://github.com/walchko/build_utils
cd build_utils
pip install -e .
用法
若要使用此软件包,请至少将您的回购设置为:
myLibrary/
|
+- myLibrary/
| |
| +- src files
+- tests/
| |
| +- test.py
+- setup.py
还可以在您的setup.py
中添加以下内容:
... other imports ... from build_utils import BuildCommand from build_utils import PublishCommand from build_utils import BinaryDistribution from build_utils import SetGitTag VERSION = '1.0.0' PACKAGE_NAME = 'myLibrary' # class to test and build the module BuildCommand.pkg = PACKAGE_NAME BuildCommand.test = True # run all tests, True by default, False, no tests run BuildCommand.py2 = True # test and build python2, True by default BuildCommand.py3 = True # test and build python3, True by default # class to publish the module to PyPi PublishCommand.pkg = PACKAGE_NAME PublishCommand.version = VERSION SetGitTag.version = VERSION setup( name=PACKAGE_NAME, version=VERSION, ... other options ... cmdclass={ 'publish': PublishCommand, # run this to publish to pypi 'make': BuildCommand, # run this to test/build library 'git': SetGitTag # this creates a new tag on your repo } )
以github
上此库的设置为例。
注意,默认情况下,testing和py2和py3都是True
by
违约。现在您可以通过:
python setup.py make
python setup.py publish
python setup.py git
其他
获取一些基本系统信息:
>>>importbuild_utilsasbu>>>bu.get_system()System(os='macos',arch='x86_64',kernel='17.5.0',os_version='17.5.0')
获取库的版本号:
>>>importbuild_utilsasbu>>>bu.get_pkg_version('build_utils/__init__.py')"0.2.0"
测试
它使用nose
运行测试并发出命令
python -m nose -w tests -v test.py
其中python
将是
python2
或python3
取决于您启用的功能。
如果您有多个测试文件,请尝试:
# assume you have test1.py, test2.py and test3.py ... do: from .test1 import * from .test2 import * from .test3 import *
一切都会好起来的。
发布
默认情况下使用twine
。确保您的配置文件设置如下
在主目录中:
[distutils]
index-servers = pypi
[pypi]
repository: https://pypi.python.org/pypi
username: my-awesome-username
password: super-cool-passworld
更改日志
Date | Version | Notes |
---|---|---|
2018-07-08 | 0.3.0 | added git version command and colorama |
2018-06-20 | 0.2.2 | added some helper functions |
2017-04-09 | 0.1.0 | init |
麻省理工学院许可证
版权所有(c)2017 Kevin J.Walchko
特此免费向任何获得 本软件和相关文档文件的副本 “软件”),无限制地处理软件,包括 但不限于使用、复制、修改、合并、发布, 分发、再授权和/或出售软件副本,以及 允许向其提供软件的人员这样做,但须遵守 以下条件:
上述版权公告及本许可公告须包括在内 在软件的所有副本或大部分中。
软件按“原样”提供,不作任何保证, 明示或默示,包括但不限于 适销性、适合特定目的和不侵权。 在任何情况下,作者或版权持有人均不对任何 索赔、损害赔偿或其他责任,无论是在合同诉讼中, 侵权行为或其他,由 软件或软件中的使用或其他交易。