擅长:python、mysql、java
<p>这里有一个非常简单的解决方案,您只需过滤掉<code>sys.argv</code>,并在调用distutils<code>setup(..)</code>之前自己处理它。
像这样的:</p>
<pre><code>if "--foo" in sys.argv:
do_foo_stuff()
sys.argv.remove("--foo")
...
setup(..)
</code></pre>
<p>关于如何使用distutils实现这一点的文档非常糟糕,最终我遇到了这个:<a href="http://readthedocs.org/docs/the-hitchhikers-guide-to-packaging/en/latest/specification.html">the hitchhikers guide to packaging</a>,它使用<code>sdist</code>及其<code>user_options</code>。
我发现<a href="http://docs.python.org/2/distutils/extending">extending distutils</a>引用没有特别的帮助。</p>
<p>虽然这看起来像是用distutils来做的“正确”的方法(至少我能找到的唯一一个是含糊不清的文档)。我在另一个答案中提到的<code>--with</code>和<code>--without</code>开关上找不到任何东西。</p>
<p>这个distutils解决方案的问题是,它对我所寻找的东西来说太复杂了(对你来说也是如此)。
对我来说,添加几十行和子类化<code>sdist</code>是错误的。</p>