All the QGIS documentation I've seen on custom functions (used in expressions) says that the code is saved in the user's local expressions directory, e.g. ~/.local/share/QGIS/QGIS3/profiles/default/python/expressions in Linux. The same documentation typically says something like "remember to share your expression files if others need this functionality" (example)

It seems like the only way to share this code is for other users to manually copy it to their own expressions directory, however that seems inadequate. If multiple map developers share a version control system the onus is on them to manually copy any updates to custom functions to their expressions directory. It does not seem possible for expressions to be loaded from an alternate path, e.g. one relative to the .qgs file, and therefore automatically update each time a project is loaded.

I plan to create a Feature Request for loading custom functions from a relative path, but first wanted to check that I have understood the current situation correctly. Do all users of shared custom functions really need to manually copy the code to their expressions directory each time it changes?

  • You could create symlinks to the shared function files, or put the Expression directory under version control (and automate updates), or write a small python code to copy the files when the project opens etc. – JGH Mar 19 at 11:46
  • @JGH can you expand on "put the Expression directory under version control"? My expressions are already under version control but the problem is QGIS doesn't know to look there for expressions so they are never loaded when the project opens unless the user manually copies them to their local expressions directory. – tomfumb Mar 19 at 17:10
  • You would checkout the remote (svn, git, whatever) folder in ~/.local/share/QGIS/QGIS3/profiles/default/python/expressions, then either at given time interval or when an app opens (or when you manually do it), you refresh this local folder using the content of the remote folder – JGH Mar 19 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.