Skip to content

Commit

Permalink
feat: pre-commit and more extensive rust linting (prefix-dev#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofer-Julian authored Dec 3, 2024
1 parent dd49557 commit ede51b8
Show file tree
Hide file tree
Showing 9 changed files with 2,133 additions and 1,018 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Pre-commit

on:
push:
branches: [ "main" ]
pull_request:

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up pixi
uses: prefix-dev/[email protected]
with:
environments: lint
- name: pre-commit
run: pixi run pre-commit-run --color=always --show-diff-on-failure
4 changes: 2 additions & 2 deletions .github/workflows/rattler-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
TARGET_PLATFORM: ${{ matrix.target }}
RECIPE_VERSION: ${{ needs.generate_version.outputs.version }}
RATTLER_BUILD_ENABLE_GITHUB_INTEGRATION: "true"
RATTLER_BUILD_COLOR: "always"
RATTLER_BUILD_COLOR: "always"
run: |
pixi r -e build-self rattler-build build --recipe recipe/recipe.yaml --output-dir=$RUNNER_TEMP --target-platform=${{ env.TARGET_PLATFORM }} --experimental --test native
- name: Upload all packages
Expand All @@ -65,7 +65,7 @@ jobs:
if: github.event_name == 'push' && matrix.os != 'windows-latest'
run: |
# ignore errors because we want to ignore duplicate packages
for file in $RUNNER_TEMP/**/*.conda; do
for file in "$RUNNER_TEMP"/**/*.conda; do
echo "Uploading ${file}"
pixi r -e build-self rattler-build upload prefix -c pixi-build-backends "$file"
done
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rust-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Run rustfmt
uses: actions-rust-lang/rustfmt@v1
- name: Run clippy
run: cargo clippy --all-targets
run: cargo clippy --all-targets --workspace

test:
name: Test
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:

- name: Run tests
run: >
cargo nextest run --workspace
cargo nextest run --workspace --all-targets
- name: Run doctests
run: >
Expand Down
40 changes: 40 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
exclude: (^.pixi/|.snap)
repos:
- repo: local
hooks:
- id: check-yaml
name: check-yaml
entry: pixi run -e lint check-yaml
language: system
types: [yaml]
- id: end-of-file
name: end-of-file
entry: pixi run -e lint end-of-file-fixer
language: system
types: [text]
stages: [pre-commit, pre-push, manual]
- id: trailing-whitespace
name: trailing-whitespace
entry: pixi run -e lint trailing-whitespace-fixer
language: system
types: [text]
stages: [pre-commit, pre-push, manual]
# GitHub Actions
- id: actionlint
name: Lint GitHub Actions workflow files
language: system
entry: pixi run -e lint actionlint
types: [yaml]
files: ^\.github/workflows/
# typos
- id: typos
name: typos
entry: pixi run -e lint typos --write-changes --force-exclude
language: system
types: [text]
# TOML format
- id: taplo
name: taplo
entry: pixi run -e lint toml-format
language: system
types: [file, toml]
4 changes: 2 additions & 2 deletions crates/pixi-build/src/bin/pixi-build-python/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl PythonBuildBackend {

/// Returns the capabilities of this backend based on the capabilities of
/// the frontend.
pub fn capabilites(
pub fn capabilities(
&self,
_frontend_capabilities: &FrontendCapabilities,
) -> BackendCapabilities {
Expand Down Expand Up @@ -558,7 +558,7 @@ impl ProtocolFactory for PythonBuildBackendFactory {
params.cache_directory,
)?;

let capabilities = instance.capabilites(&params.capabilities);
let capabilities = instance.capabilities(&params.capabilities);
Ok((instance, InitializeResult { capabilities }))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl RattlerBuildBackend {

/// Returns the capabilities of this backend based on the capabilities of
/// the frontend.
pub fn capabilites(
pub fn capabilities(
&self,
_frontend_capabilities: &FrontendCapabilities,
) -> BackendCapabilities {
Expand Down Expand Up @@ -354,7 +354,7 @@ impl ProtocolFactory for RattlerBuildBackendFactory {
params.cache_directory,
)?;

let capabilities = instance.capabilites(&params.capabilities);
let capabilities = instance.capabilities(&params.capabilities);
Ok((instance, InitializeResult { capabilities }))
}
}
Expand Down
3,014 changes: 2,025 additions & 989 deletions pixi.lock

Large diffs are not rendered by default.

59 changes: 40 additions & 19 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,42 @@ platforms = ["osx-arm64", "win-64", "linux-64", "osx-64"]

[tasks]
run-release = { cmd = "cargo run --release", inputs = [
"crates/**",
"Cargo.toml",
"Cargo.lock",
"crates/**",
"Cargo.toml",
"Cargo.lock",
], outputs = [
"target/debug/**",
"target/debug/**",
] }

build = { cmd = "cargo build", inputs = [
"crates/**",
"Cargo.toml",
"Cargo.lock",
"crates/**",
"Cargo.toml",
"Cargo.lock",
], outputs = [
"target/debug/**",
"target/debug/**",
] }
build-release = { cmd = "cargo build --release", inputs = [
"crates/**",
"Cargo.toml",
"Cargo.lock",
"crates/**",
"Cargo.toml",
"Cargo.lock",
], outputs = [
"target/release/**",
"target/release/**",
] }
run = { cmd = "cargo run", inputs = [
"crates/**",
"Cargo.toml",
"Cargo.lock",
"crates/**",
"Cargo.toml",
"Cargo.lock",
], outputs = [
"target/debug/**",
"target/debug/**",
] }


install-pixi-build-python = { cmd = "cargo install --path crates/pixi-build --bin pixi-build-python --locked"}
install-pixi-build-cmake = { cmd = "cargo install --path crates/pixi-build --bin pixi-build-cmake --locked"}
install-pixi-backends = { depends-on = ["install-pixi-build-python", "install-pixi-build-cmake"] }
install-pixi-build-python = { cmd = "cargo install --path crates/pixi-build --bin pixi-build-python --locked" }
install-pixi-build-cmake = { cmd = "cargo install --path crates/pixi-build --bin pixi-build-cmake --locked" }
install-pixi-backends = { depends-on = [
"install-pixi-build-python",
"install-pixi-build-cmake",
] }

[dependencies]
rust = "~=1.80.1"
Expand All @@ -64,7 +67,25 @@ generate-schema = "python schema/model.py > schema/schema.json"
fmt-schema = "ruff format schema"
lint-schema = "ruff check schema --fix"

[feature.lint.dependencies]
actionlint = ">=1.7.4,<2"
pre-commit = ">=3.7.1,<4"
pre-commit-hooks = ">=4.6.0,<5"
shellcheck = ">=0.10.0,<0.11"
taplo = ">=0.9.1,<0.10"
typos = ">=1.23.1,<2"

[feature.lint.tasks]
actionlint = { cmd = "actionlint", env = { SHELLCHECK_OPTS = "-e SC2086" } }
lint = "pre-commit run --all-files --hook-stage=manual"
pre-commit-install = "pre-commit install"
pre-commit-run = "pre-commit run --all-files"
toml-format = { cmd = "taplo fmt", env = { RUST_LOG = "warn" } }
toml-lint = "taplo lint --verbose **/pixi.toml"


[environments]
test = ["test"]
schema = { no-default-feature = true, features = ["schema"] }
lint = { features = ["lint"], no-default-feature = true }
build-self = { no-default-feature = true, features = ["build-self"] }
4 changes: 2 additions & 2 deletions tests/recipe/boltons/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ source:

build:
noarch: python
script:
script:
- python -m pip install . --no-deps -vv

requirements:
Expand All @@ -32,4 +32,4 @@ requirements:

about:
license: BSD-3-Clause
license_file: LICENSE
license_file: LICENSE

0 comments on commit ede51b8

Please sign in to comment.