Version 1.3.0
Stéphane Bidoul <stephane.bidoul@acsone.eu>
Odoo development work ow
with pip and virtualenv
Python ecosystem packaging tools
Installation tools
Packaging tools
Start reading from Python Packaging Authority.
pip to install Python packages
virtualenv to create isolated Python environments
·
·
setuptools to de ne projects and create distributions
wheel the modern Python built distribution format
·
·
Copyright © 2016-2017 ACSONE SA/NV 2/22
virtualenv
Create and activate a new virtualenv named myproject:
Upgrade to a recent pip version in your activated virtualenv:
$ virtualenv myproject
$ source myproject/bin/activate
$ pip install -U "pip>=9.0.1"
Copyright © 2016-2017 ACSONE SA/NV 3/22
virtualenv (2)
To juggle many projects, use virtualenvwrapper.
Create and activate a virtualenv for a new project:
Easily switch project:
$ mkdir ~/project1
$ mkvirtualenv project1 -a ~/project1
$ pip install -U "pip>=9.0.1"
$ workon project1
$ workon project2
Copyright © 2016-2017 ACSONE SA/NV 4/22
Installing python packages
Install a library and its dependencies:
Find what is installed:
$ pip install hieroglyph
Collecting hieroglyph
Downloading hieroglyph-0.7.1-py2.py3-none-any.whl (1.6MB)
100% |████████████████████████████████| 1.7MB 3.6MB/s
Collecting Sphinx>=1.2 (from hieroglyph)
Downloading Sphinx-1.4.6-py2.py3-none-any.whl (1.6MB)
100% |████████████████████████████████| 1.6MB 3.7MB/s
[...]
Successfully installed Jinja2-2.8 MarkupSafe-0.23 Pygments-2.1.3
Sphinx-1.4.6 alabaster-0.7.9 babel-2.3.4 docutils-0.12 [...]
$ pip list
Copyright © 2016-2017 ACSONE SA/NV 5/22
Start working on a python project
Git clone it.
Install in editable (aka develop) mode:
This installs the latest version of dependencies.
Projects usually provide a known-good set of dependency versions in
requirements.txt:
$ pip install -e . # or python setup.py develop
$ pip install -r requirements.txt
$ pip install -e .
Copyright © 2016-2017 ACSONE SA/NV 6/22
Working with unrelased libraries
Just pip install them from git.
If you want to hack your own version, fork it and install it in editable mode:
If you have it cloned locally already
$ pip install -e git+https://github.com/nyergler/hieroglyph.git#egg=hieroglyph
$ pip install -e git+ssh://git@github.com/sbidoul/hieroglyph.git#egg=hieroglyph
$ pip install -e ~/projects/hieroglyph
Copyright © 2016-2017 ACSONE SA/NV 7/22
Freeze
Because you git tag everything you send to production, don't you?
Create a repeatable know-good set of dependencies.
$ pip freeze > requirements.txt
$ cat requirements.txt
alabaster==0.7.9
Babel==2.3.4
docutils==0.12
-e git+https://github.com/nyergler/hieroglyph.git@800323dea#egg=hieroglyph
Pygments==2.1.3
Sphinx==1.4.6
[...]
Copyright © 2016-2017 ACSONE SA/NV 8/22
What about the Odoo ecosystem?
Current state
It does not need to be so di cult.
After all Odoo addons are just python code.
install Odoo using standard python tools, so far so good
locate and download addons (on apps.odoo.com, github, etc)
read their manifest and/or doc to nd dependencies (other addons, python
dependencies)
manually install dependencies
ddle with --addons-path
start Odoo and hope for the best
repeat
·
·
·
·
·
·
·
Copyright © 2016-2017 ACSONE SA/NV 9/22
With setuptools-odoo, you can now do this [9.0]
Install Odoo 9 latest nightly:
Install mis_builder and it's dependencies:
Notice the installation of two dependent addons (date_range, report_xlsx) from
di erent OCA github repositories, and one python library (xslxwriter).
Tip: --pre is to get the latest development version of the addon and its
dependencies.
$ pip install https://nightly.odoo.com/9.0/nightly/src/odoo_9.0.latest.zip
$ pip install odoo9-addon-mis_builder --pre
Installing collected packages:
odoo9-addon-mis-builder,
odoo9-addon-date-range, odoo9-addon-report-xlsx,
xlsxwriter
Copyright © 2016-2017 ACSONE SA/NV 10/22
With setuptools-odoo, you can now do this [9.0]
(2)
Freeze:
You can work with development branches too:
$ pip freeze | grep odoo
odoo==9.0rc20160918
odoo9-addon-date-range==9.0.1.0.0.99.dev11
odoo9-addon-mis-builder==9.0.2.0.1.99.dev2
odoo9-addon-report-xlsx==9.0.1.0.0.99.dev1
$ pip install -e git+https://github.com/acsone/account-financial-reporting
> @9.0-imp_mis_builder_style_9e_tbi#
> egg=odoo9-addon-mis_builder&subdirectory=setup/mis_builder
Copyright © 2016-2017 ACSONE SA/NV 11/22
With setuptools-odoo, you can now do this [10.0]
Install Odoo 10 latest nightly:
Install account_fiscal_year and it's dependencies:
Notice the installation of one dependent addons (date_range) from di erent
OCA github repositories.
Tip: --pre is to get the latest development version of the addon and its
dependencies.
$ pip install https://nightly.odoo.com/10.0/nightly/src/odoo_10.0.latest.zip
$ pip install odoo10-addon-account_fiscal_year --pre
Installing collected packages:
odoo10-addon-date-range
Copyright © 2016-2017 ACSONE SA/NV 12/22
With setuptools-odoo, you can now do this [10.0]
(2)
Freeze:
You can work with development branches too:
$ pip freeze | grep odoo
odoo==10.0.post20161011
odoo10-addon-account-fiscal-year==10.0.1.0.0
odoo10-addon-date-range==10.0.1.0.0
$ pip install -e git+https://github.com/acsone/account-invoicing
> @10-mig-account_invoice_supplier_ref_unique-ape#
> egg=odoo10-addon-account_invoice_supplier_ref_unique
> &subdirectory=setup/account_invoice_supplier_ref_unique
Copyright © 2016-2017 ACSONE SA/NV 13/22
Packaging your own addons [9.0]
Create the following directory structure:
Where odoo_addons/__init__.py contains:
setup.py
odoo_addons/__init__.py
odoo_addons/youraddon/__openerp__.py
odoo_addons/youraddon/__init__.py
odoo_addons/youraddon/models/...
__import__('pkg_resources').declare_namespace(__name__)
Copyright © 2016-2017 ACSONE SA/NV 14/22
Packaging your own addons [9.0] (2)
And setup.py is:
The odoo_addon keyword does the magic by examining the addon's
__openerp__.py.
from setuptools import setup
setup(
setup_requires=['setuptools-odoo']
odoo_addon=True,
)
Copyright © 2016-2017 ACSONE SA/NV 15/22
Packaging your own addons [9.0] (3)
In this example it is the equivalent of:
from setuptools import setup
setup(
name='odoo9-addon-youraddon',
version='...', # version from manifest
description='...', # summary from manifest
long_description='...', # description from manifest or README.rst
url='...', # url from manifest
install_requires=['odoo>=9.0a,<9.1a',
'odoo9-addon-dependency1', 'odoo9-addon-dependency2',
'some_python_dependency'],
packages=['odoo_addons',
'odoo_addons.youraddon', 'odoo_addons.youraddon.models', ...],
namespace_packages=['odoo_addons'],
include_package_data=True,
license='AGPL-3')
Copyright © 2016-2017 ACSONE SA/NV 16/22
Packaging your own addons [10.0]
Create the following directory structure:
Where odoo/__init__.py and odoo/addons/__init__.py contains:
setup.py
odoo/__init__.py
odoo/addons/__init__.py
odoo/addons/youraddon/__manifest__.py
odoo/addons/youraddon/__init__.py
odoo/addons/youraddon/models/...
__import__('pkg_resources').declare_namespace(__name__)
Copyright © 2016-2017 ACSONE SA/NV 17/22
Packaging your own addons [10.0] (2)
And setup.py is:
The odoo_addon keyword does the magic by examining the addon's
__manifest__.py.
from setuptools import setup
setup(
setup_requires=['setuptools-odoo']
odoo_addon=True,
)
Copyright © 2016-2017 ACSONE SA/NV 18/22
Packaging your own addons [10.0] (3)
In this example it is the equivalent of:
from setuptools import setup
setup(
name='odoo10-addon-youraddon',
version='...', # version from manifest
description='...', # summary from manifest
long_description='...', # description from manifest or README.rst
url='...', # url from manifest
install_requires=['odoo>=10.0,<10.1dev',
'odoo10-addon-dependency1', 'odoo10-addon-dependency2',
'some_python_dependency'],
packages=['odoo', 'odoo.addons',
'odoo.addons.youraddon', 'odoo_addons.youraddon.models', ...],
namespace_packages=['odoo', 'odoo.addons'],
include_package_data=True,
license='AGPL-3')
Copyright © 2016-2017 ACSONE SA/NV 19/22
Automatic discovery of installed addons
In Odoo 8 and 9, addons installed this way can be discovered automatically using
odoo-autodiscover.
In Odoo 10, autodiscovery of installed addons is a built-in feature, so starting
odoo is enough for it to extend the addons-path automatically..
The main di erence between 8/9 and 10 is that in the namespace package for
addons is odoo.addons (directory odoo/addons) instead of odoo_addons (in 8
and 9).
Copyright © 2016-2017 ACSONE SA/NV 20/22
Bringing Odoo into the python ecosystem
automatic discovery of dependencies
automatic discovery of installed addons, no need to maintain --addons-path
robust install/uninstall
freeze !
pythonistas don't need to learn new tools
·
·
·
·
·
Copyright © 2016-2017 ACSONE SA/NV 21/22
Q&A
Thank You
@sbidoul
stephane.bidoul@acsone.eu
https://acsone.eu/
https://wheelhouse.odoo-community.org/
Copyright © 2016-2017 ACSONE SA/NV 22/22

Odoo development workflow with pip and virtualenv

  • 1.
             Version 1.3.0 Stéphane Bidoul <[email protected]> Odoo development work ow with pip and virtualenv
  • 2.
    Python ecosystem packagingtools Installation tools Packaging tools Start reading from Python Packaging Authority. pip to install Python packages virtualenv to create isolated Python environments · · setuptools to de ne projects and create distributions wheel the modern Python built distribution format · · Copyright © 2016-2017 ACSONE SA/NV 2/22
  • 3.
    virtualenv Create and activatea new virtualenv named myproject: Upgrade to a recent pip version in your activated virtualenv: $ virtualenv myproject $ source myproject/bin/activate $ pip install -U "pip>=9.0.1" Copyright © 2016-2017 ACSONE SA/NV 3/22
  • 4.
    virtualenv (2) To jugglemany projects, use virtualenvwrapper. Create and activate a virtualenv for a new project: Easily switch project: $ mkdir ~/project1 $ mkvirtualenv project1 -a ~/project1 $ pip install -U "pip>=9.0.1" $ workon project1 $ workon project2 Copyright © 2016-2017 ACSONE SA/NV 4/22
  • 5.
    Installing python packages Installa library and its dependencies: Find what is installed: $ pip install hieroglyph Collecting hieroglyph Downloading hieroglyph-0.7.1-py2.py3-none-any.whl (1.6MB) 100% |████████████████████████████████| 1.7MB 3.6MB/s Collecting Sphinx>=1.2 (from hieroglyph) Downloading Sphinx-1.4.6-py2.py3-none-any.whl (1.6MB) 100% |████████████████████████████████| 1.6MB 3.7MB/s [...] Successfully installed Jinja2-2.8 MarkupSafe-0.23 Pygments-2.1.3 Sphinx-1.4.6 alabaster-0.7.9 babel-2.3.4 docutils-0.12 [...] $ pip list Copyright © 2016-2017 ACSONE SA/NV 5/22
  • 6.
    Start working ona python project Git clone it. Install in editable (aka develop) mode: This installs the latest version of dependencies. Projects usually provide a known-good set of dependency versions in requirements.txt: $ pip install -e . # or python setup.py develop $ pip install -r requirements.txt $ pip install -e . Copyright © 2016-2017 ACSONE SA/NV 6/22
  • 7.
    Working with unrelasedlibraries Just pip install them from git. If you want to hack your own version, fork it and install it in editable mode: If you have it cloned locally already $ pip install -e git+https://github.com/nyergler/hieroglyph.git#egg=hieroglyph $ pip install -e git+ssh://[email protected]/sbidoul/hieroglyph.git#egg=hieroglyph $ pip install -e ~/projects/hieroglyph Copyright © 2016-2017 ACSONE SA/NV 7/22
  • 8.
    Freeze Because you gittag everything you send to production, don't you? Create a repeatable know-good set of dependencies. $ pip freeze > requirements.txt $ cat requirements.txt alabaster==0.7.9 Babel==2.3.4 docutils==0.12 -e git+https://github.com/nyergler/hieroglyph.git@800323dea#egg=hieroglyph Pygments==2.1.3 Sphinx==1.4.6 [...] Copyright © 2016-2017 ACSONE SA/NV 8/22
  • 9.
    What about theOdoo ecosystem? Current state It does not need to be so di cult. After all Odoo addons are just python code. install Odoo using standard python tools, so far so good locate and download addons (on apps.odoo.com, github, etc) read their manifest and/or doc to nd dependencies (other addons, python dependencies) manually install dependencies ddle with --addons-path start Odoo and hope for the best repeat · · · · · · · Copyright © 2016-2017 ACSONE SA/NV 9/22
  • 10.
    With setuptools-odoo, youcan now do this [9.0] Install Odoo 9 latest nightly: Install mis_builder and it's dependencies: Notice the installation of two dependent addons (date_range, report_xlsx) from di erent OCA github repositories, and one python library (xslxwriter). Tip: --pre is to get the latest development version of the addon and its dependencies. $ pip install https://nightly.odoo.com/9.0/nightly/src/odoo_9.0.latest.zip $ pip install odoo9-addon-mis_builder --pre Installing collected packages: odoo9-addon-mis-builder, odoo9-addon-date-range, odoo9-addon-report-xlsx, xlsxwriter Copyright © 2016-2017 ACSONE SA/NV 10/22
  • 11.
    With setuptools-odoo, youcan now do this [9.0] (2) Freeze: You can work with development branches too: $ pip freeze | grep odoo odoo==9.0rc20160918 odoo9-addon-date-range==9.0.1.0.0.99.dev11 odoo9-addon-mis-builder==9.0.2.0.1.99.dev2 odoo9-addon-report-xlsx==9.0.1.0.0.99.dev1 $ pip install -e git+https://github.com/acsone/account-financial-reporting > @9.0-imp_mis_builder_style_9e_tbi# > egg=odoo9-addon-mis_builder&subdirectory=setup/mis_builder Copyright © 2016-2017 ACSONE SA/NV 11/22
  • 12.
    With setuptools-odoo, youcan now do this [10.0] Install Odoo 10 latest nightly: Install account_fiscal_year and it's dependencies: Notice the installation of one dependent addons (date_range) from di erent OCA github repositories. Tip: --pre is to get the latest development version of the addon and its dependencies. $ pip install https://nightly.odoo.com/10.0/nightly/src/odoo_10.0.latest.zip $ pip install odoo10-addon-account_fiscal_year --pre Installing collected packages: odoo10-addon-date-range Copyright © 2016-2017 ACSONE SA/NV 12/22
  • 13.
    With setuptools-odoo, youcan now do this [10.0] (2) Freeze: You can work with development branches too: $ pip freeze | grep odoo odoo==10.0.post20161011 odoo10-addon-account-fiscal-year==10.0.1.0.0 odoo10-addon-date-range==10.0.1.0.0 $ pip install -e git+https://github.com/acsone/account-invoicing > @10-mig-account_invoice_supplier_ref_unique-ape# > egg=odoo10-addon-account_invoice_supplier_ref_unique > &subdirectory=setup/account_invoice_supplier_ref_unique Copyright © 2016-2017 ACSONE SA/NV 13/22
  • 14.
    Packaging your ownaddons [9.0] Create the following directory structure: Where odoo_addons/__init__.py contains: setup.py odoo_addons/__init__.py odoo_addons/youraddon/__openerp__.py odoo_addons/youraddon/__init__.py odoo_addons/youraddon/models/... __import__('pkg_resources').declare_namespace(__name__) Copyright © 2016-2017 ACSONE SA/NV 14/22
  • 15.
    Packaging your ownaddons [9.0] (2) And setup.py is: The odoo_addon keyword does the magic by examining the addon's __openerp__.py. from setuptools import setup setup( setup_requires=['setuptools-odoo'] odoo_addon=True, ) Copyright © 2016-2017 ACSONE SA/NV 15/22
  • 16.
    Packaging your ownaddons [9.0] (3) In this example it is the equivalent of: from setuptools import setup setup( name='odoo9-addon-youraddon', version='...', # version from manifest description='...', # summary from manifest long_description='...', # description from manifest or README.rst url='...', # url from manifest install_requires=['odoo>=9.0a,<9.1a', 'odoo9-addon-dependency1', 'odoo9-addon-dependency2', 'some_python_dependency'], packages=['odoo_addons', 'odoo_addons.youraddon', 'odoo_addons.youraddon.models', ...], namespace_packages=['odoo_addons'], include_package_data=True, license='AGPL-3') Copyright © 2016-2017 ACSONE SA/NV 16/22
  • 17.
    Packaging your ownaddons [10.0] Create the following directory structure: Where odoo/__init__.py and odoo/addons/__init__.py contains: setup.py odoo/__init__.py odoo/addons/__init__.py odoo/addons/youraddon/__manifest__.py odoo/addons/youraddon/__init__.py odoo/addons/youraddon/models/... __import__('pkg_resources').declare_namespace(__name__) Copyright © 2016-2017 ACSONE SA/NV 17/22
  • 18.
    Packaging your ownaddons [10.0] (2) And setup.py is: The odoo_addon keyword does the magic by examining the addon's __manifest__.py. from setuptools import setup setup( setup_requires=['setuptools-odoo'] odoo_addon=True, ) Copyright © 2016-2017 ACSONE SA/NV 18/22
  • 19.
    Packaging your ownaddons [10.0] (3) In this example it is the equivalent of: from setuptools import setup setup( name='odoo10-addon-youraddon', version='...', # version from manifest description='...', # summary from manifest long_description='...', # description from manifest or README.rst url='...', # url from manifest install_requires=['odoo>=10.0,<10.1dev', 'odoo10-addon-dependency1', 'odoo10-addon-dependency2', 'some_python_dependency'], packages=['odoo', 'odoo.addons', 'odoo.addons.youraddon', 'odoo_addons.youraddon.models', ...], namespace_packages=['odoo', 'odoo.addons'], include_package_data=True, license='AGPL-3') Copyright © 2016-2017 ACSONE SA/NV 19/22
  • 20.
    Automatic discovery ofinstalled addons In Odoo 8 and 9, addons installed this way can be discovered automatically using odoo-autodiscover. In Odoo 10, autodiscovery of installed addons is a built-in feature, so starting odoo is enough for it to extend the addons-path automatically.. The main di erence between 8/9 and 10 is that in the namespace package for addons is odoo.addons (directory odoo/addons) instead of odoo_addons (in 8 and 9). Copyright © 2016-2017 ACSONE SA/NV 20/22
  • 21.
    Bringing Odoo intothe python ecosystem automatic discovery of dependencies automatic discovery of installed addons, no need to maintain --addons-path robust install/uninstall freeze ! pythonistas don't need to learn new tools · · · · · Copyright © 2016-2017 ACSONE SA/NV 21/22
  • 22.