Brian May <[email protected]> writes:

> What is considered current best practise for version numbers in python
> modules?

My cynical assessment of the field is that a great many publishers of
Python modules don't pay much care to library version numbers.

> PEP-8 says you should define a module.__version__ string.

I've seen this done in various places, but it seems less than useful
once a library gets beyond a single module. The package's ‘__init__’
module can define a ‘__version__’ attribute; but then what happens when
the library as a whole comprises multiple packages? This doesn't seem a
very reliable solution.

> Also, I end up with the version string in many places, and forget to
> update some on new releases.

My current recommended solution:

* Define a version string (remember, folks, a version is *not* a simple
  number; it's a string representing a sequence of integers) in a text
  file at the top level of the code working tree.

  This allows the same canonical version string to be available for any
  other tool that works with the same code base (e.g. code in non-Python
  languages, or your build system).

* Put nothing else in that file. Name it ‘VERSION’.

* Read the contents of ‘VERSION’ in the ‘setup.py’, and use that string
  as the version string value for ‘setup()’.

* Use Distribute's ‘pkg_resources’[0] to query the version string
  anywhere it's needed in the library.

This is not ideal. While ‘distutils’ does provide ‘setup’ (allowing us
to define the version in one place), it does not provide a convenient
means of querying the resulting metadata of an installed distribution.

For that, we need the third-party ‘pkg_resources’. This library was
proposed for the Python standard library in PEP 365, but rejected
<URL:http://legacy.python.org/dev/peps/pep-0365/> for reasons not
explained in that PEP.


[0] <URL:https://pythonhosted.org/setuptools/pkg_resources.html>. Why is
    it called “setuptools”, but actually named “Distribute”, for a
    library named “pkg_resources”? That's a long and sad story, and its
    telling would take this thread too far afield.

-- 
 \        “If it ain't bust don't fix it is a very sound principle and |
  `\      remains so despite the fact that I have slavishly ignored it |
_o__)                                     all my life.” —Douglas Adams |
Ben Finney

_______________________________________________
melbourne-pug mailing list
[email protected]
https://mail.python.org/mailman/listinfo/melbourne-pug

Reply via email to