Diff for "LazrStyleGuide"

Not logged in - Log In / Register

Differences between revisions 6 and 7
Revision 6 as of 2010-04-28 13:10:32
Size: 3323
Editor: mars
Comment:
Revision 7 as of 2011-07-13 01:57:44
Size: 3318
Editor: lifeless
Comment: edge must die
Deletions are marked like this. Additions are marked like this.
Line 7: Line 7:
New projects should also always follow, and start from, the [[https://edge.launchpad.net/lazr.yourpkg|lazr.yourpkg template]]. Use the prepare.py script in the template package to get the package ready for development. For instance, if you want to make a ``lazr.foo`` package, you might do this. New projects should also always follow, and start from, the [[https://launchpad.net/lazr.yourpkg|lazr.yourpkg template]]. Use the prepare.py script in the template package to get the package ready for development. For instance, if you want to make a ``lazr.foo`` package, you might do this.

Style Guide for Lazr Projects

Lazr projects are a collection of the open-sourced stand-alone components that Canonical releases.

Lazr projects generally follow the guidelines described in the HackingLazrLibraries and Launchpad Hacking documents.

New projects should also always follow, and start from, the lazr.yourpkg template. Use the prepare.py script in the template package to get the package ready for development. For instance, if you want to make a lazr.foo package, you might do this.

bzr branch lp:lazr.yourpkg lazr.foo
cd lazr.foo
./prepare.py foo

See the Hacking document on where to go from there.

Package README.txt, docs, and tests

All documents in the package should use reStructuredText, with Sphinx extensions as needed. Try using bin/docs in your buildout's bin directory, and then looking at parts/docs/lazr.yourpkg/build/README.html.

The package's README.txt should be an introduction to the package.

If it gets too long strongly consider dividing up the document into a briefer introduction in the README.txt using Sphinx extensions or cross-references to link to documents in the docs/ directory.

On the other hand, if your package is very small, the README.txt may be the only documentation you need. In that case, delete the docs directory.

The README.txt and any/all documents in the docs directory are tested automatically by default (see tests/test_docs.py in lazr.yourpkg).

Doctests are encouraged. Additional unit-style tests should be added in the tests directory.

__version__ number

The __init__.py should have a __version__ string for the package that is used by setup.py for the packages version.

Guidelines for re-exporting

Sometimes a package wants to re-export code in its __init__.py file. For instance, if your package is essentially a module with tests and documentation, it may be quite ugly to have your users import your code with from foo.bar.bar import Bar. You would prefer to have your code canonically available as foo.bar.Bar.

However, the __init__.py should have a __version__, as described above; when the setup.py tries to import it, it may get an import error when it is trying to build. And coders looking at your package will generally not expect to find much code in your init.py file.

Our compromise is the following:

  • Code that you want to re-export in your __init__.py should be placed in a file with a "_" prefix. For instance, in the "foo.bar.Bar" example, you would create a "foo.bar._bar" module for the Bar class.

  • The __init__.py code that imports your modules should import them within a try: except block:

       1     try:
       2         from foo.bar._bar import Bar
       3     except ImportError:
       4         pass
    

    This allows the setup.py usage of __version__ to still work.

  • Tests should only import from the package: that is, if you re-export, the re-export should be the canonical and tested location for imports.

LazrStyleGuide (last edited 2011-07-13 01:57:44 by lifeless)