Bug 957577 - Current initialisation of bkr.__version__ is not appropriate for a namespace package
Summary: Current initialisation of bkr.__version__ is not appropriate for a namespace...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Beaker
Classification: Retired
Component: command line
Version: 0.12
Hardware: Unspecified
OS: Unspecified
high
unspecified
Target Milestone: 0.13
Assignee: Nick Coghlan
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-04-29 05:01 UTC by Nick Coghlan
Modified: 2018-02-06 00:41 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-06-25 06:27:12 UTC
Embargoed:


Attachments (Terms of Use)

Description Nick Coghlan 2013-04-29 05:01:28 UTC
Description of problem:

When the Beaker RPM is installed and pkg_resources is imported before bkr, then "bkr.__version__" will always be reported as the installed version, even if imports of submodules are coming from a source checkout.

How reproducible:

Always

Steps to Reproduce:
1. Install bkr from an RPM
2. Run Beaker with an appropriate PYTHONPATH setting
3. Import pkg_resources
4. Import bkr
5. Check bkr.__version__
  
Actual results:

bkr.__version__ reports the installed version

Expected results:

bkr.__version__ reports the source checkout version

Additional info:

This is actually inherent in the way Python's namespace packages work - the only meaningful package level state allowed is the __path__ attribute that defines where submodules may be found. This is made more obvious in the innate namespace package support in Python 3.3, where the way you indicate a namespace package is not providing an __init__.py file *at all*.

To resolve this issue for Beaker, the current "bkr.__version__" attribute should be moved to "bkr.common.__version__" instead, as retrieving the "bkr.common" sub module will correctly respect PYTHONPATH and report the version that is being used to satisfy submodule imports, rather than the version that was used to create the top level namespace package.

The *only* code in the bkr level __init__.py should be the boilerplate to declare the namespace package.

Until this is changed, in order to build the documentation correctly, it is currently necessary to uninstall any Beaker RPMs.

Comment 1 Nick Coghlan 2013-04-29 05:05:54 UTC
Note that, for backwards compatibility, the line in bkr/__init__.py that currently sets the version can be replaced with:

from bkr.common import __version__

That way bkr.__version__ can still be used to access the version information, it just gets set indirectly in order to ensure that a system installation and a source checkout can share a common __init__ file for the namespace package without conflict.

Comment 2 Nick Coghlan 2013-05-28 06:47:03 UTC
On Gerrit: http://gerrit.beaker-project.org/#/c/1978/

Comment 3 Nick Coghlan 2013-05-29 07:18:57 UTC
Previous patch broke the RPM build.

Comment 4 Nick Coghlan 2013-05-29 08:38:19 UTC
New patch that properly treats bkr as a stateless namespace package:
http://gerrit.beaker-project.org/#/c/1991/

Comment 6 Nick Coghlan 2013-05-31 04:03:04 UTC
More fixes from Dan to get local builds working on RHEL 6 when an RPM is also installed : 
http://gerrit.beaker-project.org/#/c/2000/

Comment 7 Dan Callaghan 2013-05-31 04:50:48 UTC
I believe this is finally sorted now...

Comment 9 xjia 2013-06-03 06:48:47 UTC
[root@beaker-devel ~]# python
Python 2.6.6 (r266:84292, Oct 12 2012, 14:23:48)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> from bkr.common import __version__
>>> bkr.common.__version__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'bkr' is not defined
>>> import bkr
>>> bkr.common.__version__
'0.12.1'
>>> exit
Use exit() or Ctrl-D (i.e. EOF) to exit
>>>
[root@beaker-devel ~]# rpm -qa | grep beaker
beaker-server-0.12.1-1.git.177.5d4e6bf.el6.noarch
beaker-server-redhat-0.1.14-1.el6eng.noarch
beaker-0.12.1-1.git.177.5d4e6bf.el6.noarch

Comment 11 Amit Saha 2013-06-25 06:27:12 UTC
Beaker 0.13.1 has been released.


Note You need to log in before you can comment on or make changes to this bug.