This is a guide of how to package Odoo addons, while our case study is Coopiteasy, it is perfectly valid for any Odoo addon.
Coopiteasy developed a bunch of modules to easy the management of consumer cooperatives, the Vertical cooperative or Easy my coop.
They deploy these community modules directly from git, shallow-clonninig repos with git-aggregator, directly from within the host.
However, we use [[Ansible|Uso de Ansible en Coopdevs]] from working devices, and deploy community modules from pypi using pip and a requirements file.
As we are interested in their modules and want to keep the same deployment strategy we are using, we take charge on publishing them to pypi. The process right now is manual, but ideally would be triggered by commits to main branch.
We have already done this with some non-odoo python works
setup.py
with info from Odoo filespython setup.py ...
twine
You can create and activate a venv:
python3 -m venv venv
source venv/bin/activate
And install the tools
pip install twine wheel setuptools-odoo
Assuming no previous work on pypi has been done, we need to check for the file structure. Odoo community has its own standards. It can be a single repo module, or more frequently, a multi-module repo. In any case, we will need a certain folder structure and a __manifest__.py
for each addon.
version
must have 5 levels: 2 for Odoo (e.g. 12.0) and 3 for addon (e.g. 1.5.2)website
must be a URL, therefore, must include the protocol part, i.e. https://
installable
is a flag to disable the addon from being installed to Odoo or being packed for pypi.Place yourself at the root of the repo:
ls .
addon1/
addon2/
And then run
setuptools-odoo-make-default -d .
A new setup/
folder with this structure:
...
setup/addon1/odoo/addons/<addon1_name> -> ../../../../<addon1_name>
setup/addon2/setup.py
...
This must be only once if no addons are added. Removed addons should remove too their setup/ symlinks.
Since setuptools-odoo
relies on what’s committed to your Git repository, you need to commit the changes occurred in the setup/
directory before executing the next steps.
If you don’t do that, setuptools
will create an empty build/
directory and your package will be broken and not recognized by Odoo. More details here.
This is the first half of cyclical packaging process.
For each addon, do:
cd setup/addon_name
python setup.py bdist_wheel --universal sdist
cd ../..
You can inspect the generated dir setup/addon_name/odooXX_addon_addon_name.egg-info/
:
PKG-INFO
: version, name, author, etc. Mostly compiled from Odoo manifest file. See how and why weird version numbers like ···99.dev17
are computedSOURCES.txt
: included files. Useful if you added a new translation or class and want to ensure it’s there. Bear inrequires.txt
: pip dependencies.This whole process is git-dependand. Both versions and sources depend on git: version to decide the devXX number, and sources to ignore untracked files.
For any doubt of what’s inside, you can unzip the whl
file in dist/
to see what’s in.
If you are testing, you can use the test pypi instance just by inserting --repository-url https://test.pypi.org/legacy/
to the next command, just after upload
:
Otherwise, just do for each addon to upload:
cd setup/addon_name
twine upload dist/*
# fill in credentials
# wait for the upload
cd ../..
NOTE: If, for any reason (actually don’tknow wy), you have a used set in your .pypirc file you will be asked to give usernameand password (it’s not allowed to update packages using this method) sou you must set username to “token” and give your token as password. You can read more about it here. For exemple:
twine upload -u __token__ dist/*
If this happens it may be better to set your user name in .pypirc file as defined here
pip install odoo12-addon-easy_my_coop_website==12.0.1.0.0.99.dev23
. If testing, just insert --index-url https://test.pypi.org/simple/
after install
.