News for hackers. Stuff that matters.
Re:How To Package Your Python Code by gvalkov on Sunday November 18, 2012 @05:18PM (#4801898)
I've wondered why using a dictionary to initialize setuptools.setup() isn't more advocated in such guides. I understand this is superficial, but imho, this looks much clearer than the author's suggestion [1]:

    from setuptools import setup

    kw = {
        'name'         : 'funniest',
        'version'      : '0.1',
        'description'  : 'The funniest joke in the world',
        'url'          : 'http://github.com/storborg/funniest',
        'author'       : 'Flying Circus',
        'author_email' : '[email protected]',
        'license'      : 'MIT',
        'packages'     : ['funniest'],
        'zip_safe'     : False,
    }

    if __name__ == '__main__':
        setup(**kw)
Here are a few of my setup.py files that follow this convention [2] [3] [4].

[1]: http://www.scotttorborg.com/python-packaging/minimal.html#cr...

[2]: https://github.com/gvalkov/harstats-graphite/blob/master/set...

[3]: https://github.com/gvalkov/jenkins-autojobs/blob/master/setu...

[4]: https://github.com/gvalkov/python-evdev/blob/master/setup.py

Re:How To Package Your Python Code by michaelhoffman on Sunday November 18, 2012 @06:56PM (#4802157)
Adding spaces to make things line up is proscribed by the Python Style Guide. Which is entirely optional, but many people follow it.

http://www.python.org/dev/peps/pep-0008/#pet-peeves

Re:How To Package Your Python Code by shawnps on Sunday November 18, 2012 @11:11PM (#4802850)
I'm so glad Go removes these sort of nitpicky style problems with gofmt. At first I was bothered by how gofmt makes things line up like this, but now I prefer no style guide and a tool that formats stuff for you.
Re:How To Package Your Python Code by storborg on Monday November 19, 2012 @01:03AM (#4803161)
Python has a tool (aptly named "pep8") which provides similar functionality. It doesn't make the changes for you, but it's very specific about what you need to fix to comply with the style guide.
Re:How To Package Your Python Code by njharman on Monday November 19, 2012 @02:34AM (#4803344)
Autopep8 makes the changes for you.
Re:How To Package Your Python Code by borntyping on Sunday November 18, 2012 @05:38PM (#4801954)
Because the only difference there is neater indentation, which you could do using the keywords method.

Additionally, there's no point checking that the script is the main file, as there's only ever one use-case for the script, and that's to call setuptools.

Re:How To Package Your Python Code by gvalkov on Sunday November 18, 2012 @05:48PM (#4801972)
It actually comes in handy if you're using Sphinx and don't want to maintain release and version in conf.py separately from the version in setup.py. There's no reasons why the data should be consumable only by setuptools .
Re:How To Package Your Python Code by Flimm on Sunday November 18, 2012 @06:28PM (#4802093)
You can use pkg_resources which comes with setuptools to look up the version number of your package in setup.py:

  import pkg_resources
  pkg_resources.get_distribution("PIL").version
Re:How To Package Your Python Code by borntyping on Sunday November 18, 2012 @05:51PM (#4801981)
I put the version information inside the package, then anything with access to the package (which both setup.py and sphinx have) can access it - quite useful for doing things like checking the version number from the REPL, for instance.
Re:How To Package Your Python Code by rhettg on Sunday November 18, 2012 @08:33PM (#4802429)
It can be problematic to import your package from setup.py if you want your dependency specification to be useful.