From 8df2fed6aee7efe25fa47bfd4b532e2e4ce19751 Mon Sep 17 00:00:00 2001 From: Alice Butcher Date: Tue, 29 Oct 2024 17:48:07 +0000 Subject: [PATCH 01/13] ci: update workflow files standardise format, change name of tests file --- .github/workflows/bump.yml | 8 ++++---- .github/workflows/pypi-publish.yml | 9 ++++----- .github/workflows/sync.yml | 6 +++--- .github/workflows/{main.yml => tests.yml} | 8 ++++---- 4 files changed, 15 insertions(+), 16 deletions(-) rename .github/workflows/{main.yml => tests.yml} (77%) diff --git a/.github/workflows/bump.yml b/.github/workflows/bump.yml index 8b17261..1bb1860 100644 --- a/.github/workflows/bump.yml +++ b/.github/workflows/bump.yml @@ -7,12 +7,12 @@ on: jobs: bump-version: - if: "!startsWith(github.event.head_commit.message, 'bump:')" + name: Bump version and create changelog runs-on: ubuntu-latest - name: "Bump version and create changelog" + if: "!startsWith(github.event.head_commit.message, 'bump:')" steps: - - name: Check out - uses: actions/checkout@v3 + - name: Checkout source code + uses: actions/checkout@v4 with: token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} fetch-depth: 0 diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index 6866a49..d3ac620 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -10,17 +10,16 @@ permissions: jobs: deploy: + name: Deploy package to PyPI runs-on: ubuntu-latest steps: - - name: Check out - uses: actions/checkout@v3 + - name: Checkout source code + uses: actions/checkout@v4 with: token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v3 - with: - python-version: '3.x' + uses: actions/setup-python@5 - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index bc66f38..4fec115 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -7,11 +7,11 @@ on: jobs: sync-branches: + name: Sync dev and patch branches to latest commit runs-on: ubuntu-latest - name: "Sync dev and patch branches to latest commit" steps: - - name: Check out - uses: actions/checkout@v3 + - name: Checkout source code + uses: actions/checkout@v4 with: token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} fetch-depth: 0 diff --git a/.github/workflows/main.yml b/.github/workflows/tests.yml similarity index 77% rename from .github/workflows/main.yml rename to .github/workflows/tests.yml index 49847ba..8029992 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/tests.yml @@ -3,18 +3,18 @@ name: Tests on: push: workflow_dispatch: + pull_request: + types: [opened, edited, reopened, synchronize] jobs: test: + name: Run tests runs-on: ubuntu-latest - steps: - name: Checkout source code - uses: actions/checkout@v3 - + uses: actions/checkout@v4 - name: Build images run: docker compose build - - name: Run tests env: COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} From 42db2480ad1d8e0d3dbccbd5c9dd3e41b4a8ec7f Mon Sep 17 00:00:00 2001 From: Alice Butcher Date: Tue, 29 Oct 2024 17:48:14 +0000 Subject: [PATCH 02/13] ci: add pull request validation workflow new workflow to check commit format and code style against pre-commit config --- .github/workflows/pull-requests.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/pull-requests.yml diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml new file mode 100644 index 0000000..b9aa2bd --- /dev/null +++ b/.github/workflows/pull-requests.yml @@ -0,0 +1,27 @@ +name: Validate pull requests + +on: + pull_request: + types: [opened, edited, reopened, synchronize] + +jobs: + validate-commits: + name: Validate commit messages + runs-on: ubuntu-latest + steps: + - name: Checkout source code + uses: actions/checkout@v4 + - name: Check commit message format + uses: webiny/action-conventional-commits@v1.3.0 + with: + allowed-commit-types: 'feat,fix,refactor,perf,docs,style,test,build,ci,chore,new,patch,revert,ui' + pre-commit: + name: Run pre-commit checks + runs-on: ubuntu-latest + steps: + - name: Checkout source code + uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + - name: Run pre-commit + uses: pre-commit/action@v3.0.1 From 8493f26bc67d8c78b74e24457b217b2a35505834 Mon Sep 17 00:00:00 2001 From: Alice Butcher Date: Tue, 29 Oct 2024 17:48:21 +0000 Subject: [PATCH 03/13] ci: update tool config update pre-commit repo versions and switch black to ruff --- .pre-commit-config.yaml | 19 +++++++++---------- pyproject.toml | 7 +++---- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2d3b017..728e347 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ exclude: /(vendor|dist)/ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v5.0.0 hooks: - id: check-merge-conflict - id: detect-private-key @@ -11,23 +11,22 @@ repos: exclude: ^tests/helpers/ - id: trailing-whitespace - repo: https://github.com/commitizen-tools/commitizen - rev: v2.37.0 + rev: v3.30.0 hooks: - id: commitizen additional_dependencies: ["cz-nhm"] - - repo: https://github.com/psf/black - rev: 22.10.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.7.1 hooks: - - id: black + - id: ruff + args: [ '--fix', '--select', 'I', '--select', 'F401' ] + - id: ruff-format - repo: https://github.com/PyCQA/docformatter - rev: v1.5.0 + rev: eb1df34 hooks: - id: docformatter - # these can't be pulled directly from the config atm, not sure why - args: ["-i", "--wrap-summaries=88", "--wrap-descriptions=88", - "--pre-summary-newline", "--make-summary-multi-line"] - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.0-alpha.4 + rev: v4.0.0-alpha.8 hooks: - id: prettier types_or: [ javascript, vue, less, sass, scss, css ] diff --git a/pyproject.toml b/pyproject.toml index 5888ac5..d204be0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ classifiers = [ "Programming Language :: Python :: 3.8" ] dependencies = [ - "ckantools>=0.3.0" + "ckantools>=0.4.1" ] [project.optional-dependencies] @@ -64,9 +64,8 @@ version_files = [ "CITATION.cff:^version" ] -[tool.black] -line-length = 88 -skip_string_normalization = true +[tool.ruff.format] +quote-style = "single" [tool.pylint] max-line-length = 88 From 21ecb9aacc3065d45e84896cfa6b3c06d623302b Mon Sep 17 00:00:00 2001 From: Alice Butcher Date: Tue, 29 Oct 2024 17:48:24 +0000 Subject: [PATCH 04/13] chore: update tool details in contributing guide --- CONTRIBUTING.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2ec0e34..1e8de44 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,7 @@ This extension and [several others](https://github.com/search?q=topic:ckan+org:N The current core team consists of: - Josh ([@jrdh](https://github.com/jrdh)) - Technical Lead -- Ginger ([@alycejenni](https://github.com/alycejenni)) - Software Engineer +- Ginger ([@alycejenni](https://github.com/alycejenni)) - Senior Software Engineer ## Questions @@ -81,7 +81,10 @@ The process is generally as follows: 3. Make your changes, and commit often; each commit should only contain one change. See below for specifics on how to word your commits. 4. Push your changes back to your fork. 5. [Open a pull request](https://docs.github.com/en/get-started/quickstart/contributing-to-projects#making-a-pull-request) in this repository, with the base branch set to **dev** and the compare branch set to your new branch. Provide a summary of your changes in the description. -6. If the automatic tests fail (these may take a while), please go back to your code and try to make them pass. You may have to update the tests themselves. You don't have to close the pull request while you're doing this; it'll update as you add further commits. +6. There are several automated checks that will run when you open the pull request. Try to make all of them pass. If you do not at least _attempt_ to make them pass, we will not merge your pull request. + 1. Tests. Update them so that they pass, if necessary. New tests are always welcome in any pull request, but if you have added a new feature that has decreased the coverage, new tests are required. + 2. Commit format validation. If you have not followed the conventional commits format for one or more of your commits, this will fail. + 3. Code format validation. If you have not formatted your code correctly (using Ruff, docformatter, and/or Prettier), this will fail. 7. Wait for feedback from one of the core maintainers. If it's been a week or so and we haven't responded, we may not have seen it. You can find other places to contact us in [SUPPORT.md](./.github/SUPPORT.md). ### Commits @@ -142,9 +145,9 @@ cz c ##### pre-commit -pre-commit is a tool that runs a variety of checks and modifications before a commit is made. You can check the [.pre-commit-config.yaml](./.pre-commit-config.yaml) file to see eaxtly what it's currently configured to do for this repository, but of particular note: +pre-commit is a tool that runs a variety of checks and modifications before a commit is made. You can check the [.pre-commit-config.yaml](./.pre-commit-config.yaml) file to see exactly what it's currently configured to do for this repository, but of particular note: -- reformats Python code with [Black](https://github.com/psf/black) +- reformats Python code with [Ruff](https://docs.astral.sh/ruff) - reformats JavaScript and stylesheets with [Prettier](https://prettier.io) - reformats docstrings with [docformatter](https://github.com/PyCQA/docformatter) - checks your commit message is correcly formatted @@ -161,15 +164,15 @@ pre-commit run Don't forget to stage any modifications that it makes! Once it runs without failing, then you can make your commit. -Something to remember is that empty docstrings will cause conflicts between Black and docformatter and the checks will fail repeatedly - so don't leave your docstrings empty! +Something to remember is that empty docstrings will cause conflicts between Ruff and docformatter and the checks will fail repeatedly - so don't leave your docstrings empty! ### Code changes and style guide -We generally use external style guides and tools to help us maintain standardised code. Black and Prettier will be run with pre-commit. +We generally use external style guides and tools to help us maintain standardised code. Ruff and Prettier will be run with pre-commit. #### Python -We follow the [Black style](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html), with the notable exception that we use single quotes. +We use [Ruff](https://docs.astral.sh/ruff) to format our code, using defaults for everything except quote style (we use single quotes). We also _mostly_ use [CKAN's style](http://docs.ckan.org/en/latest/contributing/python.html), with the following exceptions: - prefer `f''` strings over `.format()` @@ -178,7 +181,7 @@ We also _mostly_ use [CKAN's style](http://docs.ckan.org/en/latest/contributing/ #### JavaScript and stylesheets (CSS, LESS, etc) -We use [Prettier](https://prettier.io) to format these files. +We use [Prettier](https://prettier.io) to format these files. As with Ruff, we use defaults for everything except quote style (we use single quotes). #### Accessibility From 6a9aed17374e2a3dbe5b80131bc33ce73a6263e5 Mon Sep 17 00:00:00 2001 From: Alice Butcher Date: Tue, 29 Oct 2024 17:48:28 +0000 Subject: [PATCH 05/13] chore: add pull request template --- .github/PULL_REQUEST_TEMPLATE.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..5f5ce3c --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,4 @@ +- [ ] I have read the [section on commits and pull requests](https://github.com/NaturalHistoryMuseum/ckanext-webview/blob/main/CONTRIBUTING.md#commits-and-pull-requests) in `CONTRIBUTING.md` + + +Describe your changes, tagging relevant issues where possible. From 6bdae9a49435e62622e6a0da3c0e944cb580d51e Mon Sep 17 00:00:00 2001 From: Alice Butcher Date: Tue, 29 Oct 2024 17:48:35 +0000 Subject: [PATCH 06/13] build: remove version from docker compose file version specifier is deprecated --- docker-compose.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a935674..609303d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3" - services: ckan: build: From f0684e2bccbdc07397663466cea780a976330a91 Mon Sep 17 00:00:00 2001 From: Alice Butcher Date: Wed, 30 Oct 2024 12:47:06 +0000 Subject: [PATCH 07/13] ci: only apply auto-fixes in pre-commit F401 returns linting errors as well as auto-fixes, so this disables the errors and just applies the fixes --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 728e347..cd0f8b7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,7 @@ repos: rev: v0.7.1 hooks: - id: ruff - args: [ '--fix', '--select', 'I', '--select', 'F401' ] + args: [ '--fix', '--select', 'I', '--select', 'F401', '--fix-only' ] - id: ruff-format - repo: https://github.com/PyCQA/docformatter rev: eb1df34 From 9eb410f0a73a423a6396f7340173bb168db5733f Mon Sep 17 00:00:00 2001 From: Ginger Burns Date: Wed, 30 Oct 2024 14:52:01 +0000 Subject: [PATCH 08/13] ci: add docformatter args and dependency docformatter currently can't read from pyproject.toml without tomli --- .pre-commit-config.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cd0f8b7..04e9d79 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,14 +7,14 @@ repos: - id: detect-private-key - id: end-of-file-fixer - id: name-tests-test - args: ["--pytest-test-first"] + args: ['--pytest-test-first'] exclude: ^tests/helpers/ - id: trailing-whitespace - repo: https://github.com/commitizen-tools/commitizen rev: v3.30.0 hooks: - id: commitizen - additional_dependencies: ["cz-nhm"] + additional_dependencies: ['cz-nhm'] - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.7.1 hooks: @@ -25,6 +25,8 @@ repos: rev: eb1df34 hooks: - id: docformatter + args: [ '-i', '--config', './pyproject.toml' ] + additional_dependencies: ['tomli'] - repo: https://github.com/pre-commit/mirrors-prettier rev: v4.0.0-alpha.8 hooks: From f8502569671d57b77a1d78565f0185bc7b65ae5c Mon Sep 17 00:00:00 2001 From: Ginger Burns Date: Wed, 30 Oct 2024 17:33:05 +0000 Subject: [PATCH 09/13] style: automatic reformat auto reformat with ruff/docformatter/prettier after config changes --- ckanext/webview/plugin.py | 13 +++++++------ docs/_scripts/gen_api_pages.py | 1 - tests/test_validators.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ckanext/webview/plugin.py b/ckanext/webview/plugin.py index d4de555..205a1b6 100644 --- a/ckanext/webview/plugin.py +++ b/ckanext/webview/plugin.py @@ -5,6 +5,7 @@ # Created by the Natural History Museum in London, UK from ckan.plugins import SingletonPlugin, implements, interfaces, toolkit + from ckanext.webview.logic.validators import is_valid_url, not_datastore ignore_empty = toolkit.get_validator('ignore_empty') @@ -20,8 +21,8 @@ class WebviewPlugin(SingletonPlugin): ## IConfigurer def update_config(self, config): - toolkit.add_template_directory(config, u'theme/templates') - toolkit.add_resource(u'theme/assets', u'ckanext-webview') + toolkit.add_template_directory(config, 'theme/templates') + toolkit.add_resource('theme/assets', 'ckanext-webview') ## IResourceView def info(self): @@ -46,15 +47,15 @@ def setup_template_variables(self, context, data_dict): return {'web_url': web_url} def view_template(self, context, data_dict): - ''' + """ :param context: :param data_dict: - ''' + """ return 'views/web_view.html' def form_template(self, context, data_dict): - ''' + """ :param context: :param data_dict: - ''' + """ return 'views/web_view_form.html' diff --git a/docs/_scripts/gen_api_pages.py b/docs/_scripts/gen_api_pages.py index a0e0c1a..f208736 100644 --- a/docs/_scripts/gen_api_pages.py +++ b/docs/_scripts/gen_api_pages.py @@ -1,6 +1,5 @@ # !/usr/bin/env python # encoding: utf-8 - """ Generate the code reference pages and navigation. diff --git a/tests/test_validators.py b/tests/test_validators.py index 4a2421f..6a60f42 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -1,10 +1,10 @@ from unittest.mock import MagicMock import pytest -from ckanext.webview.logic.validators import is_valid_url, not_datastore - from ckan.plugins import toolkit +from ckanext.webview.logic.validators import is_valid_url, not_datastore + class TestIsValidURL(object): def test_valid_https(self): From 314b54966c26fca1f5f653a6c7bdfda0b7c3a064 Mon Sep 17 00:00:00 2001 From: Ginger Burns Date: Mon, 4 Nov 2024 09:50:20 +0000 Subject: [PATCH 10/13] ci: add merge to valid commit types --- .github/workflows/pull-requests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index b9aa2bd..134e108 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -14,7 +14,7 @@ jobs: - name: Check commit message format uses: webiny/action-conventional-commits@v1.3.0 with: - allowed-commit-types: 'feat,fix,refactor,perf,docs,style,test,build,ci,chore,new,patch,revert,ui' + allowed-commit-types: 'feat,fix,refactor,perf,docs,style,test,build,ci,chore,new,patch,revert,ui,merge' pre-commit: name: Run pre-commit checks runs-on: ubuntu-latest From 901d74b017350bf77e0c95de1097764c1541630e Mon Sep 17 00:00:00 2001 From: Ginger Burns Date: Mon, 4 Nov 2024 10:08:38 +0000 Subject: [PATCH 11/13] ci: fix python setup action version --- .github/workflows/pypi-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index d3ac620..bf30290 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -19,7 +19,7 @@ jobs: token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@5 + uses: actions/setup-python@v5 - name: Install dependencies run: | python -m pip install --upgrade pip From 8d1ce366021556f242ccaf6a4ad267025d0aef51 Mon Sep 17 00:00:00 2001 From: Ginger Burns Date: Mon, 4 Nov 2024 11:18:23 +0000 Subject: [PATCH 12/13] docs: fix tests badge tests workflow file was renamed --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 672e668..780c902 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # ckanext-webview -[![Tests](https://img.shields.io/github/actions/workflow/status/NaturalHistoryMuseum/ckanext-webview/main.yml?style=flat-square)](https://github.com/NaturalHistoryMuseum/ckanext-webview/actions/workflows/main.yml) +[![Tests](https://img.shields.io/github/actions/workflow/status/NaturalHistoryMuseum/ckanext-webview/tests.yml?style=flat-square)](https://github.com/NaturalHistoryMuseum/ckanext-webview/actions/workflows/tests.yml) [![Coveralls](https://img.shields.io/coveralls/github/NaturalHistoryMuseum/ckanext-webview/main?style=flat-square)](https://coveralls.io/github/NaturalHistoryMuseum/ckanext-webview) [![CKAN](https://img.shields.io/badge/ckan-2.9.7-orange.svg?style=flat-square)](https://github.com/ckan/ckan) [![Python](https://img.shields.io/badge/python-3.6%20%7C%203.7%20%7C%203.8-blue.svg?style=flat-square)](https://www.python.org/) From cbd7c1a2279231dc288fba0c8427640abf0d8014 Mon Sep 17 00:00:00 2001 From: Ginger Burns Date: Mon, 4 Nov 2024 11:25:08 +0000 Subject: [PATCH 13/13] docs: use variable logo based on colour scheme --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 780c902..3de361a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ - + + + + The Natural History Museum logo. + # ckanext-webview