From 099f90eac18fa59db4609884bb20c627cdba5ff9 Mon Sep 17 00:00:00 2001 From: Florian Pfaff Date: Sat, 12 Aug 2023 16:57:55 +0200 Subject: [PATCH 1/2] Upped mega linter to v7.3.0 and fixed issues --- .github/workflows/mega-linter.yml | 30 ++++++++----------- .github/workflows/update-requirements.yml | 1 + .mega-linter.yml | 1 + README.md | 2 +- .../nonperiodic/gaussian_distribution.py | 2 +- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/.github/workflows/mega-linter.yml b/.github/workflows/mega-linter.yml index d465aa7b..375a8b17 100644 --- a/.github/workflows/mega-linter.yml +++ b/.github/workflows/mega-linter.yml @@ -115,7 +115,6 @@ jobs: cd .. mv SHTOOLS/dist/*.whl ./alpine-wheels/ rm -rf SHTOOLS - rm -rf CMakeFiles elif ! pip download --only-binary=:all: --no-deps "$package" -d ./alpine-wheels > /dev/null 2>&1; then echo "No compatible wheel for $package found, building..." pip wheel --wheel-dir=./alpine-wheels "$package" @@ -128,25 +127,22 @@ jobs: - name: List available wheels run: ls -l ./alpine-wheels + - name: Clean up temporary files (in case they are generated) + run: rm -rf CMakeFiles CMakeCache.txt cmake_install.cmake Makefile + # MegaLinter - name: MegaLinter id: ml # You can override MegaLinter flavor used to have faster performances - # More info at https://megalinter.io/flavors/ - uses: oxsecurity/megalinter/flavors/python@v7.1.0 + # More info at https://megalinter.io/latest/configuration/#shared-variables + uses: oxsecurity/megalinter/flavors/python@v7.3.0 env: # All available variables are described in documentation - # https://megalinter.io/configuration/ - VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # Validates all source when push on main, else just the git diff with main. Override with true if you always want to lint all sources - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # https://megalinter.io/latest/configuration/#shared-variables # ADD YOUR CUSTOM ENV VARIABLES HERE OR DEFINE THEM IN A FILE .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY - # DISABLE: COPYPASTE,SPELL # Uncomment to disable copy-paste and spell checks - #with: - # args: -v ${{ github.workspace }}/cache-directory:/cache-directory - - #- name: List cache-directory contents - # if: ${{ success() }} || ${{ failure() }} - # run: ls -la ${{ github.workspace }}/cache-directory + VALIDATE_ALL_CODEBASE: true # ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # Validates all source when push on main, else just the git diff with main. Override with true if you always want to lint all sources + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + EMAIL_REPORTER_SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }} # Upload MegaLinter artifacts - name: Archive production artifacts @@ -161,7 +157,7 @@ jobs: # Create pull request if applicable (for now works only on PR from same repository, not from forks) - name: Create Pull Request with applied fixes id: cpr - if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) + if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix') uses: peter-evans/create-pull-request@v5 with: token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }} @@ -169,17 +165,17 @@ jobs: title: "[MegaLinter] Apply linters automatic fixes" labels: bot - name: Create PR output - if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) + if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix') run: | echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" # Push new commit if applicable (for now works only on PR from same repository, not from forks) - name: Prepare commit - if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) + if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix') run: sudo chown -Rc $UID .git/ - name: Commit and push applied linter fixes - if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) + if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix') uses: stefanzweifel/git-auto-commit-action@v4 with: branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }} diff --git a/.github/workflows/update-requirements.yml b/.github/workflows/update-requirements.yml index 1af0b665..8714d589 100644 --- a/.github/workflows/update-requirements.yml +++ b/.github/workflows/update-requirements.yml @@ -1,3 +1,4 @@ +--- name: Update requirements.txt permissions: diff --git a/.mega-linter.yml b/.mega-linter.yml index 873bc8b8..9e2d1fe9 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -12,3 +12,4 @@ DISABLE_LINTERS: - REPOSITORY_TRIVY # Reenable as soon as (if?) https://avd.aquasec.com/nvd/2021/cve-2021-29063/ confirms that 1.3.0 is no longer a risk - JSON_JSONLINT # Disable because there is only .devcontainer.json, for which it throws an unwanted warning - MAKEFILE_CHECKMAKE # Not using a Makefile + - REPOSITORY_GRYPE # Currently, a false alarm is raised diff --git a/README.md b/README.md index c0c77127..58c63c91 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Please refer to the test cases for usage examples. ## Credits -- Florian Pfaff (pfaff@kit.edu) +- Florian Pfaff () pyRecEst borrows its structure from libDirectional and follows its code closely for many classes. libDirectional, a project to which I contributed extensively, is [available on GitHub](https://github.com/libDirectional). diff --git a/pyrecest/distributions/nonperiodic/gaussian_distribution.py b/pyrecest/distributions/nonperiodic/gaussian_distribution.py index 6c685fb4..b9e1564b 100644 --- a/pyrecest/distributions/nonperiodic/gaussian_distribution.py +++ b/pyrecest/distributions/nonperiodic/gaussian_distribution.py @@ -73,7 +73,7 @@ def convolve(self, other): return GaussianDistribution(new_mu, new_C, check_validity=False) def marginalize_out(self, dimensions): - if type(dimensions) is int: # Make it iterable if single integer + if isinstance(dimensions, int): # Make it iterable if single integer dimensions = [dimensions] assert all(dim <= self.dim for dim in dimensions) remaining_dims = [i for i in range(self.dim) if i not in dimensions] From c41d767819b3de88e3573a06424acf3219c10e62 Mon Sep 17 00:00:00 2001 From: FlorianPfaff Date: Sat, 12 Aug 2023 16:17:52 +0000 Subject: [PATCH 2/2] [MegaLinter] Apply linters fixes --- .../hypertorus/custom_toroidal_distribution.py | 9 ++++++--- .../hypertorus/toroidal_von_mises_sine_distribution.py | 8 +++++++- .../test_hypercylindrical_dirac_distribution.py | 2 ++ .../distributions/test_wrapped_laplace_distribution.py | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pyrecest/distributions/hypertorus/custom_toroidal_distribution.py b/pyrecest/distributions/hypertorus/custom_toroidal_distribution.py index 08153201..364e89c8 100644 --- a/pyrecest/distributions/hypertorus/custom_toroidal_distribution.py +++ b/pyrecest/distributions/hypertorus/custom_toroidal_distribution.py @@ -1,7 +1,10 @@ -from .custom_hypertoroidal_distribution import CustomHypertoroidalDistribution from .abstract_toroidal_distribution import AbstractToroidalDistribution +from .custom_hypertoroidal_distribution import CustomHypertoroidalDistribution + -class CustomToroidalDistribution(CustomHypertoroidalDistribution, AbstractToroidalDistribution): +class CustomToroidalDistribution( + CustomHypertoroidalDistribution, AbstractToroidalDistribution +): def __init__(self, f): AbstractToroidalDistribution.__init__(self) - CustomHypertoroidalDistribution.__init__(self, f, 2) \ No newline at end of file + CustomHypertoroidalDistribution.__init__(self, f, 2) diff --git a/pyrecest/distributions/hypertorus/toroidal_von_mises_sine_distribution.py b/pyrecest/distributions/hypertorus/toroidal_von_mises_sine_distribution.py index ab089a3d..7699d304 100644 --- a/pyrecest/distributions/hypertorus/toroidal_von_mises_sine_distribution.py +++ b/pyrecest/distributions/hypertorus/toroidal_von_mises_sine_distribution.py @@ -21,7 +21,13 @@ def __init__(self, mu, kappa, lambda_): @property def norm_const(self): def s(m): - return comb(2 * m, m) * (self.lambda_ ** 2 / 4 / self.kappa[0] / self.kappa[1]) ** m * iv(m, self.kappa[0]) * iv(m, self.kappa[1]) + return ( + comb(2 * m, m) + * (self.lambda_**2 / 4 / self.kappa[0] / self.kappa[1]) ** m + * iv(m, self.kappa[0]) + * iv(m, self.kappa[1]) + ) + Cinv = 4 * np.pi**2 * np.sum([s(m) for m in range(11)]) return Cinv diff --git a/pyrecest/tests/distributions/test_hypercylindrical_dirac_distribution.py b/pyrecest/tests/distributions/test_hypercylindrical_dirac_distribution.py index 3251b9bb..212be897 100644 --- a/pyrecest/tests/distributions/test_hypercylindrical_dirac_distribution.py +++ b/pyrecest/tests/distributions/test_hypercylindrical_dirac_distribution.py @@ -56,8 +56,10 @@ def test_reweigh(self): # Define functions for testing def f1(x): return np.sum(x, axis=-1) == 3 + def f2(x): return 2 * np.ones(x.shape[0]) + def f3(x): return x[:, 0] diff --git a/pyrecest/tests/distributions/test_wrapped_laplace_distribution.py b/pyrecest/tests/distributions/test_wrapped_laplace_distribution.py index 42aea50b..f0dde446 100644 --- a/pyrecest/tests/distributions/test_wrapped_laplace_distribution.py +++ b/pyrecest/tests/distributions/test_wrapped_laplace_distribution.py @@ -28,6 +28,7 @@ def laplace(x): def pdftemp(x): return sum(laplace(z) for z in x + 2 * np.pi * np.arange(-20, 21)) + for x in [0, 1, 2, 3, 4]: np.testing.assert_allclose(self.wl.pdf(x), pdftemp(x), rtol=1e-10)