From 643888ee72ec5e1ac257a08a659b9dff35ae67b4 Mon Sep 17 00:00:00 2001 From: JesperDramsch Date: Tue, 10 Dec 2024 09:48:28 +0000 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=94=84=20synced=20local=20'.github/wo?= =?UTF-8?q?rkflows/'=20with=20remote=20'workflows/code-quality/'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/codeql.yml | 67 +++++------------------------------- 1 file changed, 9 insertions(+), 58 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 067a864..30d0c0d 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -1,74 +1,25 @@ -# 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" +# .github/workflows/codeql.yml +name: CodeQL Analysis on: push: - branches: [ "main" ] + branches: [ main, master ] pull_request: - # The branches below must be a subset of the branches above - branches: [ "main" ] + branches: [ main, master ] schedule: - - cron: '27 20 * * 0' + - cron: '0 0 * * 0' 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. + - uses: actions/checkout@v4 - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 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 - + languages: python - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - with: - category: "/language:${{matrix.language}}" + uses: github/codeql-action/analyze@v3 From 6a51ee506dce721c35bc2f3cd85708da01096cd3 Mon Sep 17 00:00:00 2001 From: JesperDramsch Date: Tue, 10 Dec 2024 09:48:28 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=94=84=20created=20local=20'.github/d?= =?UTF-8?q?ependabot.yml'=20from=20remote=20'configs/dependabot.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/dependabot.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..57535d9 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: +- package-ecosystem: "pip" + directory: "/" + schedule: + interval: "daily" +- package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" From 1fb45bc93e779d618a8e60a1df99162062548527 Mon Sep 17 00:00:00 2001 From: JesperDramsch Date: Tue, 10 Dec 2024 09:48:28 +0000 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=94=84=20synced=20local=20'.github/wo?= =?UTF-8?q?rkflows/'=20with=20remote=20'workflows/python/'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pre-commit.yml | 18 +++++++++++++ .github/workflows/python-linting.yml | 26 +++++++++++++++++++ .github/workflows/python-publish.yml | 28 ++++++++++++++++++++ .github/workflows/python-testing.yml | 38 ++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .github/workflows/python-linting.yml create mode 100644 .github/workflows/python-publish.yml create mode 100644 .github/workflows/python-testing.yml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..23a8fc9 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,18 @@ +# .github/workflows/pre-commit.yml +name: Pre-commit Checks + +on: + pull_request: + push: + branches: [ main, master ] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + cache: 'pip' + - uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/python-linting.yml b/.github/workflows/python-linting.yml new file mode 100644 index 0000000..b3b5098 --- /dev/null +++ b/.github/workflows/python-linting.yml @@ -0,0 +1,26 @@ +# .github/workflows/python-linting.yml +name: Lint + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.x' + cache: 'pip' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ruff black + - name: Run Black + run: black . --check -l 120 + - name: Run Ruff + run: ruff check . diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml new file mode 100644 index 0000000..f6c807b --- /dev/null +++ b/.github/workflows/python-publish.yml @@ -0,0 +1,28 @@ +# .github/workflows/python-publish.yml +name: Publish to PyPI + +on: + release: + types: [ published ] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + cache: 'pip' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install build twine + - name: Build package + run: python -m build + - name: Publish to PyPI + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + run: twine upload dist/* diff --git a/.github/workflows/python-testing.yml b/.github/workflows/python-testing.yml new file mode 100644 index 0000000..fd6fbfa --- /dev/null +++ b/.github/workflows/python-testing.yml @@ -0,0 +1,38 @@ +# .github/workflows/python-testing.yml +name: Python Tests + +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.8', '3.9', '3.10', '3.11'] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest pytest-cov pytest-mock pytest-emoji + pip install -e . + - name: Run tests + run: | + pytest --cov=./ --cov-report=xml --emoji + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5 + with: + file: ./coverage.xml + fail_ci_if_error: true + + From d2a30af6c4ed960195562827b41515e399ed2d6b Mon Sep 17 00:00:00 2001 From: JesperDramsch Date: Tue, 10 Dec 2024 09:48:28 +0000 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=94=84=20synced=20local=20'./'=20with?= =?UTF-8?q?=20remote=20'configs/python/'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 211 ++++++++++++++++++++++++++++++++--------- .pre-commit-config.yml | 56 +++++++++++ ruff.toml | 61 ++++++++++++ 3 files changed, 284 insertions(+), 44 deletions(-) create mode 100644 .pre-commit-config.yml create mode 100644 ruff.toml diff --git a/.gitignore b/.gitignore index bb23d83..74d610e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,50 +1,173 @@ -# Global ignore patters. They cause the files with the following names and -# extensions to be ignored in general by Git. -# -# We ignore these files because they're usually binary and/or very large, which -# greatly bloats the repository and its clone time. In this category are the -# files .h5/.hdf5/.txt/.log and files named *log_file*. Some of these logs are -# enormous. -# -# We also ignore files that can be easily reproduced one way or another by -# compilers, like .pyc/.o/.so/.a/.lib. -# -# Lastly we ignore files and directories that signal their temporary character -# with a name that contains "tmp". -# -# **************************************************************************** -# ** DO NOT put ignore patterns here that are private to your clone of this ** -# ** repository. Those belong in your clone's .git/info/exclude file. ** -# **************************************************************************** -# -**/*.h5 -**/*.hdf5 -**/*.txt -**/*log_file* -**/*.log -**/*.out -**/*.pyc -**/*.o -**/*.so -**/*.a -**/*.lib -**/*.dll -**/*.exe -**/*tmp* -**/*.yaml -**/*.npy -**/slurm-*.out -keras_complex.egg-info/ +_site +.bundle +vendor +.vscode +.DS_Store +.idea +.tmp + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py -# Ignore virtual environment -venv +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env .venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ -# IDE -.vscode -.idea +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ -dist/* +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ -__pycache__/* \ No newline at end of file +utils/tidy_conf/data/.tmp/ +# pixi environments +.pixi +*.egg-info diff --git a/.pre-commit-config.yml b/.pre-commit-config.yml new file mode 100644 index 0000000..0cf98ed --- /dev/null +++ b/.pre-commit-config.yml @@ -0,0 +1,56 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: check-yaml # Check YAML files for syntax errors + - id: debug-statements # Check for debugger imports and py37+ breakpoint() + - id: end-of-file-fixer # Ensure files end in a newline + - id: trailing-whitespace # Trailing whitespace checker + - id: check-added-large-files # Check for large files added to git + - id: check-merge-conflict # Check for files that contain merge conflict strings +- repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 # Use the ref you want to point at + hooks: + - id: python-use-type-annotations # Check for missing type annotations + - id: python-check-blanket-noqa # Check for # noqa: all + - id: python-no-log-warn # Check for log.warn +- repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + args: + - -l 120 + - --force-single-line-imports + - --profile black +- repo: https://github.com/asottile/pyupgrade # Upgrade Python syntax + rev: v3.15.2 + hooks: + - id: pyupgrade + args: + - --py310-plus +- repo: https://github.com/psf/black # Format Python code + rev: 24.4.2 + hooks: + - id: black + args: + - --line-length=120 +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.4.4 + hooks: + - id: ruff + args: + - --line-length=120 + - --fix + - --exit-non-zero-on-fix + - --preview +- repo: https://github.com/jshwi/docsig # Check docstrings against function sig + rev: v0.53.2 + hooks: + - id: docsig + args: + - --ignore-no-params # Allow docstrings without parameters + - --check-dunders # Check dunder methods + - --check-overridden # Check overridden methods + - --check-protected # Check protected methods + - --check-class # Check class docstrings + - --disable=E113 # Disable empty docstrings diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..3e7557b --- /dev/null +++ b/ruff.toml @@ -0,0 +1,61 @@ +line-length = 120 +target-version = "py310" +preview = true + +[lint] +select = [ + "A", # flake8 builtins + "B", # flake8-bugbear + "D", # pydocstyle + "E", # pycodestyle error + "W", # pycodestyle warning + "F", # flake8 error + "UP", # Pyupgrade + "SIM", # flake8-simplify + "N", # pep8 naming + "YTT", # flake8-2020 + "S", # bandit + "COM", # Commas + "C4", # Comprehensions + "DTZ", # Datetimes + "ISC", # Implicit string concatenation + "ICN", # Import conventions + "LOG", # Logging + "PIE", # Misc lints + "PT", # Pytest + "Q", # Quotes + "RSE", # Raises + "TID", # Tidy imports + "PTH", # Use Pathlib + "PGH", # Pygrep hooks + "R", # Refactor + "FLY", # Fstrings + "PERF", # Perfomance linting + "FURB", # Modernising code + "RUF", # Ruff specific + "NPY", # Numpys + # "PL", # Pylint + # "TD", # Todos + # "FBT", # Boolean traps + # "CPY", # Copyright +] +ignore = [ + "E203", + "D100", + "D101", + "D102", + "D103", + "D104", + "D105", + "D401", + "S101", + "B028", + "B018", + "PT018", + "RET504", + +] + + +[lint.pydocstyle] +convention = "numpy" From 33db6b2daad69f9b6bdc0a8baa5690e6e932184e Mon Sep 17 00:00:00 2001 From: JesperDramsch Date: Tue, 10 Dec 2024 09:48:28 +0000 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=94=84=20created=20local=20'.github/w?= =?UTF-8?q?orkflows/labeler.yml'=20from=20remote=20'workflows/issue-pr/lab?= =?UTF-8?q?eler.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/labeler.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/labeler.yml diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 0000000..e57cd86 --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,12 @@ +name: "Pull Request Labeler" +on: +- pull_request_target + +jobs: + labeler: + permissions: + contents: read + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: actions/labeler@v5 From 46ff42f5f296af821ada55537fad41924d992915 Mon Sep 17 00:00:00 2001 From: JesperDramsch Date: Tue, 10 Dec 2024 09:48:28 +0000 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=94=84=20created=20local=20'.github/l?= =?UTF-8?q?abeler.yml'=20from=20remote=20'configs/labeler.yml'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/labeler.yml | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/labeler.yml diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 0000000..aa9b60f --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,63 @@ +Tests: +- changed-files: + - any-glob-to-any-file: [ "tests/**/*" ] + +Dependencies: +- changed-files: + - any-glob-to-any-file: + - "requirements.txt" + - "setup.py" + - "pyproject.toml" + - "poetry.lock" + - "pixi.toml" + - "pixi.lock" + - "Pipfile" + - "Pipfile.lock" + - "requirements/*.txt" + - "requirements/*.in" + +Build: +- changed-files: + - any-glob-to-any-file: + - "Dockerfile*" + - "docker-compose*.yml" + - "Makefile" + +Documentation: +- changed-files: + - any-glob-to-any-file: + - "docs/**/*" + - "*.md" + - "*.rst" + +Config: +- changed-files: + - any-glob-to-any-file: + - ".pre-commit-config.yaml" + - "config/**/*" + - "settings/**/*" + - "*.ini" + - "*.cfg" + - "*.conf" + +CI/CD: +- changed-files: + - any-glob-to-any-file: + - ".github/**/*" + - "tox.ini" + - ".coveragerc" + +# Add 'feature' label to any PR where the head branch name starts with `feature` or has a `feature` section in the name +feature: +- head-branch: + - '^feature' + - 'feature' + +# Add 'bugfix' label to branches with bug/fix/hotfix prefixes +bugfix: +- head-branch: [ '^bug', '^fix', '^hotfix' ] + +# Add 'breaking' label for major version bumps or breaking change commits +breaking: +- title: [ '^BREAKING CHANGE', 'BREAKING-CHANGE' ] +- body: [ 'BREAKING CHANGE:', 'BREAKING-CHANGE:' ]