From c43fa25a76bc87d2d179f1c0891508d5fe5468d7 Mon Sep 17 00:00:00 2001 From: Adrien Berchet Date: Fri, 27 Jan 2023 17:01:56 +0100 Subject: [PATCH] CI: Apply Copier template (#55) --- .auto-changelog | 2 +- .auto-changelog-template.hbs | 21 ++++++-- .copier-answers.yml | 2 +- .gitattributes | 2 + .github/dependabot.yml | 13 +++++ .github/workflows/codeql.yml | 71 +++++++++++++++++++++++++++ .github/workflows/commitlint.yml | 8 +-- .github/workflows/publish-sdist.yml | 8 +-- .github/workflows/run-tox.yml | 31 ++++++++++-- commitlint.config.js | 6 +++ neurots/astrocyte/context.py | 1 + neurots/generate/algorithms/common.py | 2 + pyproject.toml | 3 +- setup.py | 2 +- tox.ini | 9 ++-- 15 files changed, 154 insertions(+), 27 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/codeql.yml diff --git a/.auto-changelog b/.auto-changelog index 26bf2b47..6a107aba 100644 --- a/.auto-changelog +++ b/.auto-changelog @@ -3,7 +3,7 @@ "template": ".auto-changelog-template.hbs", "commitLimit": false, "backfillLimit": false, - "ignoreCommitPattern": "Release [0-9]+\\.[0-9]+\\.[0-9]+|Update CHANGELOG.*|.*\\[skip-changelog\\].*|\\[pre-commit.ci\\]", + "ignoreCommitPattern": "Release:? [0-9]+\\.[0-9]+\\.[0-9]+|Update CHANGELOG.*|.*\\[skip-changelog\\].*|\\[pre-commit.ci\\]", "commitUrl": "https://github.com/BlueBrain/NeuroTS/commit/{id}", "issueUrl": "https://github.com/BlueBrain/NeuroTS/issues/{id}", "mergeUrl": "https://github.com/BlueBrain/NeuroTS/pull/{id}", diff --git a/.auto-changelog-template.hbs b/.auto-changelog-template.hbs index 20953c34..5a2c3f90 100644 --- a/.auto-changelog-template.hbs +++ b/.auto-changelog-template.hbs @@ -9,6 +9,7 @@ Introduction • The types feat:, fix:, chore:, docs:, refactor:, test:, style:, perf: must be at the beginning of the commit subject with an : on end. • They can optionally have a scope set to outline the module or component that is affected eg feat(bldAssess): • There is a short hash on the end of every commit that is currently commented out so that change log did not grow too long (due to some system's file size limitations). You can uncomment if you wish [`{{shorthash}}`]({{href}}) + Example Definitions • feat: A new feature • fix: A bug fix @@ -30,6 +31,8 @@ Example Definitions "replaceText": { "([bB]reaking:)": "", "([bB]reaking change:)": "", + "(^[bB]uild:)": "", + "(^[bB]uild\\()": "\\(", "(^[fF]eat:)": "", "(^[fF]eat\\()": "\\(", "(^[fF]ix:)": "", @@ -59,7 +62,7 @@ Example Definitions \s = whitespace . = any character except newline | = or - [aA] = charcter a or character A + [aA] = character a or character A --}} @@ -87,7 +90,11 @@ Example Definitions {{/commit-list}} {{! List commits organised under a heading, but not those already listed in the breaking section }} - {{#commit-list merges heading='### New Features' message='^[fF]eat:|[fF]eat\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}} + {{#commit-list merges heading='### Build' message='^[bB]uild:|^[bB]uild\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}} + - {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}}) + {{/commit-list}} + + {{#commit-list merges heading='### New Features' message='^[fF]eat:|^[fF]eat\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}} - {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}}) {{/commit-list}} @@ -123,7 +130,7 @@ Example Definitions - {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}}) {{/commit-list}} - {{#commit-list merges heading='### Uncategorized Changes' exclude='[bB]reaking [cC]hange:|[bB]reaking:|^[fF]eat:|^[fF]eat\(|^[fF]ix:|^[fF]ix\(|^[cC]hore:|^[cC]hore\(|^[cC][iI]:|^[cC][iI]\(|^[dD]ocs:|^[dD]ocs\(|^[rR]efactor:|^[rR]efactor\(|^[tT]est:|^[tT]est\(|^[sS]tyle:|^[sS]tyle\(|^[pP]erf:|^[pP]erf\(|\[skip-changelog\]'}} + {{#commit-list merges heading='### General Changes' exclude='[bB]reaking [cC]hange:|[bB]reaking:|^[bB]uild:|^[bB]uild\(|^[fF]eat:|^[fF]eat\(|^[fF]ix:|^[fF]ix\(|^[cC]hore:|^[cC]hore\(|^[cC][iI]:|^[cC][iI]\(|^[dD]ocs:|^[dD]ocs\(|^[rR]efactor:|^[rR]efactor\(|^[tT]est:|^[tT]est\(|^[sS]tyle:|^[sS]tyle\(|^[pP]erf:|^[pP]erf\(|\[skip-changelog\]'}} - {{message}} ({{author}}{{#if href}} - [#{{id}}]({{href}}){{/if}}) {{/commit-list}} @@ -133,7 +140,11 @@ Example Definitions {{/commit-list}} {{! List commits organised under a heading, but not those already listed in the breaking section }} - {{#commit-list commits heading='### New Features' message='^[fF]eat:|[fF]eat\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}} + {{#commit-list commits heading='### Build' message='^[bB]uild:|^[bB]uild\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}} + - {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}}) + {{/commit-list}} + + {{#commit-list commits heading='### New Features' message='^[fF]eat:|^[fF]eat\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:|\[skip-changelog\]'}} - {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}}) {{/commit-list}} @@ -169,7 +180,7 @@ Example Definitions - {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}}) {{/commit-list}} - {{#commit-list commits heading='### Uncategorized Changes' exclude='[bB]reaking [cC]hange:|[bB]reaking:|^[fF]eat:|^[fF]eat\(|^[fF]ix:|^[fF]ix\(|^[cC]hore:|^[cC]hore\(|^[cC][iI]:|^[cC][iI]\(|^[dD]ocs:|^[dD]ocs\(|^[rR]efactor:|^[rR]efactor\(|^[tT]est:|^[tT]est\(|^[sS]tyle:|^[sS]tyle\(|^[pP]erf:|^[pP]erf\(|\[skip-changelog\]'}} + {{#commit-list commits heading='### General Changes' exclude='[bB]reaking [cC]hange:|[bB]reaking:|^[bB]uild:|^[bB]uild\(|^[fF]eat:|^[fF]eat\(|^[fF]ix:|^[fF]ix\(|^[cC]hore:|^[cC]hore\(|^[cC][iI]:|^[cC][iI]\(|^[dD]ocs:|^[dD]ocs\(|^[rR]efactor:|^[rR]efactor\(|^[tT]est:|^[tT]est\(|^[sS]tyle:|^[sS]tyle\(|^[pP]erf:|^[pP]erf\(|\[skip-changelog\]'}} - {{subject}} ({{author}}{{#if href}} - [{{shorthash}}]({{href}}){{/if}}) {{/commit-list}} diff --git a/.copier-answers.yml b/.copier-answers.yml index 874c6562..80166fa6 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,6 +1,6 @@ # Changes here will be overwritten by Copier -_commit: 0.1.9 +_commit: 0.1.33 _src_path: git@bbpgitlab.epfl.ch:neuromath/python-template.git author_email: '' author_name: Blue Brain Project, EPFL diff --git a/.gitattributes b/.gitattributes index 7a0362de..3f6122e7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,3 @@ *.asc linguist-detectable=false +.auto-changelog-template.hbs linguist-detectable=false +commitlint.config.js linguist-detectable=false diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..870e6546 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,13 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + # Configure check for outdated GitHub Actions actions in workflows. + # See: https://docs.github.com/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot + - package-ecosystem: "github-actions" + directory: "/" # Check the repository's workflows under /.github/workflows/ + schedule: + interval: "weekly" diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000..d8e65e9f --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,71 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "main" ] + schedule: + - cron: '56 17 * * 4' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'python' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # ℹ️ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index fd95bda9..47ab1b3d 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -9,11 +9,11 @@ jobs: name: Check PR title runs-on: ubuntu-latest steps: - - uses: actions/checkout@master - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: - node-version: '14' + node-version: '16' - run: npm install -g --force commitlint @commitlint/cli commitlint-plugin-cleanfeet - run: npm install conventional-changelog-conventionalcommits - run: touch .git/COMMIT_EDITMSG - - run: echo ${{ github.event.pull_request.title }} | commitlint + - run: echo "${{ github.event.pull_request.title }}" | commitlint diff --git a/.github/workflows/publish-sdist.yml b/.github/workflows/publish-sdist.yml index 1bbf6704..c48e4cd6 100644 --- a/.github/workflows/publish-sdist.yml +++ b/.github/workflows/publish-sdist.yml @@ -10,15 +10,15 @@ jobs: name: Build and publish on PyPI runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v3 - name: Set up Python 3.8 - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: 3.8 - name: Build a wheel and a source tarball run: | - pip install setuptools>=42 wheel setuptools_scm[toml]>=3.4 - python setup.py sdist bdist_wheel + pip install setuptools>=42 build setuptools_scm[toml]>=3.4 + python -m build -o dist - name: Publish distribution package to PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: diff --git a/.github/workflows/run-tox.yml b/.github/workflows/run-tox.yml index 57fe4547..038440d0 100644 --- a/.github/workflows/run-tox.yml +++ b/.github/workflows/run-tox.yml @@ -5,6 +5,7 @@ on: push: branches: - main + workflow_dispatch: jobs: build: @@ -15,28 +16,48 @@ jobs: python-version: ["3.8", "3.9", "3.10", "3.11"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + - name: Cache tox and precommit environments + uses: actions/cache@v3 + with: + path: | + .tox + ~/.cache/pre-commit + key: ${{ runner.os }}-${{ matrix.python-version }}-${{ steps.date.outputs.date }}-${{ hashFiles('setup.py') }}-${{ hashFiles('.pre-commit-config.yaml') }} - name: Install dependencies run: | python -m pip install --upgrade pip setuptools pip install tox-gh-actions + - name: Clear results in tox environments + run: | + rm -rf .tox/*/tmp - name: Run tox run: | tox - name: JUnit Report Action - uses: mikepenz/action-junit-report@v3.2.0 + uses: mikepenz/action-junit-report@v3 if: always() # always run even if the previous step fails with: report_paths: 'reports/pytest-*.xml' - name: Upload to codecov if: ${{matrix.python-version == '3.9'}} - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3 with: fail_ci_if_error: false files: ./coverage.xml flags: pytest - name: "NeuroTS" + name: "NeuroTS-py${{ matrix.python-version }}" + - name: Upload test artifacts + uses: actions/upload-artifact@v3 + if: always() + with: + name: tests-${{ matrix.python-version }} + retention-days: 4 + path: | + .tox/py*/tmp + docs/build + reports diff --git a/commitlint.config.js b/commitlint.config.js index c640e72a..80904874 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -25,6 +25,7 @@ module.exports = { 'Fix', 'Perf', 'Refactor', + 'Release', 'Revert', 'Style', 'Test', @@ -95,6 +96,11 @@ module.exports = { title: 'Reverts', emoji: '🗑', }, + Release: { + description: 'Release commit', + title: 'Release', + emoji: '🎉', + }, }, }, scope: { diff --git a/neurots/astrocyte/context.py b/neurots/astrocyte/context.py index 4a456db7..2eee4858 100644 --- a/neurots/astrocyte/context.py +++ b/neurots/astrocyte/context.py @@ -53,6 +53,7 @@ def __init__(self, coordinates): self.active = np.ones(len(coordinates), dtype=bool) def __len__(self): + """Return the number of active points.""" return len(self.active) @property diff --git a/neurots/generate/algorithms/common.py b/neurots/generate/algorithms/common.py index e296c773..39222f28 100644 --- a/neurots/generate/algorithms/common.py +++ b/neurots/generate/algorithms/common.py @@ -85,6 +85,7 @@ def __init__(self, bif_id, bif, term_id, term, ref): # self.verify() def __str__(self): + """Return the string representation of the TMDStop.""" return ( f"(Ref: {self.ref}, BifID: {self.bif_id}, Bif: {self.bif}, TermID: {self.term_id}, " f"Term: {self.term})" @@ -167,6 +168,7 @@ def expected_maximum_length(self): return abs(self.ref - max(self.bif, self.term)) def __eq__(self, other): + """Check for equality with another object.""" if isinstance(other, TMDStop): return ( self.bif_id == other.bif_id diff --git a/pyproject.toml b/pyproject.toml index 9e8b6e2c..187aeee4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,6 @@ target-version = [ "py38", "py39", ] -include = 'neurots\/.*\.py$|tests\/.*\.py$|doc\/source\/conf\.py$|setup\.py$|examples\/*.py$' # PYDOCSTYLE [tool.pydocstyle] @@ -24,7 +23,7 @@ add-ignore = [ "D107", ] convention = "google" -match = "[neurots, tests, docs/source/conf.py, setup.py, examples]" +match = 'neurots\/.*\.py$|docs\/source\/conf\.py$|setup\.py$|examples\/.*.py$' # ISORT [tool.isort] diff --git a/setup.py b/setup.py index dd6f7a8d..9f1428a3 100644 --- a/setup.py +++ b/setup.py @@ -74,6 +74,7 @@ "docs": doc_reqs, "test": test_reqs, }, + include_package_data=True, classifiers=[ "Development Status :: 4 - Beta", "Intended Audience :: Science/Research", @@ -86,5 +87,4 @@ "Programming Language :: Python :: 3.11", "Topic :: Scientific/Engineering :: Bio-Informatics", ], - include_package_data=True, ) diff --git a/tox.ini b/tox.ini index f57d9749..b1eb04e8 100644 --- a/tox.ini +++ b/tox.ini @@ -53,10 +53,10 @@ commands = [testenv:check-packaging] skip_install = true deps = - wheel + build twine commands = - python setup.py sdist bdist_wheel -d {envtmpdir}/dist + python -m build -o {envtmpdir}/dist twine check {envtmpdir}/dist/* [testenv:lint] @@ -75,13 +75,14 @@ deps = codespell pre-commit commands = - codespell -i 2 -x .codespellignorelines -w {[base]files} README.md CHANGELOG.md + codespell -i 3 -x .codespellignorelines -w {[base]files} README.md CHANGELOG.md docs/source pre-commit run --all-files [testenv:docs] changedir = docs extras = docs -allowlist_externals = make +allowlist_externals = + make # set warnings as errors using the -W sphinx option commands = make clean