[Cubicweb] Working with pip install -e / setup.py develop on a cube
Christophe de Vienne
christophe at unlish.com
Fri Sep 26 09:19:58 CEST 2014
I did a few experiment to see how we could use pip install -e / setup.py
develop on a cube *with the current layout*.
It turns out that we can tweak the virtualenv after pip install -e is
run on the cube.
The solution I will describe below allow to both work on the cube and
the unittests, importing from "cubes.thecube" and "cubes.anothercube" in
a virtualenv. It can be applied to several cubes in the same virtualenv.
It does *not* apply to the other cubicweb packages.
Note : from this point, 'thecube' is the cube that we work on,
'anothercube' is any other cube involved in the application we develop.
Problem 1 - the cubes path
Once pip install -e has been run the cube on which it was launched is
not usable because it is not present in the cube path.
We do not want to add the parent directory of our cube to CW_CUBES_PATH
- When importing from cubes.acube, and because "cubes" is not a
proper namespace, we have issues
- The spirit of virtualenv is that where the project was checked out
does not matter -> we do not want to put restriction on where it can be
put in the filesystem.
From within the virtualenv :
ln -s $(pwd) $VIRTUAL_ENV/share/cubicweb/cubes/thecube
Problem 2 - the python path
2.1 - pip install -e add our directory to the interpreter path. It is a
problem because it pollutes the root namespace, it not masks some
modules when the names match (for example in unlish we have a
2.2 - for some reason I did not identified, I could not import from
cubes.xxx because the virtualenv cubes path is not added to the syspath
like I expected it to (I may have done something wrong on this matter).
2.1 - Remove the our directory from the virtualenv path :
grep -v $(pwd) $PTH > .pth.tmp
mv .pth.tmp $PTH
2.2 - Add the virtualenv cubes path to the python path :
This last command has to be done each time the virtualenv is activated,
it is recommended to add it to the 'activate' script, OR postactivate
script if you are using virtualenvwrapper (which I recommend too).
The attached script does all that for you, and has to be run after each
run of pip install -e.
Note that it will overwrite your postactivate script, set CW_MODE=user
and define a 'ctl' alias, so you may need to modify it before using it.
To conclude, and even if we integrate this in a custom 'develop'
command, it is only a workaround and does not prevent us from redefining
the cube layout.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 758 bytes
Desc: not available
More information about the Cubicweb