[Python-checkins] peps: Updates based on python-dev feedback.
barry.warsaw
python-checkins at python.org
Wed Apr 13 21:21:27 CEST 2011
http://hg.python.org/peps/rev/ed1008f29bf8
changeset: 3867:ed1008f29bf8
user: Barry Warsaw <barry at python.org>
date: Wed Apr 13 15:21:13 2011 -0400
summary:
Updates based on python-dev feedback.
* Remove the __version_info__ tuple discussion. Because of the sorting order
for the non-numeric sections, this can't really work.
* Remove the regexp code sample; it was distracting and ultimately isn't the
core of this PEP.
files:
pep-0396.txt | 38 +++++++++++---------------------------
1 files changed, 11 insertions(+), 27 deletions(-)
diff --git a/pep-0396.txt b/pep-0396.txt
--- a/pep-0396.txt
+++ b/pep-0396.txt
@@ -76,7 +76,7 @@
of an ``__version__`` module attribute by independent module
developers dates back to 1995.
-Another example of version information is the sqlite3 [5]_ library
+Another example of version information is the sqlite3 [5]_ module
with its ``sqlite_version_info``, ``version``, and ``version_info``
attributes. It may not be immediately obvious which attribute
contains a version number for the module, and which contains a version
@@ -121,13 +121,6 @@
supplied revision numbers, or any other semantically different
version numbers (e.g. underlying library version number).
-#. Wherever a ``__version__`` attribute exists, a module MAY also
- include a ``__version_info__`` attribute, containing a tuple
- representation of the module version number, for easy comparisons.
-
-#. ``__version_info__`` SHOULD be of the format returned by PEP 386's
- ``parse_version()`` function.
-
#. The ``version`` attribute in a classic distutils ``setup.py``
file, or the PEP 345 [7]_ ``Version`` metadata field SHOULD be
derived from the ``__version__`` field, or vice versa.
@@ -184,8 +177,11 @@
number once, and have all the other uses derive from this single
definition.
-While there are any number of ways this could be done, this section
-describes one possible approach, for each scenario.
+This could be done in any number of ways, a few of which are outlined
+below. These are included for illustrative purposes only and are not
+intended to be definitive, complete, or all-encompassing. Other
+approaches are possible, and some included below may have limitations
+that prevent their use in some situations.
Let's say Elle adds this attribute to her module file ``elle.py``::
@@ -208,24 +204,12 @@
the ``elle`` module has been converted).
In that case, it's not much more difficult to write a little code to
-parse the ``__version__`` from the file rather than importing it::
+parse the ``__version__`` from the file rather than importing it.
+Without providing too much detail, it's likely that modules such as
+``distutils2`` will provide a way to parse version strings from files.
+E.g.::
- import re
- DEFAULT_VERSION_RE = re.compile(r'(?P<version>\d+\.\d(?:\.\d+)?)')
-
- def get_version(filename, pattern=None):
- if pattern is None:
- cre = DEFAULT_VERSION_RE
- else:
- cre = re.compile(pattern)
- with open(filename) as fp:
- for line in fp:
- if line.startswith('__version__'):
- mo = cre.search(line)
- assert mo, 'No valid __version__ string found'
- return mo.group('version')
- raise AssertionError('No __version__ assignment found')
-
+ from distutils2 import get_version
setup(name='elle', version=get_version('elle.py'))
--
Repository URL: http://hg.python.org/peps
More information about the Python-checkins
mailing list