diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 4eb1d53..49ba8e6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,3 +9,4 @@ updates: directory: "/" schedule: interval: "monthly" + target-branch: "develop" diff --git a/.github/workflows/issue_to_jira.yml b/.github/workflows/issue_to_jira.yml new file mode 100644 index 0000000..009b3f3 --- /dev/null +++ b/.github/workflows/issue_to_jira.yml @@ -0,0 +1,36 @@ +# This workflow will create a JIRA issue upon creation of a GitHub issue + +name: Create JIRA issue + +on: + issues: + types: [opened] + +jobs: + new_jira_issue: + runs-on: ubuntu-latest + + steps: + - name: JIRA Login + uses: atlassian/gajira-login@v3.0.1 + env: + JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} + JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} + JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} + - name: Jira Create issue + id: create_jira_issue + uses: atlassian/gajira-create@v3.0.1 + with: + project: GEOPY + issuetype: Story + summary: ${{ github.event.issue.title }} + description: "_from [GitHub issue #${{ github.event.issue.number }}|${{ github.event.issue.html_url }}]_" + # Additional fields in JSON format + fields: '{"components": [{"name": "LAS"}]}' + - name: Post JIRA link + uses: peter-evans/create-or-update-comment@v3 + with: + # The number of the issue or pull request in which to create a comment. + issue-number: ${{ github.event.issue.number }} + # The comment body. + body: "JIRA issue [${{ steps.create_jira_issue.outputs.issue }}] was created." diff --git a/.github/workflows/pr_add_jira_summary.yml b/.github/workflows/pr_add_jira_summary.yml new file mode 100644 index 0000000..11f4f9b --- /dev/null +++ b/.github/workflows/pr_add_jira_summary.yml @@ -0,0 +1,50 @@ +# This workflow will comment the PR with the JIRA issue summary +# if a JIRA issue number is detected in the branch name or title + +name: Add JIRA issue summary + +on: + pull_request_target: + types: [opened] + +jobs: + add_jira_summary: + runs-on: ubuntu-latest + + steps: + - name: Find JIRA issue key + id: find_jira_key + env: + HEAD_REF: ${{ github.head_ref}} + PR_TITLE: ${{ github.event.pull_request.title }} + run: > + echo $HEAD_REF $PR_TITLE + | echo "issue_key=$(grep -os "\b\(GA\|GEOPY\)-[0-9]\+" | head -n1)" >> $GITHUB_OUTPUT + - name: Get JIRA summary + id: get_jira_summary + if: ${{ steps.find_jira_key.outputs.issue_key }} + env: + JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} + JIRA_BASIC_AUTH: ${{ secrets.JIRA_BASIC_AUTH }} + run: > + curl -sS -X GET + -H "Authorization: Basic $JIRA_BASIC_AUTH" + -H "Content-Type: application/json" + "$JIRA_BASE_URL/rest/api/2/issue/${{ steps.find_jira_key.outputs.issue_key }}" + | echo "summary=$(jq -r '.fields.summary')" >> $GITHUB_OUTPUT + - name: Add comment + if: ${{ steps.find_jira_key.outputs.issue_key }} + env: + ISSUE_SUMMARY: ${{ steps.get_jira_summary.outputs.summary }} + PR_BODY: ${{ github.event.pull_request.body }} + run: > + jq + --arg ISSUE_ID "${{ steps.find_jira_key.outputs.issue_key }}" + --arg ISSUE_SUMMARY "$(cat <<< $ISSUE_SUMMARY)" + --arg PR_BODY "$(cat <<< $PR_BODY)" + -c '."body"="**" + $ISSUE_ID + " - " + $ISSUE_SUMMARY + "**\n" + $PR_BODY' <<< {} + | curl -sS -X POST -d @- + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" + -H "Content-Type: application/json" + "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/pulls/${{ github.event.pull_request.number }}" + > /dev/null diff --git a/.github/workflows/pytest-windows.yml b/.github/workflows/pytest-windows.yml index fb290d6..8ceb13d 100644 --- a/.github/workflows/pytest-windows.yml +++ b/.github/workflows/pytest-windows.yml @@ -71,4 +71,3 @@ jobs: uses: codecov/codecov-action@v3 with: name: GitHub - token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 0abc1f4..5d9b515 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -24,34 +24,6 @@ env: source_dir: las_geoh5 jobs: - pre-commit: - name: pre-commit - strategy: - fail-fast: false - runs-on: ubuntu-latest - env: - SKIP: pylint - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - - name: capture modified files - if: github.event_name == 'pull_request' - run: >- - git fetch --deepen=500 origin ${{github.base_ref}} - && echo "FILES_PARAM=$( - git diff --diff-filter=AM --name-only refs/remotes/origin/${{github.base_ref}}... -- | grep -E "^(${source_dir}|tests)/.*\.py$" | xargs - )" >> $GITHUB_ENV - - name: Run pre-commit on modified files - if: github.event_name == 'pull_request' && env.FILES_PARAM - uses: pre-commit/action@v3.0.0 - with: - extra_args: --hook-stage push --files ${{ env.FILES_PARAM }} - - name: Run pre-commit on all files - if: github.event_name == 'push' - uses: pre-commit/action@v3.0.0 - with: - extra_args: --hook-stage push --all-files - pylint: name: pylint runs-on: ubuntu-latest diff --git a/.idea/scopes/sources.xml b/.idea/scopes/sources.xml index 18500c7..c282b03 100644 --- a/.idea/scopes/sources.xml +++ b/.idea/scopes/sources.xml @@ -1,3 +1,3 @@ - \ No newline at end of file + diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1ef9d80..e0d3260 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,18 +12,14 @@ ci: repos: - repo: https://github.com/psf/black - rev: 23.7.0 + rev: 23.10.1 hooks: - id: black -- repo: https://github.com/asottile/seed-isort-config - rev: v2.2.0 - hooks: - - id: seed-isort-config - repo: https://github.com/PyCQA/isort rev: 5.12.0 hooks: - id: isort - additional_dependencies: [toml] # to read config from pyproject.toml + additional_dependencies: [tomli] # to read config from pyproject.toml - repo: https://github.com/humitos/mirrors-autoflake rev: v1.1 hooks: @@ -33,17 +29,23 @@ repos: hooks: - id: flake8 - repo: https://github.com/asottile/pyupgrade - rev: v3.10.1 + rev: v3.15.0 hooks: - id: pyupgrade args: [--py39-plus] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.4.1 + rev: v1.6.1 hooks: - id: mypy - additional_dependencies: [types-toml] - args: [--ignore-missing-imports, --scripts-are-modules, --show-error-context, - --show-column-numbers] + additional_dependencies: [ + types-toml, + tomli, # to read config from pyproject.toml + ] +- repo: https://github.com/codingjoe/relint + rev: 3.1.0 + hooks: + - id: relint + args: [-W] # to fail on warnings - repo: local hooks: - id: pylint @@ -57,16 +59,17 @@ repos: name: Check copyright entry: python devtools/check-copyright.py language: python - types: [python] - exclude: (^setup.py$|(docs|assets)/) + files: (^LICENSE|README.rst|\.py|\.pyi)$ + types: [text] + exclude: (^setup.py$|^\.|\b(docs|assets)/) - repo: https://github.com/codespell-project/codespell - rev: v2.2.5 + rev: v2.2.6 hooks: - id: codespell - exclude: (\.ipynb$|poetry.lock) + exclude: (.lock|\.ipynb|^THIRD_PARTY_SOFTWARE\.rst)$ entry: codespell -I .codespellignore - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: trailing-whitespace exclude: \.mdj$ @@ -82,11 +85,13 @@ repos: - id: mixed-line-ending - id: name-tests-test - repo: https://github.com/rstcheck/rstcheck - rev: v6.1.2 + rev: v6.2.0 hooks: - id: rstcheck + exclude: ^THIRD_PARTY_SOFTWARE.rst$ additional_dependencies: [sphinx] - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.10.0 hooks: - id: rst-backticks + exclude: ^THIRD_PARTY_SOFTWARE.rst$ diff --git a/.relint.yml b/.relint.yml new file mode 100644 index 0000000..ab30728 --- /dev/null +++ b/.relint.yml @@ -0,0 +1,10 @@ +- name: No import os.path + pattern: 'from os import\b.*\bpath\b' + hint: Use from pathlib import Path + filePattern: .*\.pyi? + error: false +- name: No os.path + pattern: '\bos\.path\b' + hint: Use pathlib.Path + filePattern: .*\.pyi? + error: false diff --git a/poetry.lock b/poetry.lock index b9d9ae0..26357e8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.5.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. [[package]] name = "astroid" @@ -449,17 +449,6 @@ pytest = ">=4.6" [package.extras] testing = ["fields", "hunter", "process-tests", "pytest-xdist", "six", "virtualenv"] -[[package]] -name = "toml" -version = "0.10.2" -description = "Python Library for Tom's Obvious, Minimal Language" -optional = false -python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" -files = [ - {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, - {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, -] - [[package]] name = "tomli" version = "2.0.1" @@ -516,4 +505,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.9, <3.11" -content-hash = "e6f3412dda94e37d730c88a5409d8da5ea4ded367e4586d569e6835e2b371214" +content-hash = "4127e273dfa98db6f602ca57656e865dfee0fdc658e5b9648660c0df1f4cc9ae" diff --git a/pyproject.toml b/pyproject.toml index 6d16065..c88c452 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,17 +9,17 @@ python = "^3.9, <3.11" ## dependencies on github repos #geoh5py = { url = "https://github.com/MiraGeoscience/geoh5py/archive/refs/heads/release/0.8.0.zip#sha256=" } -geoh5py = {version ="~0.8.0rc1", source = "pypi", allow-prereleases = true} +geoh5py = {version ="~0.8.0rc1", allow-prereleases = true} ## pip dependencies -lasio = {version = "~0.31", source = "pypi", allow-prereleases = true} -tqdm = {version = "^4.64.0"} +lasio = "~0.31" +tqdm = "^4.64.0" [tool.poetry.dev-dependencies] pylint = "*" pytest = "*" pytest-cov = "*" -toml = "*" +tomli = "*" [tool.isort] # settings for compatibility between ``isort`` and ``black`` formatting @@ -28,12 +28,44 @@ include_trailing_comma = true force_grid_wrap = 0 use_parentheses = true line_length = 88 -# auto-updated by seed-isort-config -known_third_party = ["geoh5py", "lasio", "numpy", "pytest", "toml", "tqdm"] [tool.black] # defaults are just fine +[tool.mypy] +warn_unused_configs = true +ignore_missing_imports = true +scripts_are_modules = true +show_error_context = true +show_column_numbers = true +check_untyped_defs = true + +plugins = [ + # 'numpy.typing.mypy_plugin' +] + +[tool.pytest.ini_options] +addopts = "--cov las_geoh5 --cov-report html --cov-report term-missing:skip-covered" + +[tool.coverage.run] +branch = true +source = ["las_geoh5"] +omit = [] + +[tool.coverage.report] +exclude_lines = [ + "raise NotImplementedError", + "pass", + "if TYPE_CHECKING", + "pragma: no cover" +] + +fail_under = 80 + +[tool.coverage.html] +skip_empty = true +skip_covered = true + [build-system] requires = ["poetry-core>=1.0.0", "setuptools"] build-backend = "poetry.core.masonry.api" diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..22692c4 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,21 @@ +# Copyright (c) 2023 Mira Geoscience Ltd. +# +# This file is part of las_geoh5 project. +# +# All rights reserved. + +from __future__ import annotations + +from pathlib import Path + +import pytest +import tomli as toml + + +@pytest.fixture +def pyproject() -> dict: + """Return the pyproject.toml as a dictionary.""" + + pyproject_path = Path(__file__).resolve().parents[1] / "pyproject.toml" + with open(pyproject_path, "rb") as pyproject_file: + return toml.load(pyproject_file) diff --git a/tests/version_test.py b/tests/version_test.py index 6192edf..d8249bf 100644 --- a/tests/version_test.py +++ b/tests/version_test.py @@ -7,24 +7,12 @@ from __future__ import annotations import re -from pathlib import Path - -import toml import las_geoh5 -def get_version(): - path = Path(__file__).resolve().parents[1] / "pyproject.toml" - - with open(str(path), encoding="utf-8") as file: - pyproject = toml.loads(file.read()) - - return pyproject["tool"]["poetry"]["version"] - - -def test_version_is_consistent(): - assert las_geoh5.__version__ == get_version() +def test_version_is_consistent(pyproject: dict): + assert las_geoh5.__version__ == pyproject["tool"]["poetry"]["version"] def test_version_is_semver():