[Distutils] advice re: packaging tasks

Marius Gedminas marius at pov.lt
Thu Oct 2 17:08:05 CEST 2014

On Tue, Sep 30, 2014 at 04:44:09PM -0700, Chris Jerdonek wrote:
> I was curious what others do for the following packaging tasks, or if
> you have any recommendations otherwise.  There is also a code
> organization question at the end.
> 1) For starters, it's very easy to make mistakes in one's MANIFEST.in,
> so I hacked the sdist command in my setup.py to list the differences
> between one's project repo and the generated sdist each time you run
> "python setup.py sdist".  Are there better solutions for this out
> there so I don't have to rely on my own hack?

I wrote check-manifest for this.

Prior to that I used to have horrific Makefile rules that did a similar check:

> 2)  Secondly, like many, my README files are in markdown, so I hacked
> a command in my setup.py to use Pandoc to convert README.md to a .rst
> file for use as the long_description argument to setup().  I also
> check in the resulting file for troubleshooting purposes, etc.  Are
> there more elegant solutions for this that people know of?

I wrote restview for a different purpose, but found it rather useful for
discovering ReStructuredText problems that would make PyPI's fall back
to plaintext rendering.

If you run

  restview --long-description

in a directory containing a setup.py, it'll invoke `python setup.py
--long-description' and interpret it using the same docutils settings as
PyPI, highlighting any errors.

For a more automated (but perhaps less accurate) solution I pipe 

  python setup.py --long-description | rst2html > /dev/null

in my Makefile:

> Also, for commands like the latter, is it better to define them in
> one's setup.py, or simply to have separate scripts in one's repo?

I'm really happy with being able to make releases of any of my packages

  make release

This runs the test suite (tox/detox FTW), checks for uncommitted
changes, makes sure MANIFEST.in is correct, makes sure the version
number in setup.py matches the version number in CHANGES.rst (and
release date is today), makes sure there are no RST errors in
long_descrption, and reminds me the commands I need to run to creates a
version control system tag and package + upload the sdist to PyPI.  (I'm
too paranoid to let automated tools perform externally-visible actions
like uploading to PyPI or pushing git tags, so I just copy & paste the
commands once I'm sure everything's ship-shape.)

There are other excellent tools for this (e.g. zest.releaser).  One day
I'll get tired of copy-pasting my Makefiles from project to project and
I'll switch to zest.releaser.

> Lastly, as these setup-related tasks grow larger and more complicated,
> I found it helped to break them out into a separate setup package that
> sits alongside my project's main package library (and even adding
> tests in some cases).  Is this normal?  Have other people run into
> this?

I'm not sure what you mean.  Do you have any examples?

Marius Gedminas
Life begins when you can spend your spare time programming instead of
watching television.
                -- Cal Keegan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20141002/de03c80e/attachment.sig>

More information about the Distutils-SIG mailing list