【问题标题】:Python application directory strucuture (Linux)Python应用程序目录结构(Linux)
【发布时间】:2013-04-05 02:16:37
【问题描述】:

当作为 rpm/deb 包安装到系统时,构建 python 应用程序的最佳实践是什么? 应用程序代码大部分是用 Python 编写的,还有一些 shell 脚本、配置文件和日志文件。

我想有如下结构。

  • 将 Python 包放在哪里?
  • 我需要有应用程序的配置文件,但它会被 Python 包使用。配置文件放在哪里?

/opt/.../app_name-1.0.0/

                  bin/
                      /*Here would be few shell scripts I need*/
                      shell_script_1.sh
                      shell_script_2.sh

                   var/
                       log/
                          /* Log files */
                          app_name.log
                       notifications/
                                    /* notifications, generated by app,
                                       temporarily kept */
                                    alert_1.tmp
                                    alert_2.tmp 

                   etc/
                       /*python package configuration*/
                       /*is it better to put this in package dir?*/
                       app_name.config 

                   app_name/
                           /*Python package, the main content*/
                            __init__.py
                            app_name.py
                            a.py
                            b.py
                            config_file_reader.py

                            subpackage_1/                  
                                          __init__.py
                                          c.py
                            subpackage_2/                  
                                          __init__.py
                                          d.py

【问题讨论】:

    标签: python installation package dir


    【解决方案1】:

    您可以将配置文件放在主目录中,许多应用程序都会这样做(例如 bash、vim...)

    【讨论】:

    • 是的,我猜也可以。
    【解决方案2】:

    将 python 代码放入标准 python 目录是最好的。(例如 /usr/local/lib/pythonX.Y/site-packages)。 不幸的是,我需要将源代码放在应用程序目录中,所以我将把它放在我认为第二好的地方: /opt/.../app_name-1.0.0/lib/python/app_name/

    配置文件进入 etc/

    嗯,我不确定这是否符合标准,但对我来说似乎已经足够了。

    【讨论】:

      猜你喜欢
      • 2012-03-23
      • 2015-07-08
      • 1970-01-01
      • 1970-01-01
      • 2012-01-04
      • 2014-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多