Optional Apps

Amara.org uses several apps/packages that are stored in private github repositories that add extra functionality for paid partnerships. These apps are optional – the amara codebase runs fine without them.

The coding issue is how to make amara work without these repositories, but automatically pull them in if they are present. Here’s how we do it:

  • For each repository we create a file inside the optional/ directory:
    • The filename is the name of the repository
    • The contents are the git commit ID that we want to use
  • To enable a repository, it must be checked out in the amara root directory, using the same name as the git repository.
  • The optionalapps module handles figuring out which repositories are present and how we should modify things at runtime
optionalapps.setup_path()

Add optional repositories to the python path

optionalapps.get_repository_paths()

Get paths to optional repositories that are present

Returns:list of paths to our optional repositories. We should add these to sys.path so that we can import the apps.
optionalapps.get_apps()

Get a list of optional apps

Returns:list of app names from our optional repositories to add to INSTALLED_APPS.
optionalapps.get_urlpatterns()

Get Django urlpatterns for URLs from our optional apps.

This function finds urlpatterns inside the urls module for each optional app. In addition a module variable can define a variable called PREFIX to add a prefix to the urlpatterns.

Returns:url patterns containing urls for our optional apps to add to our root urlpatterns
optionalapps.exec_repository_scripts(filename, globals, locals)

Add extra values to the settings module.

This function looks for files named filename in each optional repository. If that exists, then we call execfile() to run the code using the settings globals/locals. This simulates that code being inside the current scope.