diff --git a/.coveragerc b/.coveragerc index 8703b933..aa747a0b 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,5 +1,6 @@ [run] branch = True +relative_files = True source = src/ omit = .coveragerc diff --git a/.github/workflows/python-coverage.yml b/.github/workflows/python-coverage.yml new file mode 100644 index 00000000..00b9d3a8 --- /dev/null +++ b/.github/workflows/python-coverage.yml @@ -0,0 +1,62 @@ +name: Python CI Coverage + +on: + push: + branches: [ "main", "develop", "feature/*" ] + pull_request: + branches: [ "main" ] + +env: + LOG_LEVEL: INFO + +jobs: + + build: + name: "Run CI" + strategy: + fail-fast: false + matrix: + os: ["ubuntu-latest"] + python: ['3.12'] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Setup Python + uses: actions/setup-python@master + with: + python-version: ${{ matrix.python }} + + - name: Install + run: | + pip3 install -r requirements.txt + + - name: Test an coverage collect + run: | + python3 -m coverage run -m pytest --verbose -o log_cli=true --log-cli-level=INFO src/ + + - name: Coverage Report + run: | + python3 -m coverage report + + - name: Coverage lcov + run: | + python3 -m coverage lcov -o coverage/lcov.info + + - name: Upload coverage reports to Codecov with GitHub Action + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} # required + verbose: true # optional (default = false) + + - name: Coverage XML + run: | + python3 -m coverage xml + + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index d66c8819..3c38141f 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -1,4 +1,4 @@ -name: Python +name: Python CI Tests on: push: @@ -58,9 +58,3 @@ jobs: - name: Coverage run: | coverage report - - - name: Upload coverage reports to Codecov with GitHub Action - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} # required - verbose: true # optional (default = false) diff --git a/.sonarcloud.properties b/.sonarcloud.properties deleted file mode 100644 index 31587d1a..00000000 --- a/.sonarcloud.properties +++ /dev/null @@ -1,12 +0,0 @@ -# Must be unique in a given SonarQube instance -sonar.projectKey=algorithm-exercises-py -sonar.projectName=algorithm-exercises-py - -# Path is relative to the sonar-project.properties file. -# Replace "\" by "/" on Windows. -# This property is optional if sonar.modules is set. -sonar.sources=src - -# Encoding of the source code. Default is default system encoding -sonar.sourceEncoding=UTF-8 -sonar.python.version=3.12 diff --git a/README.md b/README.md index 2016b211..8266a51a 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,12 @@ ![GitHub language count](https://img.shields.io/github/languages/count/sir-gon/algorithm-exercises-py) ![GitHub top language](https://img.shields.io/github/languages/top/sir-gon/algorithm-exercises-py) +[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-py&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-py) +[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-py&metric=coverage)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-py) +[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-py&metric=bugs)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-py) +[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-py&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-py) +[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-py&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-py) + ## What is this? [Project Euler](https://algorithm-exercises.net/) provide some algorithms and diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 00000000..63d81bf5 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,26 @@ +sonar.projectKey=sir-gon_algorithm-exercises-py +sonar.organization=sir-gon + +# This is the name and version displayed in the SonarCloud UI. +#sonar.projectName=algorithm-exercises-py +#sonar.projectVersion=1.0 + + +# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. +# sonar.sources=src +sonar.exclusions=**/*test.py,**/__init__.py + +# Encoding of the source code. Default is default system encoding +#sonar.sourceEncoding=UTF-8 + +sonar.python.version=3.12 + +# Coverage +sonar.python.coverage.reportPaths=coverage.xml + +# Ignore +sonar.issue.ignore.multicriteria=e1 + +# python:S6792 Use the "type" parameter syntax to declare this generic class. +sonar.issue.ignore.multicriteria.e1.ruleKey=python:S6792 +sonar.issue.ignore.multicriteria.e1.resourceKey=**/*.py diff --git a/src/projecteuler/lib/binary_node.py b/src/projecteuler/lib/binary_node.py index ccfc2955..ea65475a 100644 --- a/src/projecteuler/lib/binary_node.py +++ b/src/projecteuler/lib/binary_node.py @@ -4,6 +4,9 @@ T = TypeVar("T") +# Recommended way to define Generics in python >= 3.12: +# https://peps.python.org/pep-0695/ +# https://docs.python.org/3.12/whatsnew/3.12.html#pep-695-type-parameter-syntax class BinaryNode(Generic[T]): def __init__( self,