Skip to main content

Basic Template system for project skeleton.

Project description

skeleton is similar to the template part of PasteScript but without any dependencies; it is also compatible with Python 3.

Requirements

  • Python 2.5+ (python 2.6+ to use the default template formatter)

It currently only has been tested with Python 2.5, 2.6 and 3.1 on Mac OSX.

Installation

The easiest way to get skeleton is if you have setuptools / distribute or pip installed:

easy_install skeleton

or:

pip install skeleton

The current development version can be found at http://github.com/dinoboff/skeleton/tarball/master.

Usage example

Let’s create a basic module template; one with a setup.py, a README and the module files.

First, create the skeleton script layout:

mkmodule.py
basic-module/README
basic-module/setup.py_tmpl
basic-module/{ModuleName}.py

mkmodule.py

mkmodule.py is the script that create new module:

#!/usr/bin/env python

from skeleton import Skeleton, Var


class BasicModule(Skeleton):
    src = 'basic-module'
    vars = [
        Var('ModuleName'),
        Var('Author'),
        Var('AuthorEmail'),
        ]


def main():
    BasicModule.cmd()

if __name__ == '__main__':
    main()

The src attribute sets the relative path to the skeleton directory where the script will find the files and directories to create.

The vars attribute list the variables the templates will require. The variables with a default can be left blank by the user.

Skeleton.cmd() is a convenient method to set an optparser and the logging basic config, and to apply the skeleton:

Usage: mkmodule.py [options] dst_dir

Options:
  -h, --help            show this help message and exit
  -q, --quiet
  -v, --verbose
  -d, --debug
  --ModuleName=MODULENAME
                        ModuleName
  --Author=AUTHOR       Author
  --AuthorEmail=AUTHOREMAIL
                        AuthorEmail

If you needed to run a Skeleton yourself, you would use the constructor, the update or __setitem__ methods to set the variables (Skeleton is a dict subclass), and the write(dst_dir) or run(dst_dir) methods to apply the skeleton. write() will raise a KeyException if a variable is not set; run() will prompt the user for the missing variables

basic-module/README`

README a is static file that will simply be copied:

TODO: write the description of this module.

basic-module/setup.py_tmpl

setup.py_tmpl is a template (it ends with the _tmpl suffix) that will be used to create a setup.py file:

#!/usr/bin/env python

from distutils.core import setup


PROJECT = {ModuleName!r}
VERSION = '0.1'
AUTHOR = {Author!r}
AUTHOR_EMAIL = {AuthorEmail!r}
DESC = "A short description..."

setup(
    name=PROJECT,
    version=VERSION,
    description=DESC,
    long_description=open('README.rst').read(),
    author=AUTHOR,
    author_email=AUTHOR_EMAIL,
    py_module={ModuleName!r}
)

By default, Skeleton uses python 2.6+ string formatting.

basic-module/{ModuleName}.py

{ModuleName}.py is the module file for which the name will be set dynamically at run time.

EXTRA

skeleton includes a skeleton for a basic package layout, you can run it with:

python -m skeleton.examples.basicpackage <dst_dir>

or with virtualenvwrapper.project. Install it:

pip install skeleton[virtualenv-templates]

Configure virtualenvwrapper and virtualenwrapper.project; then, create a new project:

mkproject -t package <project name>

CHANGES:

0.3 (Mai 6, 2010)

  • New class method, Skeleton.cmd to create the logger and optparser.

  • Skeleton.run doesn’t set the logger and optparser anymore.

  • Skeleton.write raises a KeyError exception if a key is missing instead of prompting the user.

  • Removed the pre_run, post_write and pre_write methods. Overwrite the write and run instead.

  • Added configure_parser() to configure the parser set by Skeleton.cmd.

  • Add required_skeleton attribute to Skeleton. These skeleton will be run before the main. They all share the same entries.

  • Added verbose options to the Skeleton optparser.

  • Added a basic package template extension for virtualenwrapper.project.

0.2.1 (Mai 2, 2010):

  • Fix bug with Var._prompt static method which was preventing the prompt for variable assignement.

0.2 (Mai 1, 2010):

  • Add python 3 support.

0.1 (April 31, 2010):

  • first release.

TODO:

  • Write documentation.

  • Improve variable prompt and command line option.

  • add more example.

Development

Report any issues and fork squeleton at http://github.com/dinoboff/skeleton/ .

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

skeleton-0.3.tar.gz (53.4 kB view hashes)

Uploaded Source

Built Distribution

skeleton-0.3-py3.1.egg (96.1 kB view hashes)

Uploaded Source

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