Location / Version independence

#1

Hi,

I’ve got two issues here:

My main Python installation uses an old version of Autobahn (0.5.1 and 0.5.2 on another machine), which I won’t upgrade anytime soon.

So I’m doing some testing on different versions, even modifiying Autobahn’s code, where I want to use the following structure:

development/experiment.py
development/autobahn/init.py
development/autobahn/httpstatus.py
development/autobahn/prefixmap.py
[…]
development/autobahn/xormasker.py

The problem is that init.py reads the version value from pkg_resources, which means that I might end up “using” an older version. I put “using” in quotes since only the displayed version might differ, while the code used is actually the one in the development folder, isn’t it? I wouldn’t be doubting that this is ok if there weren’t the message:

C:\foo\autobahn-test\autobahn_init_.py:20: UserWarning: Module autobahn was already imported from C:\foo\autobahn-test\autobahn_init_.py, but c:\app\python27\lib\site-packages\autobahn-0.5.9-py2.7.egg is being added to sys.path

Is this method, using pgk_resources to get the version number in the init.py file, a standard way of doing these things? Wouldn’t it be better to hard-code the version number right into the init.py file?

So, if my code relies on the version number of Autobahn, then I need to fix the init.py myself? I kind of like the idea of the autobahn folder being self-contained, with no “external references” like the one made with the version number. It helps a lot when testing among different versions, which usually is a good thing to do, before upgrading.

I’ve seen myself forced to use two different versions in the same project, in the same python process, where only their port differed. This is to share the processes memory.

This way I can keep an old version of autobahn running on one port, and the new one on another port, while the clients get a chance to use the new one if they can. This is over a transition period, where the javascript clients will be using the new version, and android clients still the old one.

In order to do this I had to rename the autobahn folder which contained the new sources (ie to autobahn_0_5_9) and copy it right into the project directory, and call an import with the renamed folder name. From there I’d import it with
from autobahn_0_5_9.websocket import listenWS as listenWS2

Now, the problem is that since wamp.py and websocket.py make an “import autobahn” call, my renamed autobahn folder, autobahn_0_5_9, will do an “import autobahn” (instead of “import autobahn_0_5_9”) just to get the version which should be its own one, but actually will be the one of the standard easy_install installation. This, plus the odd warning of pkg_resources already mentioned in point 1), makes it an odd behavior.

Wouldn’t it be better to add a new file to autobahn, called version.py, which contained a variable called version containing the string of the version number?

Then the
import autobahn
in wamp.py and websocket.py could get replaced by
import version

and all occurrences of

autobahn.version

with
version.version

I admit, it’s not as nice as being able to only update the modified code files, but then again, modifying a version number in a file when the version number of the module actually changes solves some really ugly issues.

I have a modified zip file I can send you, so that you can look at the changes, I think that would be quicker that making it via github.

Kind regards,
Daniel

0 Likes

#2

Hi Daniel,

I agree that it's more robust/flexible to have "version" read from a file.

I have changed stuff accordingly:

https://github.com/tavendo/AutobahnPython/commit/dce2501ab10c1c205af985ff1895fd8f48e21bb5

This follows the suggestions from here:

http://stackoverflow.com/a/7071358/884770

Hope that works for you ..

-- Tobias

···

Am 19.12.2012 19:35, schrieb Daniel F.:

Hi,

I've got two issues here:

1)

My main Python installation uses an old version of Autobahn (0.5.1 and
0.5.2 on another machine), which I won't upgrade anytime soon.

So I'm doing some testing on different versions, even modifiying
Autobahn's code, where I want to use the following structure:

development/experiment.py
development/autobahn/__init__.py
development/autobahn/httpstatus.py
development/autobahn/prefixmap.py
[...]
development/autobahn/xormasker.py

The problem is that __init__.py reads the version value from
pkg_resources, which means that I might end up "using" an older version.
I put "using" in quotes since only the displayed version might differ,
while the code used is actually the one in the development folder, isn't
it? I wouldn't be doubting that this is ok if there weren't the message:

C:\foo\autobahn-test\autobahn\__init__.py:20: UserWarning: Module
autobahn was already imported from
C:\foo\autobahn-test\autobahn\__init__.py, but
c:\app\python27\lib\site-packages\autobahn-0.5.9-py2.7.egg is being
added to sys.path

Is this method, using pgk_resources to get the version number in the
__init__.py file, a standard way of doing these things? Wouldn't it be
better to hard-code the version number right into the __init__.py file?

So, if my code relies on the version number of Autobahn, then I need to
fix the __init__.py myself? I kind of like the idea of the autobahn
folder being self-contained, with no "external references" like the one
made with the version number. It helps a lot when testing among
different versions, which usually is a good thing to do, before upgrading.

2)

I've seen myself forced to use two different versions in the same
project, in the same python process, where only their port differed.
This is to share the processes memory.

This way I can keep an old version of autobahn running on one port, and
the new one on another port, while the clients get a chance to use the
new one if they can. This is over a transition period, where the
javascript clients will be using the new version, and android clients
still the old one.

In order to do this I had to rename the autobahn folder which contained
the new sources (ie to autobahn_0_5_9) and copy it right into the
project directory, and call an import with the renamed folder name. From
there I'd import it with
from autobahn_0_5_9.websocket import listenWS as listenWS2

Now, the problem is that since wamp.py and websocket.py make an "import
autobahn" call, my renamed autobahn folder, autobahn_0_5_9, will do an
"import autobahn" (instead of "import autobahn_0_5_9") just to get the
version which should be its own one, but actually will be the one of the
standard easy_install installation. This, plus the odd warning of
pkg_resources already mentioned in point 1), makes it an odd behavior.

Wouldn't it be better to add a new file to autobahn, called version.py,
which contained a variable called version containing the string of the
version number?

Then the
     import autobahn
in wamp.py and websocket.py could get replaced by
     import version

and all occurrences of

     autobahn.version
with
     version.version

I admit, it's not as nice as being able to only update the modified code
files, but then again, modifying a version number in a file when the
version number of the module actually changes solves some really ugly
issues.

I have a modified zip file I can send you, so that you can look at the
changes, I think that would be quicker that making it via github.

Kind regards,
Daniel

0 Likes

#3

Hi Tobias,

nice solution, thanks for your effort.

There’s still the issue with wamp.py and websocket.py using the version number obtained from an “import autobahn”. This would mean that a renamed autobahn would still not be using its own version, but the one in lib\site-

packages. It may not really be an issue, but since the version is sent to the clients, it may have some unpredictable effects those who depend on it.

Daniel

···

On Saturday, January 5, 2013 2:57:11 PM UTC+1, Tobias Oberstein wrote:

Hi Daniel,

I agree that it’s more robust/flexible to have “version” read from a file.

I have changed stuff accordingly:

https://github.com/tavendo/AutobahnPython/commit/dce2501ab10c1c205af985ff1895fd8f48e21bb5

This follows the suggestions from here:

http://stackoverflow.com/a/7071358/884770

Hope that works for you …

– Tobias

Am 19.12.2012 19:35, schrieb Daniel F.:

Hi,

I’ve got two issues here:

My main Python installation uses an old version of Autobahn (0.5.1 and

0.5.2 on another machine), which I won’t upgrade anytime soon.

So I’m doing some testing on different versions, even modifiying

Autobahn’s code, where I want to use the following structure:

development/experiment.py

development/autobahn/init.py

development/autobahn/httpstatus.py

development/autobahn/prefixmap.py

[…]

development/autobahn/xormasker.py

The problem is that init.py reads the version value from

pkg_resources, which means that I might end up “using” an older version.

I put “using” in quotes since only the displayed version might differ,

while the code used is actually the one in the development folder, isn’t

it? I wouldn’t be doubting that this is ok if there weren’t the message:

C:\foo\autobahn-test\autobahn_init_.py:20: UserWarning: Module

autobahn was already imported from

C:\foo\autobahn-test\autobahn_init_.py, but

c:\app\python27\lib\site-packages\autobahn-0.5.9-py2.7.egg is being

added to sys.path

Is this method, using pgk_resources to get the version number in the

init.py file, a standard way of doing these things? Wouldn’t it be

better to hard-code the version number right into the init.py file?

So, if my code relies on the version number of Autobahn, then I need to

fix the init.py myself? I kind of like the idea of the autobahn

folder being self-contained, with no “external references” like the one

made with the version number. It helps a lot when testing among

different versions, which usually is a good thing to do, before upgrading.

I’ve seen myself forced to use two different versions in the same

project, in the same python process, where only their port differed.

This is to share the processes memory.

This way I can keep an old version of autobahn running on one port, and

the new one on another port, while the clients get a chance to use the

new one if they can. This is over a transition period, where the

javascript clients will be using the new version, and android clients

still the old one.

In order to do this I had to rename the autobahn folder which contained

the new sources (ie to autobahn_0_5_9) and copy it right into the

project directory, and call an import with the renamed folder name. From

there I’d import it with

from autobahn_0_5_9.websocket import listenWS as listenWS2

Now, the problem is that since wamp.py and websocket.py make an "import

autobahn" call, my renamed autobahn folder, autobahn_0_5_9, will do an

“import autobahn” (instead of “import autobahn_0_5_9”) just to get the

version which should be its own one, but actually will be the one of the

standard easy_install installation. This, plus the odd warning of

pkg_resources already mentioned in point 1), makes it an odd behavior.

Wouldn’t it be better to add a new file to autobahn, called version.py,

which contained a variable called version containing the string of the

version number?

Then the

 import autobahn

in wamp.py and websocket.py could get replaced by

 import version

and all occurrences of

 autobahn.version

with

 version.version

I admit, it’s not as nice as being able to only update the modified code

files, but then again, modifying a version number in a file when the

version number of the module actually changes solves some really ugly

issues.

I have a modified zip file I can send you, so that you can look at the

changes, I think that would be quicker that making it via github.

Kind regards,

Daniel

0 Likes

#4

Hi Daniel,

There's still the issue with wamp.py and websocket.py using the version
number obtained from an "import autobahn". This would mean that a

Changed:

https://github.com/tavendo/AutobahnPython/commit/c3b8cfc855d356d09c80b2d6ea58e697fb7b9ef4

Please check if that works for you ..

-- Tobias

0 Likes

#5

Hi Tobias,

it does. Thanks.

Daniel

···

On Sat, Jan 5, 2013 at 4:58 PM, Tobias Oberstein tobias.o...@gmail.com wrote:

Hi Daniel,

There’s still the issue with wamp.py and websocket.py using the version

number obtained from an “import autobahn”. This would mean that a

Changed:

https://github.com/tavendo/AutobahnPython/commit/c3b8cfc855d356d09c80b2d6ea58e697fb7b9ef4

Please check if that works for you …

– Tobias

0 Likes