From 3c31d98c50304d6785469aef39bb0e5584626bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 8 Oct 2020 12:56:19 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=93=9D=20Backport=20dev/contrib=20doc?= =?UTF-8?q?s=20from=20maintenance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CONTRIBUTING.md | 40 +++++++++++++++++++------------- docs/development/environment.rst | 37 +++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 63aed2508..068ea1c0a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -325,8 +325,7 @@ and branching strategy. commits of your full virtual environment). Make sure your PR consists **ideally of only one commit** (use git's rebase and squash functionality). 7. Make sure you **follow the current coding style**. This means: - * Tabs instead of spaces in the Python files[2] - * Spaces instead of tabs in the JavaScript sources + * Spaces for indenting and alignment, indentation width 4. * English language (code, variables, comments, ...) * Comments where necessary: Tell *why* the code does something like it does it, structure your code @@ -347,19 +346,32 @@ and branching strategy. in the OctoPrint checkout folder. An [automatic build workflow](https://github.com/OctoPrint/OctoPrint/actions?query=workflow%3ABuild) is also setup so that if the tests should fail, your PR will be marked accordingly. -9. **Test your changes thoroughly**. That also means testing with usage - scenarios you don't normally use, e.g. if you only use access control, test - without and vice versa. If you only test with your printer, test with the - virtual printer and vice versa. State in your pull request how you tested - your changes. Ideally **add unit tests** - OctoPrint severely lacks in that - department, but we are trying to change that, so any new code already covered - with a test suite helps a lot! -10. In your pull request's description, **state what your pull request does**, +9. Run the **pre-commit check suite** against your changes. You can run that (after + [initial development environment setup with "develop" dependencies](https://docs.octoprint.org/en/master/development/environment.html)) + by running + + ``` + pre-commit run --hook-stage manual --all-files + ``` + + in the OctoPrint checkout folder. If you install the pre-commit hooks via + `pre-commit install` (which you really should!) this will even be taken care of for you prior to committing. + + An [automatic build workflow](https://github.com/OctoPrint/OctoPrint/actions?query=workflow%3ABuild) + is in place that will run these checks - if they fail your PR will be marked accordingly. +10. **Test your changes thoroughly**. That also means testing with usage + scenarios you don't normally use, e.g. if you only use access control, test + without and vice versa. If you only test with your printer, test with the + virtual printer and vice versa. State in your pull request how you tested + your changes. Ideally **add unit tests** - OctoPrint severely lacks in that + department, but we are trying to change that, so any new code already covered + with a test suite helps a lot! +11. In your pull request's description, **state what your pull request does**, as in, what feature does it implement, what bug does it fix. The more thoroughly you explain your intent behind the PR here, the higher the chances it will get merged fast. There is a template provided below that can help you here. -11. Don't forget to **add yourself to the [AUTHORS](./AUTHORS.md) +12. Don't forget to **add yourself to the [AUTHORS](./AUTHORS.md) file** :) Template to use for Pull Request descriptions: @@ -415,14 +427,10 @@ See [the corresponding chapter in the documentation](https://docs.octoprint.org/ new features, suggest getting in touch on the forum for larger changes * 2020-08-10: Update versioning scheme and PR instructions * 2020-09-23: Move branch & versioning into development docs + * 2020-10-07: Introduce `pre-commit` ## Footnotes * [1] - If you are wondering why, the problem is that anything that you add to your PR's branch will also become part of your PR, so if you create a PR from your version of `devel` chances are high you'll add changes to the PR that do not belong to the PR. - * [2] - Yes, we know that this goes against PEP-8. OctoPrint started out as - a fork of Cura and hence stuck to the coding style found therein. Changing - it now would make the history and especially `git blame` completely - unusable, so for now we'll have to deal with it (this decision might be - revisited in the future). diff --git a/docs/development/environment.rst b/docs/development/environment.rst index 1fee1e727..964169d9c 100644 --- a/docs/development/environment.rst +++ b/docs/development/environment.rst @@ -13,8 +13,8 @@ below. * Prerequisites: - * `Python 2.7 `_ including ``pip``, ``setuptools`` and ``virtualenv`` * `Python 3.7 `_ including ``pip``, ``setuptools`` and ``virtualenv`` + * `Python 2.7 `_ including ``pip``, ``setuptools`` and ``virtualenv`` * `Git `_ * Checkout the OctoPrint sources from their Git repository: @@ -26,8 +26,8 @@ below. installing and running OctoPrint and its dependencies. Creating virtual environments avoids potential versioning issues for the dependencies with system wide installed instances: - * PY2: ``virtualenv --python=python2 venv2`` * PY3: ``virtualenv --python=python3 venv3`` + * PY2: ``virtualenv --python=python2 venv2`` .. note:: @@ -35,10 +35,11 @@ below. binaries cannot be found on your ``PATH`` like this you'll need to specify the full paths to them here, e.g. ``virtualenv --python=/path/to/python2/bin/python venv2`` - * Activate one of the virtual environments: + * Activate one of the virtual environments (the Python 3 venv should be considered the + primary one at this point): - * PY2: ``source venv2/bin/activate`` (Linux, macOS) or ``source venv2/Scripts/activate`` (Git Bash under Windows, see below) * PY3: ``source venv3/bin/activate`` (Linux, macOS) or ``source venv3/Scripts/activate`` (Git Bash under Windows, see below) + * PY2: ``source venv2/bin/activate`` (Linux, macOS) or ``source venv2/Scripts/activate`` (Git Bash under Windows, see below) * Update ``pip`` in the virtual environment: @@ -49,10 +50,20 @@ below. * ``pip install -e '.[develop,plugins]'`` + * Set up the pre-commit hooks that make sure any changes you do adhere to the styling rules: + + * ``pre-commit install`` + + * Tell ``git`` where to find the file with revisions to exclude for ``git blame``: + + * ``git config blame.ignoreRevsFile .git-blame-ignore-revs`` + When the virtual environment is activated you can then: * run the OctoPrint server via ``octoprint serve`` * run the test suite from the checked out source folder via ``pytest`` + * trigger the pre-commit check suite manually from the checked out source folder via + ``pre-commit run --hook-stage manual --all-files`` To switch the activated virtual environment, simply activate the new environment as described above. @@ -106,6 +117,8 @@ Then: source ./venv3/bin/activate pip install --upgrade pip pip install -e .[develop,plugins,docs] + pre-commit install + git config blame.ignoreRevsFile .git-blame-ignore-revs You can then start OctoPrint via ``octoprint`` after activating one of the two virtual environments. @@ -149,6 +162,8 @@ Open the Git Bash you just installed and in that: source ./venv3/Scripts/activate pip install --upgrade pip pip install -e .[develop,plugins,docs] + pre-commit install + git config blame.ignoreRevsFile .git-blame-ignore-revs .. _sec-development-environment-mac: @@ -198,6 +213,8 @@ You'll need a user account with administrator privileges. source venv/bin/activate pip install --upgrade pip pip install -e .[develop,plugins] + pre-commit install + git config blame.ignoreRevsFile .git-blame-ignore-revs .. _sec-development-environment-ides: @@ -276,6 +293,18 @@ PyCharm Note that this requires you to also have installed the additional ``docs`` dependencies into the Python 3 venv as described above via ``pip install -e .[develop,plugins,docs]``. + - Settings > Tools > File Watchers (you might have to enable this, it's a bundled plugin), add new: + + * Name: pre-commit + * File type: Python + * Scope: Module 'OctoPrint' + * Program: ``/bin/pre-commit`` (Linux) or ``/Scripts/pre-commit`` (Windows) + * Arguments: ``run --hook-stage manual --files $FilePath$`` + * Output paths to refresh: ``$FilePath$`` + * Working directory: ``$ProjectFileDir$`` + * disable "Auto-save edited files to trigger the watched" + * enable "Trigger the watched on external changes" + To switch between Python 2 and 3, all you need to do now is change the Project Default Interpreter and restart OctoPrint. On current PyCharm versions you can do that right from a small selection field in the footer of the IDE. Otherwise go through Settings. From 1688d8f22a255a9e8a7be3bf8fff95952264767a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 8 Oct 2020 12:56:55 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9D=20Feedback=20controls=20only?= =?UTF-8?q?=20work=20if=20defined=20in=20config.yaml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #3759 --- docs/features/custom_controls.rst | 11 +++++++++++ docs/plugins/viewmodels.rst | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/docs/features/custom_controls.rst b/docs/features/custom_controls.rst index fa69cc435..ad8756bbe 100644 --- a/docs/features/custom_controls.rst +++ b/docs/features/custom_controls.rst @@ -213,17 +213,28 @@ Controls - (Optional) A :ref:`regular expression ` to match against lines received from the printer to retrieve information from it (e.g. specific output). Together with ``template`` this allows rendition of received data from the printer within the UI. + + **Please also read the note below**. * - ``template`` - (Optional) A template to use for rendering the match of ``regex``. May contain placeholders in :ref:`Python Format String Syntax ` for either named groups within the regex (e.g. ``Temperature: {temperature}`` for a regex ``T:\s*(?P\d+(\.\d*)``) or positional groups within the regex (e.g. ``Position: X={0}, Y={1}, Z={2}, E={3}`` for a regex ``X:([0-9.]+) Y:([0-9.]+) Z:([0-9.]+) E:([0-9.]+)``). + + **Please also read the note below**. * - ``confirm`` - (Optional) A text to display to the user to confirm his button press. Can be used with sensitive custom controls like changing EEPROM values in order to prevent accidental clicks. The text will be displayed in a confirmation dialog like in :numref:`fig-configuration-customcontrols-confirm`. +.. note:: + + ``regex`` and ``template`` are only supported for controls that are defined through + ``config.yaml``. These control properties aren't supported for controls added only in + the frontend by the :ref:`getAdditionalControls ` + view model callback. + .. _fig-configuration-customcontrols-confirm: .. figure:: ../images/features-custom_controls-confirm.png :align: center diff --git a/docs/plugins/viewmodels.rst b/docs/plugins/viewmodels.rst index 33d28e9a8..dc8d9cace 100644 --- a/docs/plugins/viewmodels.rst +++ b/docs/plugins/viewmodels.rst @@ -238,6 +238,11 @@ getAdditionalControls() Your view model may return additional custom control definitions for inclusion on the "Control" tab of OctoPrint's interface. See :ref:`the custom control feature`. + .. note:: + + Controls injected from a view model do not support feedback controls (as defined by + ``regex`` and ``template``). + onSettingsShown() Called when the settings dialog is shown.