2014-06-30 18:42:27 -07:00
|
|
|
Contributing and feedback guidelines
|
2014-05-26 12:32:05 +02:00
|
|
|
####################################
|
2011-05-10 23:41:27 +01:00
|
|
|
|
2013-04-13 16:55:13 -07:00
|
|
|
There are many ways to contribute to Pelican. You can improve the
|
|
|
|
|
documentation, add missing features, and fix bugs (or just report them). You
|
|
|
|
|
can also help out by reviewing and commenting on
|
|
|
|
|
`existing issues <https://github.com/getpelican/pelican/issues>`_.
|
|
|
|
|
|
2014-05-26 12:32:05 +02:00
|
|
|
Don't hesitate to fork Pelican and submit an issue or pull request on GitHub.
|
2019-11-09 09:43:55 -08:00
|
|
|
When doing so, please consider the following guidelines.
|
2013-04-13 16:55:13 -07:00
|
|
|
|
|
|
|
|
.. include:: ../CONTRIBUTING.rst
|
2011-05-10 23:59:21 +01:00
|
|
|
|
2012-03-06 06:13:17 -08:00
|
|
|
Setting up the development environment
|
|
|
|
|
======================================
|
2011-05-10 23:59:21 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
While there are many ways to set up one's development environment, the following
|
2023-10-29 12:41:55 +01:00
|
|
|
instructions will utilize Pip_ and PDM_. These tools facilitate managing
|
2019-11-09 09:43:55 -08:00
|
|
|
virtual environments for separate Python projects that are isolated from one
|
|
|
|
|
another, so you can use different packages (and package versions) for each.
|
2018-06-21 15:03:00 +02:00
|
|
|
|
2023-10-28 17:43:16 +02:00
|
|
|
Please note that Python |min_python| is required for Pelican development.
|
2011-05-10 23:59:21 +01:00
|
|
|
|
2023-10-29 12:41:55 +01:00
|
|
|
*(Optional)* If you prefer to `install PDM <https://pdm.fming.dev/latest/#installation>`_ once for use with multiple projects,
|
2019-11-09 09:43:55 -08:00
|
|
|
you can install it via::
|
2011-05-10 23:59:21 +01:00
|
|
|
|
2023-10-28 17:43:16 +02:00
|
|
|
curl -sSL https://pdm.fming.dev/install-pdm.py | python3 -
|
2011-05-10 23:59:21 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
Point your web browser to the `Pelican repository`_ and tap the **Fork** button
|
|
|
|
|
at top-right. Then clone the source for your fork and add the upstream project
|
|
|
|
|
as a Git remote::
|
2011-05-10 23:59:21 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
mkdir ~/projects
|
|
|
|
|
git clone https://github.com/YOUR_USERNAME/pelican.git ~/projects/pelican
|
|
|
|
|
cd ~/projects/pelican
|
|
|
|
|
git remote add upstream https://github.com/getpelican/pelican.git
|
2011-05-10 23:59:21 +01:00
|
|
|
|
2023-10-29 12:41:55 +01:00
|
|
|
While PDM can dynamically create and manage virtual environments, we're going
|
2019-11-09 09:43:55 -08:00
|
|
|
to manually create and activate a virtual environment::
|
2012-08-01 18:20:12 -07:00
|
|
|
|
2021-04-21 10:05:28 +02:00
|
|
|
mkdir ~/virtualenvs && cd ~/virtualenvs
|
|
|
|
|
python3 -m venv pelican
|
|
|
|
|
source ~/virtualenvs/pelican/*/activate
|
2012-08-01 18:20:12 -07:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
Install the needed dependencies and set up the project::
|
2012-08-01 18:20:12 -07:00
|
|
|
|
2020-08-17 07:04:00 +02:00
|
|
|
python -m pip install invoke
|
2019-11-09 09:43:55 -08:00
|
|
|
invoke setup
|
2012-08-01 18:20:12 -07:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
Your local environment should now be ready to go!
|
2011-05-10 23:41:27 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
.. _Pip: https://pip.pypa.io/
|
2023-10-29 12:41:55 +01:00
|
|
|
.. _PDM: https://pdm.fming.dev/latest/
|
2019-11-09 09:43:55 -08:00
|
|
|
.. _Pelican repository: https://github.com/getpelican/pelican
|
2013-05-26 12:44:32 +02:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
Development
|
|
|
|
|
===========
|
2013-05-26 12:44:32 +02:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
Once Pelican has been set up for local development, create a topic branch for
|
2019-11-12 07:28:55 -08:00
|
|
|
your bug fix or feature::
|
2017-01-23 23:45:08 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
git checkout -b name-of-your-bugfix-or-feature
|
2017-01-23 23:45:08 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
Now you can make changes to Pelican, its documentation, and/or other aspects of
|
|
|
|
|
the project.
|
2013-04-13 16:55:13 -07:00
|
|
|
|
2011-05-10 23:41:27 +01:00
|
|
|
Running the test suite
|
2019-11-09 09:43:55 -08:00
|
|
|
----------------------
|
2011-05-10 23:59:21 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
Each time you make changes to Pelican, there are two things to do regarding
|
|
|
|
|
tests: check that the existing tests pass, and add tests for any new features
|
|
|
|
|
or bug fixes. The tests are located in ``pelican/tests``, and you can run them
|
|
|
|
|
via::
|
2011-05-10 23:41:27 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
invoke tests
|
2011-05-10 23:41:27 +01:00
|
|
|
|
2023-10-28 17:01:33 -05:00
|
|
|
(For more on Invoke, see ``invoke -l`` to list tasks, or
|
|
|
|
|
https://pyinvoke.org for documentation.)
|
|
|
|
|
|
2020-11-20 16:22:39 +01:00
|
|
|
In addition to running the test suite, it is important to also ensure that any
|
|
|
|
|
lines you changed conform to code style guidelines. You can check that via::
|
|
|
|
|
|
|
|
|
|
invoke lint
|
|
|
|
|
|
|
|
|
|
If code style violations are found in lines you changed, correct those lines
|
|
|
|
|
and re-run the above lint command until they have all been fixed. You do not
|
|
|
|
|
need to address style violations, if any, for code lines you did not touch.
|
2012-03-09 16:27:23 +01:00
|
|
|
|
2013-04-13 16:55:13 -07:00
|
|
|
After making your changes and running the tests, you may see a test failure
|
|
|
|
|
mentioning that "some generated files differ from the expected functional tests
|
|
|
|
|
output." If you have made changes that affect the HTML output generated by
|
|
|
|
|
Pelican, and the changes to that output are expected and deemed correct given
|
|
|
|
|
the nature of your changes, then you should update the output used by the
|
2018-06-21 17:40:58 +02:00
|
|
|
functional tests. To do so, **make sure you have both** ``en_EN.utf8`` **and**
|
2019-11-12 07:40:05 -08:00
|
|
|
``fr_FR.utf8`` **locales installed**, and then run the following command::
|
|
|
|
|
|
|
|
|
|
invoke update-functional-tests
|
2012-04-04 23:18:11 +02:00
|
|
|
|
2018-06-21 15:03:00 +02:00
|
|
|
You may also find that some tests are skipped because some dependency (e.g.,
|
|
|
|
|
Pandoc) is not installed. This does not automatically mean that these tests
|
2018-11-02 20:53:15 -06:00
|
|
|
have passed; you should at least verify that any skipped tests are not affected
|
|
|
|
|
by your changes.
|
2013-01-11 03:21:06 +01:00
|
|
|
|
2018-06-21 15:03:00 +02:00
|
|
|
You should run the test suite under each of the supported versions of Python.
|
|
|
|
|
This is best done by creating a separate Python environment for each version.
|
|
|
|
|
Tox_ is a useful tool to automate running tests inside ``virtualenv``
|
|
|
|
|
environments.
|
2013-01-11 03:21:06 +01:00
|
|
|
|
2018-06-21 15:03:00 +02:00
|
|
|
.. _Tox: https://tox.readthedocs.io/en/latest/
|
2013-01-11 03:21:06 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
Building the docs
|
|
|
|
|
-----------------
|
|
|
|
|
|
2019-11-12 08:36:22 -08:00
|
|
|
If you make changes to the documentation, you should build and inspect your
|
|
|
|
|
changes before committing them::
|
2019-11-09 09:43:55 -08:00
|
|
|
|
2019-11-12 08:36:22 -08:00
|
|
|
invoke docserve
|
2019-11-09 09:43:55 -08:00
|
|
|
|
2019-11-12 08:36:22 -08:00
|
|
|
Open http://localhost:8000 in your browser to review the documentation. While
|
|
|
|
|
the above task is running, any changes you make and save to the documentation
|
|
|
|
|
should automatically appear in the browser, as it live-reloads when it detects
|
|
|
|
|
changes to the documentation source files.
|
2019-11-09 09:43:55 -08:00
|
|
|
|
|
|
|
|
Plugin development
|
|
|
|
|
------------------
|
|
|
|
|
|
|
|
|
|
To create a *new* Pelican plugin, please refer to the `plugin template`_
|
|
|
|
|
repository for detailed instructions.
|
|
|
|
|
|
|
|
|
|
If you want to contribute to an *existing* Pelican plugin, follow the steps
|
|
|
|
|
above to set up Pelican for local development, and then create a directory to
|
|
|
|
|
store cloned plugin repositories::
|
|
|
|
|
|
|
|
|
|
mkdir -p ~/projects/pelican-plugins
|
|
|
|
|
|
|
|
|
|
Assuming you wanted to contribute to the Simple Footnotes plugin, you would
|
|
|
|
|
first browse to the `Simple Footnotes`_ repository on GitHub and tap the **Fork**
|
|
|
|
|
button at top-right. Then clone the source for your fork and add the upstream
|
|
|
|
|
project as a Git remote::
|
|
|
|
|
|
|
|
|
|
git clone https://github.com/YOUR_USERNAME/simple-footnotes.git ~/projects/pelican-plugins/simple-footnotes
|
|
|
|
|
cd ~/projects/pelican-plugins/simple-footnotes
|
|
|
|
|
git remote add upstream https://github.com/pelican-plugins/simple-footnotes.git
|
|
|
|
|
|
|
|
|
|
Install the needed dependencies and set up the project::
|
|
|
|
|
|
|
|
|
|
invoke setup
|
2012-03-09 16:27:23 +01:00
|
|
|
|
2019-12-28 10:20:19 +01:00
|
|
|
Create a topic branch for your plugin bug fix or feature::
|
|
|
|
|
|
|
|
|
|
git checkout -b name-of-your-bugfix-or-feature
|
|
|
|
|
|
2020-11-20 16:30:18 +01:00
|
|
|
After writing new tests for your plugin changes, run the plugin test suite and
|
|
|
|
|
check for code style compliance via::
|
2013-01-11 03:21:06 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
invoke tests
|
2020-11-20 16:30:18 +01:00
|
|
|
invoke lint
|
|
|
|
|
|
|
|
|
|
If style violations are found, many of them can be addressed automatically via::
|
|
|
|
|
|
2023-11-12 17:11:23 +01:00
|
|
|
invoke format
|
2020-11-20 16:30:18 +01:00
|
|
|
|
|
|
|
|
If style violations are found even after running the above auto-formatters,
|
|
|
|
|
you will need to make additional manual changes until ``invoke lint`` no longer
|
|
|
|
|
reports any code style violations.
|
2013-01-11 03:21:06 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
.. _plugin template: https://github.com/getpelican/cookiecutter-pelican-plugin
|
|
|
|
|
.. _Simple Footnotes: https://github.com/pelican-plugins/simple-footnotes
|
2013-01-11 03:21:06 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
Submitting your changes
|
|
|
|
|
-----------------------
|
2018-06-21 15:03:00 +02:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
Assuming linting validation and tests pass, add a ``RELEASE.md`` file in the root
|
|
|
|
|
of the project that contains the release type (major, minor, patch) and a
|
|
|
|
|
summary of the changes that will be used as the release changelog entry.
|
|
|
|
|
For example::
|
2018-06-21 15:03:00 +02:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
Release type: patch
|
2013-01-11 03:21:06 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
Fix browser reloading upon changes to content, settings, or theme
|
2013-01-11 03:21:06 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
Commit your changes and push your topic branch::
|
2013-01-11 03:21:06 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
git add .
|
|
|
|
|
git commit -m "Your detailed description of your changes"
|
|
|
|
|
git push origin name-of-your-bugfix-or-feature
|
2013-01-11 03:21:06 +01:00
|
|
|
|
2019-11-09 09:43:55 -08:00
|
|
|
Finally, browse to your repository fork on GitHub and submit a pull request.
|
2014-04-01 20:44:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
Logging tips
|
|
|
|
|
============
|
|
|
|
|
|
|
|
|
|
Try to use logging with appropriate levels.
|
|
|
|
|
|
2014-07-22 11:48:15 -04:00
|
|
|
For logging messages that are not repeated, use the usual Python way::
|
2014-04-01 20:44:09 +02:00
|
|
|
|
|
|
|
|
# at top of file
|
|
|
|
|
import logging
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
# when needed
|
2014-07-22 11:48:15 -04:00
|
|
|
logger.warning("A warning with %s formatting", arg_to_be_formatted)
|
2014-04-01 20:44:09 +02:00
|
|
|
|
2014-07-22 11:48:15 -04:00
|
|
|
Do not format log messages yourself. Use ``%s`` formatting in messages and pass
|
2019-11-09 09:43:55 -08:00
|
|
|
arguments to logger. This is important, because the Pelican logger will
|
|
|
|
|
preprocess some arguments, such as exceptions.
|
2014-04-01 20:44:09 +02:00
|
|
|
|
2014-07-22 11:48:15 -04:00
|
|
|
Limiting extraneous log messages
|
|
|
|
|
--------------------------------
|
2014-04-01 20:44:09 +02:00
|
|
|
|
2014-07-22 11:48:15 -04:00
|
|
|
If the log message can occur several times, you may want to limit the log to
|
|
|
|
|
prevent flooding. In order to do that, use the ``extra`` keyword argument for
|
|
|
|
|
the logging message in the following format::
|
|
|
|
|
|
|
|
|
|
logger.warning("A warning with %s formatting", arg_to_be_formatted,
|
|
|
|
|
extra={'limit_msg': 'A generic message for too many warnings'})
|
|
|
|
|
|
|
|
|
|
Optionally, you can also set ``'limit_args'`` as a tuple of arguments in
|
|
|
|
|
``extra`` dict if your generic message needs formatting.
|
|
|
|
|
|
|
|
|
|
Limit is set to ``5``, i.e, first four logs with the same ``'limit_msg'`` are
|
2018-11-02 20:53:15 -06:00
|
|
|
outputted normally but the fifth one will be logged using ``'limit_msg'`` (and
|
|
|
|
|
``'limit_args'`` if present). After the fifth, corresponding log messages will
|
|
|
|
|
be ignored.
|
2014-07-22 11:48:15 -04:00
|
|
|
|
|
|
|
|
For example, if you want to log missing resources, use the following code::
|
2014-04-01 20:44:09 +02:00
|
|
|
|
2014-04-14 16:18:07 -04:00
|
|
|
for resource in resources:
|
|
|
|
|
if resource.is_missing:
|
2014-07-22 11:48:15 -04:00
|
|
|
logger.warning(
|
|
|
|
|
'The resource %s is missing', resource.name,
|
|
|
|
|
extra={'limit_msg': 'Other resources were missing'})
|
2014-04-01 20:44:09 +02:00
|
|
|
|
2014-07-22 11:48:15 -04:00
|
|
|
The log messages will be displayed as follows::
|
2014-04-01 20:44:09 +02:00
|
|
|
|
|
|
|
|
WARNING: The resource prettiest_cat.jpg is missing
|
|
|
|
|
WARNING: The resource best_cat_ever.jpg is missing
|
|
|
|
|
WARNING: The resource cutest_cat.jpg is missing
|
|
|
|
|
WARNING: The resource lolcat.jpg is missing
|
|
|
|
|
WARNING: Other resources were missing
|
2014-07-22 11:48:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
Outputting traceback in the logs
|
|
|
|
|
--------------------------------
|
|
|
|
|
|
|
|
|
|
If you're logging inside an ``except`` block, you may want to provide the
|
|
|
|
|
traceback information as well. You can do that by setting ``exc_info`` keyword
|
|
|
|
|
argument to ``True`` during logging. However, doing so by default can be
|
|
|
|
|
undesired because tracebacks are long and can be confusing to regular users.
|
|
|
|
|
Try to limit them to ``--debug`` mode like the following::
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
some_action()
|
|
|
|
|
except Exception as e:
|
2014-09-15 20:29:00 -04:00
|
|
|
logger.error('Exception occurred: %s', e,
|
2014-07-22 11:48:15 -04:00
|
|
|
exc_info=settings.get('DEBUG', False))
|