Skip to main content

A make-style Python build tool

Project description

mkcode is a system for performing make-style development tasks. It provides execution of dependencies, a console script for calling tasks, and automatic discovery of the distutils commands found in setup.py. It does not provide tools for compiled languages or complex nested builds (look to SCons or zc.buildout for those).

Tasks are defined as plain python functions, decorated with a special @task decorator. The name of the function becomes the name of the task, and that task may be called from the command-line via the mk script.

A file in the project’s root directory named mkfile.py contains all of the task definitions. The mk script, when invoked, imports the tasks.

Here is an example mkfile.py:

from mkcode import *

@task
def clean():
    """ Clean out all .pyc files in sub-directories """
    # This is *great* for getting rid of those stale .pyc files
    # that cause mysterious test failures.
    for pyc in path().relpath().walkfiles('*pyc'):
        print 'Removing:', pyc
        pyc.remove()

setup = namespace('setup')  # the distutils commands from 'setup.py'

# re-define the 'test' target
task('test', [clean, setup.test])

Here is how you run our new test target:

$ mk test

We can still run the original setuptools test target using the setup namepace:

$ mk setup.test

Please see mkfile.py in the distribution’s base directory for more task examples.

Namespaces

Tasks may belong to namespaces. Namespace tasks are called by joining the namespace and task name with a dot, as if you were referencing a Python object attribute:

# call the 'bar' task in the 'foo' namespace
$ mk foo.bar

Please see Jeff Shell’s post for examples of how namespaces are defined and populated.

Setuptools Integration

All of the commands exported by setuptools are available in the setup namespace. However, setuptools’ commands may also be called from the root namespace - invoking them does not require the command to be prefixed with setup. Therefore the following three commands are equivalent:

$ mk develop
$ mk setup.develop
$ python setup.py develop

Other Notes

Extra command-line parameters are passed through to their targets. The following two commands are equivalent:

$ mk rotate --help
$ python setup.py rotate --help

The mk script takes a number of command-line switches, notably -T, which lists all of the registered tasks, -n, which runs a task and its dependencies without executing them, and -f, which allows you to specify an alternative mkfile.

Known Issues

The program fails on vanilla setup.py files that define their own commands. The Python Imaging Library, PIL, is one example of this.

The mk develop command can choke upon first invocation when there is a new package version. In the meantime one can fall back to the setuptools method.

Acknowledgments

This program was heavily inspired by Jeff Shell’s in-house build system. The example targets Jeff provided should work in this system with little modification.

Path support is greatly enhanced by Jason Orendorff’s excellent path module. I highly recommend it for all of your Python work.

Project details


Download files

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

Source Distributions

mkcode-0.2.zip (27.1 kB view details)

Uploaded Source

mkcode-0.2.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkcode-0.2-py2.4.egg (42.9 kB view details)

Uploaded Egg

File details

Details for the file mkcode-0.2.zip.

File metadata

  • Download URL: mkcode-0.2.zip
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mkcode-0.2.zip
Algorithm Hash digest
SHA256 18cd1ac5bdeee0a8c668bddeacdb2000c273e0fc2af0c67bc5f14be1d7b4c9b5
MD5 1aec31921d856b8c08706dcb96e8843c
BLAKE2b-256 68392771faf27de89ffc3edffef727795d355bfaabbe59afadf3f02e50cf25c2

See more details on using hashes here.

File details

Details for the file mkcode-0.2.tar.gz.

File metadata

  • Download URL: mkcode-0.2.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mkcode-0.2.tar.gz
Algorithm Hash digest
SHA256 f5ec9b50557468606d92fcf7af69ec476630c102211fe6186216f46ce41adb96
MD5 91131ad1e15d1ac193b15e5649c145d8
BLAKE2b-256 1ee3089bd88cecabca1140ac321393131ab7f904747e003dca671575003db48a

See more details on using hashes here.

File details

Details for the file mkcode-0.2-py2.4.egg.

File metadata

  • Download URL: mkcode-0.2-py2.4.egg
  • Upload date:
  • Size: 42.9 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mkcode-0.2-py2.4.egg
Algorithm Hash digest
SHA256 0c152fe55fc7a3c8108ca75b1c1b0b90e821ffee9c2160759cbc18fd4b8361cf
MD5 50cf6d398506ccfd54a56dc7709f36c4
BLAKE2b-256 6ce31de3bdd20b75e41c79e21250083b30b1920d3a72c79a1477cc7edb3c5d82

See more details on using hashes here.

Supported by

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