[Extension development] How to add own parameters?

How can I add my own extension parameters in the mopidy.conf?

I created a section in the ext.conf

[MyExtension]
enabled = true
database = /path/to/file.db

and the extension is enabled but with database mopidy throws an error

WARNING  [MainThread] mopidy.__main__ Found MyExtension configuration errors. The extension has been automatically disabled:
WARNING  [MainThread] mopidy.__main__   MyExtension/database unknown config key.
WARNING  [MainThread] mopidy.__main__ Please fix the extension configuration errors or disable the extensions to silence these messages.

I thought that ext.conf is the place to register such variables? Where elso do I need to declare it?

I am currently using python setup.py develop

Please have a read of https://docs.mopidy.com/en/latest/extensiondev/ and also https://docs.mopidy.com/en/latest/devenv/

Thanks for the hint, I have spent DAYS already in the documentation and looked at other extensions code trying to understand.

Besides ext.conf I now added the paramter to __init__.py

def get_config_schema(self):
    schema = super().get_config_schema()
    schema["database"] = config.String()

and restarted everything, not sure if this is necessary, but now it works.

sudo rm -rf *egg-info
sudo python3 setup.py develop
sudo mopidy --config /usr/share/mopidy/conf.d:/etc/mopidy/mopidy.conf:mopidy-test.conf -v

I spent like 2 hours and endless restarts to read a parameter :crazy_face:

The next one trying will find this post :slightly_smiling_face:

Our develop environment docs do not use this method.

And they definitely do not run as sudo while developing either. If you can, I really would go for the documented setup.

Also, a database file should live under Mopidy’s already existing data_dir. And a path should not be a string. Look at existing extensions, mopidy-local is a good candidate here.

From Running an extension:

While developing your extension and to avoid doing this every time you make a change, you can instead run python setup.py develop to effectively link Mopidy directly with your development files.

Thank you for taking the time and answering so many of my post, I really appreciate it.

I will check mopidy-local.

1 Like

I can only apologise. I don’t think this used to be the case, we must have changed this during the change to python 3. I still suggest you setup a real dev env. Using your system installation instead of a virtual env will cause more problems than it solves.

EDIT:
I just had a look and it seems it’s the opposite. The Extension development page is the one that is a little outdated. It contains some old Mopidy v2.x (and older) practices/info. It’s easy to let documentation become outdated, so if you see something that’s done differently in the actual code, it’s the code that’s usually right. That’s particularly the case here in respect to the example setup.py file (but note that our cookie-cutter template is correct which presumably you are using)