diff --git a/docs/upgrade.rst b/docs/upgrade.rst --- a/docs/upgrade.rst +++ b/docs/upgrade.rst @@ -39,8 +39,8 @@ Back up your configuration Make a copy of your Kallithea configuration (``.ini``) file. -If you are using :ref:`rcextensions `, you should also -make a copy of the entire ``rcextensions`` directory. +If you are using custom :ref:`extensions `, you should also +make a copy of the ``extensions.py`` file. Back up your database ^^^^^^^^^^^^^^^^^^^^^ diff --git a/docs/usage/customization.rst b/docs/usage/customization.rst --- a/docs/usage/customization.rst +++ b/docs/usage/customization.rst @@ -39,13 +39,14 @@ running:: .. _less: http://lesscss.org/ -Behavioral customization: rcextensions --------------------------------------- +Behavioral customization: Kallithea extensions +---------------------------------------------- -Some behavioral customization can be done in Python using ``rcextensions``, a -custom Python package that can extend Kallithea functionality. +Some behavioral customization can be done in Python using Kallithea +``extensions``, a custom Python file you can create to extend Kallithea +functionality. -With ``rcextensions`` it's possible to add additional mappings for Whoosh +With ``extensions`` it's possible to add additional mappings for Whoosh indexing and statistics, to add additional code into the push/pull/create/delete repository hooks (for example to send signals to build bots such as Jenkins) and even to monkey-patch certain parts of the Kallithea source code (for example @@ -55,9 +56,14 @@ To generate a skeleton extensions packag kallithea-cli extensions-create -c my.ini -This will create an ``rcextensions`` package next to the specified ``ini`` file. -See the ``__init__.py`` file inside the generated ``rcextensions`` package -for more details. +This will create an ``extensions.py`` file next to the specified ``ini`` file. +You can find more details inside this file. + +For compatibility with previous releases of Kallithea, a directory named +``rcextensions`` with a file ``__init__.py`` inside of it can also be used. If +both an ``extensions.py`` file and an ``rcextensions`` directory are found, only +``extensions.py`` will be loaded. Note that the name ``rcextensions`` is +deprecated and support for it will be removed in a future release. Behavioral customization: code changes diff --git a/kallithea/bin/kallithea_cli_extensions.py b/kallithea/bin/kallithea_cli_extensions.py --- a/kallithea/bin/kallithea_cli_extensions.py +++ b/kallithea/bin/kallithea_cli_extensions.py @@ -33,15 +33,15 @@ from kallithea.lib.utils2 import ask_ok def extensions_create(): """Write template file for extending Kallithea in Python. - An rcextensions directory with a __init__.py file will be created next to - the ini file. Local customizations in that file will survive upgrades. - The file contains instructions on how it can be customized. + Create a template `extensions.py` file next to the ini file. Local + customizations in that file will survive upgrades. The file contains + instructions on how it can be customized. """ here = kallithea.CONFIG['here'] content = pkg_resources.resource_string( - 'kallithea', os.path.join('config', 'rcextensions', '__init__.py') + 'kallithea', os.path.join('config', 'extensions', 'extensions.py') ) - ext_file = os.path.join(here, 'rcextensions', '__init__.py') + ext_file = os.path.join(here, 'extensions.py') if os.path.exists(ext_file): msg = ('Extension file %s already exists, do you want ' 'to overwrite it ? [y/n] ') % ext_file diff --git a/kallithea/config/rcextensions/__init__.py b/kallithea/config/extensions/extensions.py rename from kallithea/config/rcextensions/__init__.py rename to kallithea/config/extensions/extensions.py diff --git a/kallithea/lib/pygmentsutils.py b/kallithea/lib/pygmentsutils.py --- a/kallithea/lib/pygmentsutils.py +++ b/kallithea/lib/pygmentsutils.py @@ -69,7 +69,7 @@ def get_index_filenames(): def get_custom_lexer(extension): """ - returns a custom lexer if it's defined in rcextensions module, or None + returns a custom lexer if it's defined in the extensions module, or None if there's no custom lexer defined """ import kallithea diff --git a/kallithea/lib/utils.py b/kallithea/lib/utils.py --- a/kallithea/lib/utils.py +++ b/kallithea/lib/utils.py @@ -522,11 +522,15 @@ def repo2db_mapper(initial_repo_dict, re def load_extensions(root_path): try: - ext = create_module('rc', os.path.join(root_path, 'rcextensions', '__init__.py')) + ext = create_module('extensions', os.path.join(root_path, 'extensions.py')) except FileNotFoundError: - return + try: + ext = create_module('rc', os.path.join(root_path, 'rcextensions', '__init__.py')) + log.warning('The name "rcextensions" is deprecated. Please use a file `extensions.py` instead of a directory `rcextensions`.') + except FileNotFoundError: + return - log.info('Loaded rcextensions from %s', ext) + log.info('Loaded Kallithea extensions from %s', ext) kallithea.EXTENSIONS = ext # Additional mappings that are not present in the pygments lexers