Module Directory?

So, I know how to make a module with cookiecutter, but how do i really install it? I mean should I make them in /home/pathos/path/d/lib/python3.12/site-packages/trytond/modules here? And then I run the admin-tryton stuff?

And theres another question. I have several modules I want to try that I don’t install with pip, how do I install it without having a conflict? Thank you so much.

Have a look at the module tutorial.
There most of your questions are answered.

Edit: Recommended installation method depends on what you are trying to do.
While that can work, it is strongly discouraged.
For testing and development you will find the following in the module tutorial:
python3 -m pip install --use-pep517 --editable opportunity

After you have installed/added a module you need to run:
trytond-admin -c trytond.conf -d databasename -m.
-m updates the module list.
After adding or modifying it is necessary to restart the server so that the new code can be read, unless you are using trytond --dev.

Official tryton modules are designed to not conflict, but you do need to mind other module dependencies and external python dependencies.

1 Like

Just to be sure, suppose I already make a whole module in trytond/modules, then in the folder i run python3 -m pip install --use-pep517 --editable my_module_name?

and another question can i modify official tryton modules?? and if i can edit my module/official module should i run this again trytond-admin -c trytond.conf -d database name -m? Thank you so much for answering. :disappointed_relieved::disappointed_relieved::disappointed_relieved::disappointed_relieved::disappointed_relieved::disappointed_relieved:

Either you install using the above command, or you put the directory containing the module in the trytond/modules directory, not both.

I had the same idea when I started out using tryton.
You CAN, but it will become a nightmare to maintain.
Tryton modules are designed to be extended, so you can extend or override most aspects of a module without actually changing the original module. This is also covered in the module tutorial.

I strongly suggest you to not do this. This is mixing installation and development. You will run into troubles more quickly than you think and you will end in a nightmare.

I suggest to:

  • use a project directory per module
  • install trytond in a virtual environment
  • activate the virtual environment
  • install your module in the virtual environment (using pip like @dotbit has shown)
  • If your module depends on other custom modules, consider using a requirements.txt file to install these prior to installing your module
  • For modifying official modules: Use an own custom module containing the modifications.
1 Like

Thank you.

I have made an env for this and i installed some official modules in that env. The modules are installed in myenv/lib/python/site-packages/trytond/modules/

In modules’ path there are gnuhealth modules and official modules. Since I want to develope my own modules should I make my custom module in that exact path? Or I could create another path for my custom modules?

I suggest to use one separate path for every of your custom modules like this

.
β”œβ”€β”€ my_module_1
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ setup.py
β”‚   β”œβ”€β”€ tryton.cfg
β”‚   └── …
β”œβ”€β”€ my_module_2
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ setup.py
β”‚   β”œβ”€β”€ tryton.cfg
β”‚   └── …
└── _myvenv
    └── lib
        └── python
            └── site-packages
                └── trytond
                    └── modules/…

I get the gist of these, thank you. So i should run python3 -m pip install --use-pep517 --editable my_module_name with every name? I could not do this bundle?

P.S: I already did what you told: and after i run trytond-admin -c trytond.conf -d my_database -m this errror shown: OSError: File not found : /home/username/.virtualenvs/folder_name/lib/python3.10/site-packages/trytond/modules/absensi/tryton.cfg

Yes, every module needs to be installed.

What does ls /home/username/.virtualenvs/folder_name/lib/python3.10/site-packages/trytond/modules/absensi/tryton.cfg result in?

BTW, your venv needs to be activated before you install your module, so that you are installing the module inside your venv.

This: ls /home/username/.virtualenvs/folder_name/lib/python3.10/site-packages/trytond/modules/absensi/tryton.cfg

Result in: ls: cannot access '/home/username/.virtualenvs/folder_name/lib/python3.10/site-packages/trytond/modules/absensi/tryton.cfg': No such file or directory

But that was because absensi is a custom module, and why they would read a custom in trytond/modules/??

note: my venv is active

Every module needs to have a tryton.cfg file. It does not matter if it is custom or official.

See Anatomy of a module β€” Tryton server

When trytond starts it reads all the installed modules, even not activated ones.
If there is an error or something missing trytond will not start.

If you put absensi in your modules directory manually and you are not using it I recommend deleting it.

Of course I have trytond.cfg inside absensi. But somehow it could not read the trytond.cfg

because this path: /home/username/.virtualenvs/folder_name/lib/python3.10/site-packages/trytond/modules/absensi/tryton.cfg is not the path of absensi modules.

This is my structure file, absensi is my module:

absentia/
┣ sao/
┣ absensi/
┃ ┣ data/
┃ ┣ locale/
┃ ┣ tests/
┃ ┣ doc/
┃ ┣ report/
┃ ┣ icons/
┃ ┣ security/
┃ ┣ wizard/
┃ ┣ view/
┃ ┣ exceptions.py
┃ ┣ core.py
┃ ┣ health_report.xml
┃ ┣ health.py
┃ ┣ tryton.cfg
┃ ┣ sequences.py
┃ ┣ MANIFEST.in
┃ ┣ setup.cfg
┃ ┣ setup.py
┃ ┣ abs_view.xml
┃ ┣ __init__.py
┃ ┣ COPYING
┃ ┣ PKG-INFO
┃ β”— README.rst
┣ .reuse/
┃ β”— dep5
┣ modules.rar
┣ version
┣ trytond.conf
β”— README.rst

It seems that I have confused you with the trytond/modules directory, and for that I apologize.
There are multiple entry-points to a module depending on installation method, one of which is the module directory inside trytond directory.

It should be tryton.cfg.

Perhaps an old version of the module which is no longer there is registered in the database.
Are you using an old database, or starting a new one?
I would recommend checking that the module is installed using pip list and starting with a new database.

i mean tryton.cfg

it alrd installed in pip

(myenv) tst@DESKTOP-QK8AUMD:~/mydir$ pip list Package Version Editable project location --------------- ----------- ----------------------------------- Genshi 0.7.9 **hrms_absensi 6.0.0 /home/tst/mydir/absensi** lxml 5.3.0 passlib 1.7.4 pip 24.1.2 polib 1.2.0 psycopg2 2.9.9 python-dateutil 2.9.0.post0 python-magic 0.4.27 python-sql 1.5.1 relatorio 0.10.2 setuptools 71.0.4 six 1.16.0 trytond 6.0.0 Werkzeug 1.0.1 wheel 0.43.0 wrapt 1.16.0

I try to run trytond-admin -c configuration -d databasename --all after installing with $ python3 -m pip install --use-pep517 --editable absensi it keep showing error like this:

(myvenv) tst@DESKTOP-QK8AUMD:~/mydir$ trytond-admin -c configuration -d database name
Traceback (most recent call last):                                                                                                                                        
File "/home/tst/.virtualenvs/virtualname/bin/trytond-admin", line 23, in <module>                                                                                    
admin.run(options)                                                                                                                                                    
File "/home/tst/.virtualenvs/virtualname/lib/python3.10/site-
packages/trytond/admin.py", line 53, in run                                                             
pool.init(update=options.update, lang=list(lang),                                                                                                                     
File "/home/tst/.virtualenvs/virtualname/lib/python3.10/site-packages/trytond/pool.py", 
line 152, in init                                                            
self.start()                                                                                                                                                          
File "/home/tst/.virtualenvs/virtualname/lib/python3.10/site-packages/trytond/pool.py", 
line 105, in start                                                           
register_classes()                                                                                                                                                    
File "/home/tst/.virtualenvs/virtualname/lib/python3.10/site-
packages/trytond/modules/__init__.py", line 338, in register_classes                                    
for node in create_graph(get_module_list()):                                                                                                                          
File "/home/tst/.virtualenvs/virtualname/lib/python3.10/site-
packages/trytond/modules/__init__.py", line 147, in create_graph                                        
info = get_module_info(module)                                                                                                                                        
File "/home/tst/.virtualenvs/virtualname/lib/python3.10/site-
packages/trytond/modules/__init__.py", line 85, in get_module_info                                      
with tools.file_open(os.path.join(name, 'tryton.cfg')) as fp:                                                                                                         
File "/home/tst/.virtualenvs/virtualname/lib/python3.10/site-
packages/trytond/tools/misc.py", line 78, in file_open                                                  

raise IOError('File not found : %s ' % name)                                                                                                                       
OSError: File not found : /home/tst/.virtualenvs/virtualname/lib/python3.10/site-packages/trytond/modules/absensi/tryton.cfg

This error message is often misleading. This often means that your module fails to import (due to an error in your module). Just add a raise in front of line 77 in trytond/tools/misc.py. nly use this in your development environment!

Thank you @htgoebel, I will keep that in mind. That was beyond my knowledge.
@mahija The technique I use to avoid such errors is to make really small steps, then test and when you get an error you know which step produced the error.

1 Like

I assume the link you gave me was trytond 7.2. I forgot to mention it was trytond 6.0 and the line in misc.py is a bit differen(that already bin raised)t:

if subdir:
    if (subdir == 'modules'
            and (name.startswith('ir' + os.sep)
                or name.startswith('res' + os.sep)
                or name.startswith('tests' + os.sep))):
        name = secure_join(root_path, name)
    else:
        name = secure_join(root_path, subdir, name)
else:
    name = secure_join(root_path, name)

for i in (name, egg_name):
    if i and os.path.isfile(i):
        return io.open(i, mode, encoding=encoding)
        
raise IOError('File not found : %s ' % name)

Oh, you are still on 6.0. AFAIU you are using GnuHealth and assume GnuHealth is still on 6.0. Otherwise I’s strongly suggest to start new projects with the current TLS version.

In 6.0 the behavior was quite different and even worse. Since there are many possibilities why this can fail, I suggest to add this before line 42 and step through the code.

    if module_name == 'absensi': breakpoint()