用于初始化新的buildout/pytest/travis/setuptools启用的python项目的pastescript模板

python_boilerplate_template的Python项目详细描述


这是用于生成python项目的PasteScript模板。它为使用一些流行的最佳实践提供了简单的起点:

  • Proper setuptools-compatible package layout.
  • py.test-based tests.
  • buildout for managing development tools or developing multiple-package projects
  • Usage of the Travis-CI continuous integration service.

请注意,同一模板可通过this repositorycookiecutter一起使用。

安装

安装软件包的最简单方法是通过easy_installpip

$ easy_install python_boilerplate_template

请注意,该包是paster工具的插件paster工具由PasteScript包提供(它将随python_boilerplate_template一起自动安装)。可执行文件paster应该出现在python的bin/(在windows Scripts/)目录中。可能需要将该目录添加到PATH中才能运行可执行文件。

用法

要为新项目初始化目录布局,请确保paster位于您的路径中并运行:

$ paster create -t python_boilerplate <project_name>

在提出一些基本问题后,该工具将为您创建以下项目布局:

<project_name>/
  |
  +-- .gitignore           # Git configuration
  +-- .travis.yml          # Travis-CI configuration
  +-- bootstrap.py         # Buildout bootstrap-script
  +-- buildout.cfg         # Buildout project configuration
  +-- setup.cfg            # Configuration for py.test and other tools
  +-- README.md            # Information on how to use the project
  +-- src/                 # Directory for keeping (possible multiple) project eggs
      |
      +- <egg_name>/       # First egg of the project
         |
         +-- package/      # Python source files
         +-- tests/        # Tests
         +-- .gitignore    # Git configuration
         +-- .travis.yml   # Travis-CI configuration
         +-- setup.cfg     # Configuration for py.test and other tools
         +-- setup.py      # Package metadata
         +-- MANIFEST.in   # Files to include in the package
         +-- README.rst    # Package description
         +-- LICENSE.txt   # License
         +-- CHANGELOG.txt # Changelog

此结构建议您将项目开发为一个eggs集合,每个egg在src/中有其单独的子目录。每个egg使用标准的setuptools布局,整个项目依赖于buildout来组织各个部分

项目准备

创建项目布局之后,下一步要做的是将代码添加到版本控制存储库中。有两个常用选项供您选择:

  1. For smaller single-package projects you might want to keep only the Python’s package code (i.e. ^{tt13}$) under version control, and consider the rest (the ^{tt14}$ and all that comes with it) to be your local development environment.
  2. For larger projects you should consider keeping the whole development environment (including ^{tt14}$, perhaps several eggs under ^{tt16}$, docs in ^{tt17}$, etc) under version control.

如果您决定支持选项1

  • Create a version control repository under ^{tt13}$. Here is an example with Git:

    > cd src/<egg_name>
    > git init
    > git add .
    > git commit -m "Initial package structure"
    

    If you are using Github, proceed by creating a <your-project> repository on the Github website, and then doing:

    > git remote add origin https://github.com/<username>/<your-project>.git
    > git push origin master
    
  • You can safely delete the ^{tt19}$ file in the root of the project (but leave the one within the ^{tt13}$ directory).

如果您决定支持选项2

  • Create a version control repository under the project root. The Git/Github example above applies, except for the first ^{tt21}$ line.
  • Drop ^{tt19}$ from the ^{tt13}$ directory (leave the one in the project root).

在开始开发代码之前,您可能希望优化src/<egg_name>/README.rst文件。此文件应包含软件包应执行的操作的详细说明。特别是,当您将包提交给pypi时,该文件的内容将显示在包索引页上。

此外,样板代码中包含的LICENSE.txtMIT许可证的副本如果项目使用其他许可证,请替换此文件以匹配

最后,您还需要编辑README.md,以反映应用于项目的开发说明

最后,查看src/<egg_name>/setup.py中的设置(例如,classifiers参数可能需要调整)。

完成准备工作后,可以通过运行python bootstrap.py然后运行buildout开始开发。见下一节。

共同发展任务

  • Setting up the development environment before first use:

    > python bootstrap.py
    > export PATH=$PWD/bin:$PATH
        (in Windows: set PATH=%CD%\bin;%PATH%)
    > buildout
    
  • Running tests
    Tests are kept in the tests directory and are run using:
    > py.test
    
  • Creating Sphinx documentation:

    > sphinx-quickstart
    (Fill in the values, edit documentation, add it to version control)
    (Generate documentation by something like "cd docs; make html")
    

    (See this guide for more details)

  • Specifying dependencies for your package:
    Edit the ^{tt32}$ line in ^{tt28}$ by listing all the dependent packages.
  • Producing executable scripts:
    Edit the ^{tt34}$ section of ^{tt35}$ in ^{tt28}$. Then run ^{tt31}$. The corresponding scripts will be created in the ^{tt8}$ subdirectory. Note that the boilerplate project already contains one dummy script as an example.
  • Debugging the code manually:
    Simply run ^{tt39}$. This generated interpreter script has the project package included in the path.
  • Publishing the package on Pypi:

    > cd src/<egg_name>
    > python setup.py register sdist upload
    
  • Creating an egg or a windows installer for the package:

    > cd src/<egg_name>
    > python setup.py bdist_egg
     or
    > python setup.py bdist_wininst
    
  • Travis-CI integration:
    To use the Travis-CI continuous integration service, follow the instructions at the Travis-CI website to register an account and connect your Github repository to Travis. The boilerplate code contains a minimal ^{tt19}$ configuration file that might help you get started.
  • Other tools:
    The initial ^{tt14}$ includes several useful code-checking tools under the ^{tt42}$ section. Adapt this list to your needs (remember to run ^{tt31}$ each time you change ^{tt14}$).
  • Working with setup.py:
    If you are working on a small project you might prefer to drop the whole ^{tt31}$ business completely and only work from within the package directory (i.e. make ^{tt46}$ your project root). In this case you should know that you can use
    > python setup.py develop
    

    to include the package into the system-wide Python path. Once this is done, you can run tests via:

    > python setup.py test
    

    Finally, to remove the package from the system-wide Python path, run:

    > python setup.py develop -u
    
  • Developing multi-package projects:
    Sometimes you might need to split your project into several packages, or use a customized version of some package in your project. In this case, put additional packages as subdirectories of ^{tt12}$ alongside the original ^{tt13}$, and register them in ^{tt14}$. For example, if you want to add a new package to your project, do
    > cd src/
    > cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git
      or
    > paster create <new_package_name>
    

    Then add ^{tt50}$ to version control and add the directory ^{tt50}$ to the ^{tt52}$ list in ^{tt14}$. Also, if necessary, add ^{tt54}$ to the ^{tt55}$ part of ^{tt14}$ and mention it in the ^{tt57}$ configuration section of ^{tt58}$.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
由于测试失败,java testcontainers maven构建失败   java实现jacobi算法实现laplace方程   java中的多线程:如何在不等待所有线程使用ExecutorService完成任务的情况下终止所有线程的执行?   java Hello World不在Android Studio 3中工作   ubuntu Tomcat7的Java版本不正确   java Javafx内存泄漏   对于手动实现的Spring数据存储库方法,我应该使用Java8默认方法吗?   googleappengine中的java添加过滤查询   html当使用JSOUP库在Java中读取标签时,如何保留标签(如<br>、<ul>、<li>、<p>等)的含义?   编码为什么jasper生成的报告在Java中不显示西里尔语(保加利亚语)?   java有没有办法隐藏当前位置和jdk动作?   java找出编译原型文件的版本   有没有办法在运行时更改java方法的访问修饰符?   语法字符串。。。Java中的参数   java数组元素在添加其他元素时会相互覆盖   eclipse中的java GWT项目   java如何为spring rest模板请求将动态json属性名映射到jackson   java无法在Windows 10上找到特定的JDK   在xml字符串和java字符串之间提取正则表达式子字符串