Initialize project layout in python?

后端 未结 4 448
情书的邮戳
情书的邮戳 2020-12-28 10:38

Suppose a programmer has the following problem: he wants to start a new python project. He needs a basic layout of boilerplate stuff, like test directory, source directory,

相关标签:
4条回答
  • 2020-12-28 11:12

    I'm using modern-package-template to layout my Python projects.

    modern-package-template is a PasteScript template to create an initial layout for your Python projects using modern tools and practices followed in the Python community. Thus, your projects will have the following characteristics:

    • Use Distribute instead of setuptools as the BDFL himself supports it.
    • Buildout support, though you are not required to make use of it.
    • README.txt and NEWS.txt automatically included in your package metadata as long_description, thus making them appear in the PyPI page for your project.
    • Automatic script (or .exe) creation using Distribute

    More info and download from pypi: http://pypi.python.org/pypi/modern-package-template

    0 讨论(0)
  • 2020-12-28 11:24

    You need something that supports templating to pull this off. The most used in the python community is pastescript.

    easy_install pastescript # A one-time install
    paster create
    

    If you've already decided on the name of the package, than it's just:

    paster create mypackage
    

    If you want to customize the template, than the easiest way is to create your own python package that includes the custom template you want. Once you've installed it into your environment, you can then use this custom template as much as you want. (This is the sort of thing used by frameworks like pylons to create a template for a web application).

    paster create -t libtemplate mypackage
    paster create -t apptemplate mypackage
    

    For more details on how to create templates (which consist of a mix of code and source files) take a look at: http://pythonpaste.org/script/developer.html#templates You'll notice that templates support inheritance, so that you can, e.g. just build upon the included template, or create your own, from-scratch templates.

    For a good example of a customized template, you can take a look at the pylons template in source, here: Pylons Template Code

    In addition, if you're not already using it, you should take a look at Ian Bicking's virtualenv. It allows you to create temporary 'virtual' environments that allow you to install python packages without using and/or conflicting with whatever system-wide packages you may have installed.

    A standard setup with virtualenv and pastescript might look something like this:

    mkdir mypackage && cd mypackage
    virtualenv --distribute env
    source env/bin/activate # 'Turns on / activates' the environment
    easy_install pastescript
    paster create mypackage
    
    0 讨论(0)
  • 2020-12-28 11:33

    You can make your own templates. Really useful, for instance for in-house project structure standards.

    Best way to start making your own is to start with an existing example and to copy/paste relevant bits from it. Suggestion: ZopeSkel as it is a quite big one with lots of examples. Browse the source code.

    0 讨论(0)
  • 2020-12-28 11:33

    I've been using cookiecutter. It's written in python but can be used for any kind of project; not just python. It uses Jinja for templating and features pre and post hooks (written in python or bash) that can easily create/manage one's virtualenvs or anything else you can think of. You can store your own templates in a local directory or pull other peoples directly from the Internet and run them without storing them locally first. It seems much more versatile, simpler to use, and more useful IMHO then paster (disclosure: I've not tried paster). It also is in active development as well.

    0 讨论(0)
提交回复
热议问题