GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing peps.python.org — PEP 396 – Module Version Numbers | peps.python.org
PEP 396 – Module Version Numbers
PEP 396 – Module Version Numbers
Important This PEP has been withdrawn. × Refer to Accessing version information at runtime and
Single-sourcing the Project Version in the Python
Packaging User Guide for up to date recommendations on
accessing package version information at runtime,
and on defining runtime AbstractGiven that it is useful and common to specify version numbers for Python modules, and given that different ways of doing this have grown organically within the Python community, it is useful to establish standard conventions for module authors to adhere to and reference. This informational PEP describes best practices for Python module authors who want to define the version number of their Python module. Conformance with this PEP is optional, however other Python tools
(such as PEP Rejection/WithdrawalThis PEP was formally rejected on 2021-04-14. The packaging ecosystem
has changed significantly in the intervening years since this PEP was
first written, and APIs such as This rejection was reclassified as a withdrawal on 2024-10-21,
as the previous state was being misinterpreted [12] as suggesting
that no modules should be defining Modules are still free to define User StoriesAlice is writing a new module, called Bob has written a module called Carol maintains several namespace packages, each of which are
independently developed and distributed. In order for her users to
properly specify dependencies on the right versions of her packages,
she specifies the version numbers in the namespace package’s
David maintains a package in the standard library, and also produces standalone versions for other versions of Python. The standard library copy defines the version number in the module, and this same version number is used for the standalone distributions as well. RationalePython modules, both in the standard library and available from third
parties, have long included version numbers. There are established
de facto standards for describing version numbers, and many ad-hoc
ways have grown organically over the years. Often, version numbers
can be retrieved from a module programmatically, by importing the
module and inspecting an attribute. Classic Python distutils
Another example of version information is the sqlite3 [5] module
with its This informational PEP codifies established practice, and recommends standard ways of describing module version numbers, along with some use cases for when – and when not – to include them. Its adoption by module authors is purely voluntary; packaging tools in the standard library will provide optional support for the standards defined herein, and other tools in the Python universe may comply as well. Specification
ExamplesRetrieving the version number from a third party package: >>> import bzrlib >>> bzrlib.__version__ '2.3.0' Retrieving the version number from a standard library package that is also distributed as a standalone module: >>> import email >>> email.__version__ '5.1.0' Version numbers for namespace packages: >>> import flufl.i18n >>> import flufl.enum >>> import flufl.lock >>> print flufl.i18n.__version__ 1.0.4 >>> print flufl.enum.__version__ 3.1 >>> print flufl.lock.__version__ 2.1 >>> import flufl >>> flufl.__version__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute '__version__' >>> DerivingModule version numbers can appear in at least two places, and
sometimes more. For example, in accordance with this PEP, they are
available programmatically on the module’s 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 __version__ = '3.1.1' Classic distutilsIn classic distutils, the simplest way to add the version string to
the from elle import __version__ setup(name='elle', version=__version__) In the PEP author’s experience however, this can fail in some cases,
such as when the module uses automatic Python 3 conversion via the
In that case, it’s not much more difficult to write a little code to
parse the from distutils2 import get_version setup(name='elle', version=get_version('elle.py')) Distutils2Because the distutils2 style In consultation with the distutils-sig [9], two options are
proposed. Both entail containing the version number in a file, and
declaring that file in the [metadata] version-file: version.txt When the version number is contained within a larger file, e.g. of
Python code, such that the file must be parsed to extract the version,
the key [metadata] version-from-file: elle.py A parsing method similar to that described above will be performed on the file named after the colon. The exact recipe for doing this will be discussed in the appropriate distutils2 development forum. An alternative is to only define the version number in from distutils2._backport import pkgutil __version__ = pkgutil.get_distribution('elle').metadata['version'] PEP 376 metadataPEP 376 defines a standard for static metadata, but doesn’t
describe the process by which this metadata gets created. It is
highly desirable for the derived version information to be placed into
the PEP 376 ReferencesCopyrightThis document has been placed in the public domain. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |