-
Notifications
You must be signed in to change notification settings - Fork 32
5.0 setup
This section will explain how to setup your computer to develop a tryton module (which will, SPOILER, be what we will be doing next).
From version 5.0, Tryton uses Python 3, so the first step would be to make sure you have a sufficiently recent version of Python 3 on your system. The recommanded way to have a compatible version is to use the pyenv tool to easily install and switch versions.
In order to have a better separation of development environments, we will also need to install virtualenv.
Usually, you should be able to install Python 3 and virtualenv with the following command (for Debian based linux versions):
sudo apt install python3 virtualenv
For other distributions, some variant of those commands should do the trick, since those packages are rather basic.
Using Pyenv is usually a good thing since you will probably use it anyway if you have to work on multiple versions of Python at once without reinstalling everytime It requires some dependencies (since it will build the python versions you want locally on your machine). So for Debian & co that would be:
sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl
You can install it however you want, but the simplest (and easiest) way would be to simply run:
curl https://pyenv.run | bash
Then run
pyenv init
and follow the instructions to properly integrate pyenv with your shell.
Then restart your shell, and:
pyenv update
You can now install any python version that you want to work with by using:
pyenv install 3.7.17
In any case, you can check the install docs, the frequent problems, or switch back to the system install if needed.
You will need to create a new virtual environment to work on your project. To do so, you will first create a directory (let's assume it's called "training"), and then:
mkdir /path/to/training
pyenv virtualenv 3.7.17 training
Once it's done, you can activate your environment by running:
cd /path/to/training
pyenv local training
The tryton client uses Gtk3, and will require some dependencies to be installed:
- python3-dev
- libgirepository1.0-dev
- libcairo2-dev
- python-gi (python3-gi for more recent versions)
- python-gi-cairo (python3-gi-cairo for more recent versions)
- gir1.2-gtksource-3.0
sudo apt install python3-dev libgirepository1.0-dev libcairo2-dev python-gi \
python-gi-cairo gir1.2-gtksource-3.0
OR (Ubuntu 22.04+)
sudo apt install python3-dev libgirepository1.0-dev libcairo2-dev python3-gi \
python3-gi-cairo gir1.2-gtksource-3.0
Those are the package names for Debian based distributions, you should be able to find the relevant matches for your distribution rather easily.
The trytond server can easily be installed using pip. With your training virtual environment activated, just execute:
pip install trytond~=5.0.0
The client can also be installed easily:
# Required since we are in a virtualenv. Sometimes it fails, retrying should do
# the job
pip install pygobject
# Properly install the client
pip install tryton~=5.0.0
Since we will be using postgresql for the development, we must also install it:
There are multiple way to have access to a running postgresql instance, but the easiest would be (for Debian based distributions):
sudo apt install postgresql postgresql-contrib
Depending on your distribution, the service may be automatically started on installation, or you may have to start it manually (check the relevant documentation depending on the version that was installed, and your distribution).
We will also need to install the relevant python library in our virtualenv. The preferred version is to use the binary package:
pip install psycopg2-binary
Alternatively, you can build the package from sources. This require that you
install the libpq-dev
package in your system:
sudo apt install libpq-dev # Debian
pip install psycopg2
Trytond connects to the postgresql server using a url in its configuration file
(more on that later). The minimum to be able to do so is to create a dedicated
tryton
user and give it a password.
sudo su postgres -c "createuser -s tryton"
# Add a super secure password
sudo su postgres -c "psql -c \"ALTER ROLE tryton WITH PASSWORD 'tryton'\""
On a newly installed server, you will also have to allow database users to
connect with a password. In the configuration folder (/etc/postgresql/<version>/main
for Ubuntu / Debian), edit the pg_hba.conf
file, and replace
local all all peer
with
local all all md5
then restart the server
service postgresql restart
Now we will prepare our database for installing the application. First thing, actually create a database in the postgresql cluster:
createdb -U tryton training
Now we will tell tryton to use this database by creating a configuration file.
In the root of the training directory, create a trytond.conf
file and
write:
[database]
uri = postgresql://tryton:tryton@localhost:5432/training
We will now be able to initialize the database using the trytond-admin
utility which came along when we pip-installed the trytond
package:
trytond-admin -c trytond.conf -d training --all
This command will initialize the training
database, based on the
trytond.conf
configuration file. We will not detail what is happening here,
just note how you will be asked for an admin email (which you may leave
empty for a development database) and admin password (which you should set to
something super-secure like admin
).
You now have everything you need to properly start your trytond instance:
trytond -c trytond.conf
You can connect to the server using your brand new client:
tryton
The connection informations for your running server are as follow:
host: localhost:8000
database: training
user name: admin
password: admin
Those are defaults that can be tweaked using the configuration file, but this will be for later.
Once you effectively logged in, you can complete the start up actions that are automatically displayed without doing anything. We only want to make sure you are able to access the application for now.
Note: The trytond server accepts a --dev
flag that will make it
automatically restart as soon as a python file is modified in its filesystem,
which obviously speeds up development (a lot)
Note 2: There also is a --verbose
flag which activates the lower level of
logging (by default, the server only display ERROR
and above log levels).
This is actually very verbose, and very helpful, but requires some experience
and logging configuration to be usable so keep away for now)
In order to properly follow the tutorial, you will need to clone in your newly created virtualenv the training repository:
git clone https://github.com/coopengo/tryton-training.git
You now have a working development environment, to which we successfully connected using the client. We will now proceed to actually creating a module.