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
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.
Get a list of optional apps
Returns: list of app names from our optional repositories to add to INSTALLED_APPS.
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 called PREFIX must contain the prefix for the urls.
Returns: url patterns containing urls for our optional apps to add to our root urlpatterns