Skip to main content

Some tools to help build python2/3 source and wheel libraries

Project description

build_utils

Latest Version License image

There is a lot of boiler plate code I would write over and over for my projects, especially when I try to support both python2 and python3. This project aims to simplify it and allows me to easily add update/improvements to all of my projects at once.

Install

Most systems come with python2 installed, but if you plan on doing python3 development then you should install that for your platform. For macOS:

brew install python3

pip

The recommended way to install this library is with pip:

pip install build_utils

Development

If you wish to develop and submit git-pulls, you can do:

git clone https://github.com/walchko/build_utils
cd build_utils
pip install -e .

Usage

To use this package, at a minimum, set your repo up like:

myLibrary/
|
+- myLibrary/
|   |
|   +- src files
+- tests/
|   |
|   +- test.py
+- setup.py

Also add the following to your 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
    }
)

Take a look at the setup for this library on github for an example. Note that by default, testing and both py2 and py3 are True by default. Now you can build and publish a new package by:

python setup.py make
python setup.py publish
python setup.py git

Other

Get some basic system info:

>>> import build_utils as bu
>>> bu.get_system()
System(os='macos', arch='x86_64', kernel='17.5.0', os_version='17.5.0')

Get the version number of a library:

>>> import build_utils as bu
>>> bu.get_pkg_version('build_utils/__init__.py')
"0.2.0"

Tests

This uses nose to run tests and issues the command python -m nose -w tests -v test.py where python will be either python2 or python3 depending on what you enabled.

Now if you have more than one test file, try:

# assume you have test1.py, test2.py and test3.py ... do:
from .test1 import *
from .test2 import *
from .test3 import *

And all should work fine.

image

Publishing

This uses twine by default. Ensure you have a config file setup like in your home directory:

[distutils]
index-servers = pypi

[pypi]
repository: https://pypi.python.org/pypi
username: my-awesome-username
password: super-cool-passworld

Change Log

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

MIT License

Copyright (c) 2017 Kevin J. Walchko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Release history Release notifications

This version
History Node

0.3.2

History Node

0.3.1

History Node

0.3.0

History Node

0.2.7

History Node

0.2.6

History Node

0.2.5

History Node

0.2.4

History Node

0.2.3

History Node

0.2.2

History Node

0.2.1

History Node

0.2.0

History Node

0.1.1

History Node

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
build_utils-0.3.2-py2-none-any.whl (6.7 kB) Copy SHA256 hash SHA256 Wheel py2 Jul 8, 2018
build_utils-0.3.2-py3-none-any.whl (6.7 kB) Copy SHA256 hash SHA256 Wheel py3 Jul 8, 2018
build_utils-0.3.2.tar.gz (9.0 MB) Copy SHA256 hash SHA256 Source None Jul 8, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page