简体   繁体   English

我应该在哪里放置Python包的演示脚本?

[英]Where should I place a Python package's demo script?

I am coding a new python package to be used by others. 我正在编码一个供其他人使用的新python包。 To demonstrate how it should be used, I am writing a demo script that executes the main parts of the new package. 为了演示如何使用它,我正在编写一个演示脚本,该脚本执行新程序包的主要部分。

What is the convention for doing this, so that other will find the script easily? 这样做的惯例是什么,以便其他人可以轻松找到该脚本? Should it be a separate module (by what name)? 它应该是一个单独的模块(按什么名称)吗? Should it be located in the package's root directory? 它应该位于软件包的根目录中吗? Out of the package? 开包装? In __init__.py ? __init__.py

我从未见过任何真正的约定,但我个人将其放在__init__.py中的主python -m somepackage ,以便可以通过python -m somepackage调用它。

Should it be a separate module (by what name)? 它应该是一个单独的模块(按什么名称)吗?

demo/some_useful_name.py 演示/some_useful_name.py

A demo directory contains demo scripts. 演示目录包含演示脚本。 Similarly, a test directory contains all your unit tests. 同样,测试目录包含您的所有单元测试。

Should it be located in the package's root directory? 它应该位于软件包的根目录中吗?

No. It's not part of the package. 不,它不是包装的一部分。 It's a demo. 这是一个演示。

Out of the package? 开包装?

Yes. 是。

In init .py? 初始化的.py?

Never. 决不。


A package has two lives. 一个包有两个生命。 (1) as uninstalled source, (2) in the lib/site-packages as installed code. (1)作为卸载源,(2)在lib / site-packages中作为安装代码。

The "source" should include README, setup.py, demo directory, test directory, and the package itself. “源”应包括自述文件,setup.py,演示目录,测试目录以及程序包本身。

The top-level "source" setup.py should install just the package. 顶级“源” setup.py应该仅安装软件包。 The demo and test don't get installed. 演示和测试未安装。 They get left behind as part of the download. 在下载过程中,它们会落在后面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM