Skip to main content

Python packaging utility library

Project description

travis versions pypi

Introduction

pkutils is a Python library that simplifies python module packaging. It is intended to be used in your package’s setup.py file.

With pkutils, you can

  • Parse requirements files

  • Determine your project’s development status

  • Read text files

  • and much more…

Requirements

pkutils has been tested and is known to work on the following Python versions:

  • 2.7

  • 3.4

  • 3.5

  • pypy v4.0

  • pypy3 v2.4

Motivation

Python has a great packaging system, but to actually create and publish a package requires a lot of work to do well. I designed pkutils to provide many useful packaging use-cases out of the box. For example, to automatically include the contents of your requirements.txt file, simply add the following to setup.py:

import pkutils

...

requirements = list(pkutils.parse_requirements('requirements.txt'))
dev_requirements = list(pkutils.parse_requirements('dev-requirements.txt'))

setup(
    ...
    install_requires=requirements,
    tests_require=dev_requirements,
    ...)

Usage

pkutils is intended to be used directly as a Python library.

setup.py

import pkutils
import my_module

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

requirements = list(pkutils.parse_requirements('requirements.txt'))
dependencies = list(pkutils.parse_requirements('requirements.txt', True))
dev_requirements = list(pkutils.parse_requirements('dev-requirements.txt'))
readme = pkutils.read('README.rst')
version = my_module.__version__
project = my_module.__title__
user = 'reubano'

setup(
    long_description=readme,
    install_requires=requirements,
    tests_require=dev_requirements,
    dependency_links=dependencies,
    url=pkutils.get_url(project, user),
    download_url=pkutils.get_dl_url(project, user, version),
    classifiers=[
        pkutils.LICENSES['MIT'],
        pkutils.get_status(version),
        ...
    ],
    ...
)

This is then converted into something like the following:

...

setup(
    long_description='pkutils: a Python packaging library...',
    install_requires=['semver==2.2.1'],
    tests_require=['semver==2.2.1', 'wheel==0.24.0', 'flake8==2.5.1', ...],
    dependency_links=[],
    url='https://github.com/reubano/pkutils',
    download_url='https://github.com/reubano/pkutils/archive/v0.11.0.tar.gz',
    classifiers=[
        'License :: OSI Approved :: MIT License',
        'Development Status :: 4 - Beta',
        ...
    ],
    ...
)

Installation

(You are using a virtualenv, right?) [1]

At the command line, install pkutils using either pip (recommended)

pip install pkutils

or easy_install

easy_install pkutils

Project structure

┌── CHANGES.rst
├── CONTRIBUTING.rst
├── LICENSE
├── MANIFEST.in
├── Makefile
├── README.md
├── dev-requirements.txt
├── helpers
   ├── check-stage
   ├── clean
   ├── srcdist
   ├── test
   └── wheel
├── manage.py
├── pkutils.py
├── requirements.txt
├── setup.cfg
├── setup.py
├── tests
   ├── __init__.py
   └── standard.rc
└── tox.ini

Design Principles

  • minimize external dependencies

  • prefer functions over objects

  • keep the API as simple as possible

Scripts

pkutils comes with a built in task manager manage.py

Setup

pip install -r dev-requirements.txt

Examples

View available commands

manage

Show help for a given command

manage <command> -h

Run python linter and nose tests

manage lint
manage test

Or if make is more your speed…

make lint
make test

License

pkutils is distributed under the MIT License.

Contributing

Please mimic the coding style/conventions used in this repo. If you add new classes or functions, please add the appropriate doc blocks with examples. Also, make sure the python linter and nose tests pass.

Please see the contributing doc for more details.

Footnotes

If you have virtualenvwrapper installed, at the command line type:

mkvirtualenv pkutils
pip install pkutils

Or, if you only have virtualenv installed:

virtualenv ~/.venvs/pkutils
source ~/.venvs/pkutils/bin/activate
pip install pkutils

Otherwise, you can install globally:

pip install pkutils

Project details


Download files

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

Source Distribution

pkutils-0.12.0.tar.gz (10.8 kB view hashes)

Uploaded Source

Built Distribution

pkutils-0.12.0-py2.py3-none-any.whl (8.3 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page