22
Version 1.3.0 Stéphane Bidoul < [email protected]> Odoo development workow with pip and virtualenv

Odoo development workflow with pip and virtualenv

  • Upload
    acsone

  • View
    3.227

  • Download
    6

Embed Size (px)

Citation preview

Page 1: Odoo development workflow with pip and virtualenv

         

Version 1.3.0

Stéphane Bidoul <[email protected]>

Odoo development work�owwith pip and virtualenv

Page 2: Odoo development workflow with pip and virtualenv

Python ecosystem packaging toolsInstallation tools

Packaging tools

Start reading from Python Packaging Authority.

pip to install Python packagesvirtualenv to create isolated Python environments

··

setuptools to de�ne projects and create distributionswheel the modern Python built distribution format

··

Copyright © 2016-2017 ACSONE SA/NV 2/22

Page 3: Odoo development workflow with pip and virtualenv

virtualenvCreate 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

Page 4: Odoo development workflow with pip and virtualenv

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

Page 5: Odoo development workflow with pip and virtualenv

Installing python packagesInstall 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

Page 6: Odoo development workflow with pip and virtualenv

Start working on a python projectGit 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 inrequirements.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

Page 7: Odoo development workflow with pip and virtualenv

Working with unrelased librariesJust 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

Page 8: Odoo development workflow with pip and virtualenv

FreezeBecause 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

Page 9: Odoo development workflow with pip and virtualenv

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 goodlocate and download addons (on apps.odoo.com, github, etc)read their manifest and/or doc to �nd dependencies (other addons, pythondependencies)manually install dependencies�ddle with --addons-pathstart Odoo and hope for the bestrepeat

···

····

Copyright © 2016-2017 ACSONE SA/NV 9/22

Page 10: Odoo development workflow with pip and virtualenv

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) fromdi�erent OCA github repositories, and one python library (xslxwriter).

Tip: --pre is to get the latest development version of the addon and itsdependencies.

$ 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

Page 11: Odoo development workflow with pip and virtualenv

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

Page 12: Odoo development workflow with pip and virtualenv

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�erentOCA github repositories.

Tip: --pre is to get the latest development version of the addon and itsdependencies.

$ 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

Page 13: Odoo development workflow with pip and virtualenv

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

Page 14: Odoo development workflow with pip and virtualenv

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

Page 15: Odoo development workflow with pip and virtualenv

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

Page 16: Odoo development workflow with pip and virtualenv

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

Page 17: Odoo development workflow with pip and virtualenv

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

Page 18: Odoo development workflow with pip and virtualenv

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

Page 19: Odoo development workflow with pip and virtualenv

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

Page 20: Odoo development workflow with pip and virtualenv

Automatic discovery of installed addonsIn Odoo 8 and 9, addons installed this way can be discovered automatically usingodoo-autodiscover.

In Odoo 10, autodiscovery of installed addons is a built-in feature, so startingodoo 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 foraddons is odoo.addons (directory odoo/addons) instead of odoo_addons (in 8and 9).

Copyright © 2016-2017 ACSONE SA/NV 20/22

Page 21: Odoo development workflow with pip and virtualenv

Bringing Odoo into the python ecosystemautomatic discovery of dependenciesautomatic discovery of installed addons, no need to maintain --addons-pathrobust install/uninstallfreeze !pythonistas don't need to learn new tools

·····

Copyright © 2016-2017 ACSONE SA/NV 21/22

Page 22: Odoo development workflow with pip and virtualenv

Q&A

Thank You

@[email protected]

https://acsone.eu/https://wheelhouse.odoo-community.org/

Copyright © 2016-2017 ACSONE SA/NV 22/22