Python:在基于 distutils 的项目中安装手册页

发布于 2024-09-18 04:58:59 字数 672 浏览 12 评论 0原文

我有一个 Python 项目,它基本上是一组命令行脚本和一个帮助程序包。由于这些脚本有许多命令行选项,我决定为每个脚本创建一个手册页并使用 ronn (http: //rtomayko.github.com/ronn/)用 Markdown 编写手册并从中生成 mdoc。

问题是:如何在基于 distutils 的项目中生成和安装手册页?

我想出了以下解决方案:创建一个简单的 install.sh 脚本来生成并安装手册页。我从重载的“install”命令调用此脚本并将指定的前缀传递给它...您可以在此处检查实际代码: http://github.com/novel/lc-tools

我不太喜欢这个解决方案,因为对于简单的任务,我必须向 setup.py 添加一些 hack 并实现一个 shell 脚本。此外,我使用 ${PREFIX}/share/man 作为手册页路径,这对于所有系统来说并不正确,例如 FreeBSD 似乎将第 3 方手册页安装到 /usr/local/man (即没有 share/)。

有更优雅的方法来做到这一点吗?

I have a Python project which is basically a set of command line scripts and a helper package. As these scripts have a number of command line options I decided to create a manual page for each script and used ronn (http://rtomayko.github.com/ronn/) to write manuals in Markdown and generate mdoc from it.

The question is: how to generate and install man pages in distutils based project?

I came up with the following solution: create an simple install.sh script which generates and installs manual pages. I call this script from the overloaded 'install' command and pass specified prefix to it... you can check actual code here: http://github.com/novel/lc-tools.

I don't quite like this solution as for the simple task I have to add some hacks to setup.py and implement a shell script as well. Moreover, I use ${PREFIX}/share/man for man page path and it's not correct for all systems, e.g. FreeBSD seem to install 3rd party man pages to /usr/local/man (i.e. no share/).

Are there more elegant ways to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丘比特射中我 2024-09-25 04:58:59

distutils 不支持手册页。人们编写了扩展来支持它们,通常采用自定义 distutils 命令的形式。例如,请参阅 Ubuntu 中的 python-distutils-extra。

distutils2 将支持安装手册页。

distutils does not support man pages. People have written extensions to support them, generally in the form of a custom distutils command. See for example python-distutils-extra from Ubuntu.

distutils2 will support installing man pages.

画离情绘悲伤 2024-09-25 04:58:59

setup.py 中的小技巧可以解决问题...作为补充,您可以添加一个特殊的 man_prefix 选项,可以在设置时传递该选项来更改 man 路径。

你可以这样做:

class lc_install(install):
    description = "Custom Install Process"

    user_options= install.user_options[:]
    user_options.extend([('manprefix=', None, 'MAN Prefix Path')])

def initialize_options(self):
    self.manprefix = None
    install.initialize_options(self)
def finalize_options(self):
    if self.manprefix is None :
        self.manprefix = "DEFAULT MAN PREFIX PATH IF THE OPTION IS NOT SET"
    install.finalize_options(self)

def run(self):
    .... # Your run method

Your little hack in your setup.py does the trick.... In complement, you can add a special man_prefix options that can be passed at setup time to change the man path.

You can do this like this :

class lc_install(install):
    description = "Custom Install Process"

    user_options= install.user_options[:]
    user_options.extend([('manprefix=', None, 'MAN Prefix Path')])

def initialize_options(self):
    self.manprefix = None
    install.initialize_options(self)
def finalize_options(self):
    if self.manprefix is None :
        self.manprefix = "DEFAULT MAN PREFIX PATH IF THE OPTION IS NOT SET"
    install.finalize_options(self)

def run(self):
    .... # Your run method
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文