From cdcc7a88f9376920f225948c8ce9e925dd5f38fd Mon Sep 17 00:00:00 2001 From: Abel Soares Siqueira Date: Wed, 2 Oct 2024 17:35:14 +0200 Subject: [PATCH] Implement ExplicitImports hook in main repo Manually add an ExplicitImports pre-commit hook. Related to #349 --- .github/scripts/explicit-imports.sh | 25 +++++++++++++++++++++++++ .github/workflows/Lint.yml | 6 ++++-- .pre-commit-config.yaml | 9 +++++++++ src/debug/Debug.jl | 2 +- 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100755 .github/scripts/explicit-imports.sh diff --git a/.github/scripts/explicit-imports.sh b/.github/scripts/explicit-imports.sh new file mode 100755 index 00000000..02369c4c --- /dev/null +++ b/.github/scripts/explicit-imports.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +module=$1 + +# Check that $module is not empty +if [ -z "$module" ]; then + echo "Module was not passed. 'args: [Module]' should be included in the pre-commit config" +fi + +julia -e " + using Pkg + pkg\"activate\" + + using ExplicitImports: ExplicitImports + pkg\"activate .\" + + using $module + ExplicitImports.check_all_explicit_imports_are_public($module) + # ExplicitImports.check_all_qualified_accesses_are_public($module) # disabled due to #471 + ExplicitImports.check_all_explicit_imports_via_owners($module) + ExplicitImports.check_all_qualified_accesses_via_owners($module) + ExplicitImports.check_no_implicit_imports($module) + ExplicitImports.check_no_self_qualified_accesses($module) + ExplicitImports.check_no_stale_explicit_imports($module) +" diff --git a/.github/workflows/Lint.yml b/.github/workflows/Lint.yml index d2ca8ab9..c7b623d6 100644 --- a/.github/workflows/Lint.yml +++ b/.github/workflows/Lint.yml @@ -26,8 +26,10 @@ jobs: version: "1" - name: Use Julia cache uses: julia-actions/cache@v2 - - name: Install JuliaFormatter.jl - run: julia -e 'using Pkg; pkg"add JuliaFormatter"' + - name: Build package (required for ExplicitImports) + uses: julia-actions/julia-buildpkg@v1 + - name: Install Julia packages + run: julia -e 'using Pkg; pkg"add ExplicitImports, JuliaFormatter"' - name: Hack for setup-python cache # https://github.com/actions/setup-python/issues/807 run: touch requirements.txt - name: Setup Python diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 42e2e283..f6780ebf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -44,6 +44,15 @@ repos: rev: v1.35.1 hooks: - id: yamllint + - repo: local + hooks: + - id: explicit-imports + name: ExplicitImports checks + entry: .github/scripts/explicit-imports.sh + args: [BestieTemplate] + files: ^src.*\.jl$ + language: script + pass_filenames: false - repo: https://github.com/domluna/JuliaFormatter.jl rev: v1.0.60 hooks: diff --git a/src/debug/Debug.jl b/src/debug/Debug.jl index 30aeaecc..5ead8aff 100644 --- a/src/debug/Debug.jl +++ b/src/debug/Debug.jl @@ -11,7 +11,7 @@ Noteworthy: [`BestieTemplate.Debug.Data`](@ref) """ module Debug -using ..BestieTemplate: BestieTemplate, generate, apply +using ..BestieTemplate: BestieTemplate include("Data.jl") include("helper.jl")