Table of Contents

python3-utils Documentation

This repository contains a useful collection of python3 utilities.

Installation

To install the latest release, type:

pip install python3-utils

To install the latest code directly from source, type:

pip install git+git://github.com/micahhausler/python3-utils.git

Code documentation

compare_on_attr

class python3_utils.compare_on_attr(attr='id')

A decorator for comparing class attributes. By default, the decorator searches for an ‘id’ attribute on your class, but other attributes can be specified. The original use for this decorator is to compare Django models in Pandas DataFrames.

This decorator assumes the class you are decorating has the appropriate attribute, and will raise an error when comparing a class without the correct attribute.

Usage:

@compare_on_attr()
class MyModel(object):
    id = None
    def __init__(self, id):
        self.id = id

>>> m1 = MyModel(1)
>>> m2 = MyModel(2)
>>> m2 > m1
True

# or

@compare_on_attr(attr='count')
class MyClass(object):
    count = None

Contributing

Contributions and issues are most welcome! All issues and pull requests are handled through github on the micahhausler repository. Also, please check for any existing issues before filing a new one. If you have a great idea but it involves big changes, please file a ticket before making a pull request! We want to make sure you don’t spend your time coding something that might not fit the scope of the project.

Development Setup

To get all the development libraries, run:

$ git clone git://github.com/micahhausler/python3-utils.git
$ cd python3-utils
$ virtualenv env
$ . env/bin/activate
$ pip install -e .[all]

Running the tests

To get the source source code and run the unit tests, run:

$ pip install -e .[test]
$ python setup.py install
$ python setup.py nosetests

While 100% code coverage does not make a library bug-free, it significantly reduces the number of easily caught bugs! Please make sure coverage is at 100% before submitting a pull request!

Code Quality

For code quality, please run flake8:

$ pip install -e .[test]
$ flake8 .

Code Styling

Please arrange imports with the following style

# Standard library imports
import os

# Third party package imports
from mock import patch

# Local package imports
from python3_utils.version import __version__

Please follow Google’s python style guide wherever possible.

Building the docs

When in the project directory:

$ pip install -e .[docs]
$ python setup.py build_sphinx
$ open docs/_build/html/index.html

Release Checklist

Before a new release, please go through the following checklist:

  • Bump version in python3_utils/version.py

  • Add a release note in docs/release_notes.rst

  • Git tag the version

  • Upload to pypi:

    pip install -e .[packaging]
    python setup.py sdist bdist_wheel upload
    

Release Notes

v0.4.0

  • Fixed __eq__ and __ne__ where ‘other’ doesn’t have attribute.

v0.3

  • compare_on_attr decorator no longer checks that class has attribute

v0.2

  • Fixed tests for Python 2

v0.1

  • This is the initial release of python3-utils.