Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Alpine Linux #22

Open
tomassebestik opened this issue Aug 23, 2024 · 5 comments
Open

Support for Alpine Linux #22

tomassebestik opened this issue Aug 23, 2024 · 5 comments
Assignees
Labels
🐛 Bug Something isn't working

Comments

@tomassebestik
Copy link

Problem description

Hello,

First of all, thank you for this project! This is finally a nice, working, and configurable TOML formatter usable as a pre-commit hook.

On local machines, everything works great, but we also have a GitLab CI job with pre-commit to ensure the codebase is formatted even if developers forget to install pre-commit in the repo on their local machines.

This CI job uses an Alpine Docker image (python:3.11-alpine3.18), and currently, it is failing with:

[INFO] Installing environment for https://github.com/ComPWA/mirrors-taplo.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/root/.cache/pre-commit/reporohe5gkc/py_env-python3.11/bin/python', '-mpip', 'install', '.')
return code: 1
stdout:
    Processing /root/.cache/pre-commit/reporohe5gkc
      Preparing metadata (setup.py): started
      Preparing metadata (setup.py): finished with status 'done'
    Collecting taplo==0.9.3 (from pre_commit_placeholder_package==0.0.0)
      Downloading taplo-0.9.3.tar.gz (102 kB)
         ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 102.6/102.6 kB 4.2 MB/s eta 0:00:00
      Installing build dependencies: started
      Installing build dependencies: finished with status 'done'
      Getting requirements to build wheel: started
      Getting requirements to build wheel: finished with status 'done'
      Preparing metadata (pyproject.toml): started
      Preparing metadata (pyproject.toml): finished with status 'error'
stderr:
      error: subprocess-exited-with-error
      
      × Preparing metadata (pyproject.toml) did not run successfully.
      │ exit code: 1
      ╰─> [6 lines of output]
          
          Cargo, the Rust package manager, is not installed or is not on PATH.
          This package requires Rust and Cargo to compile extensions. Install it through
          the system's package manager or via https://rustup.rs/
          
          Checking for Rust toolchain....
          [end of output]

The issue here, I believe, is the missing Python wheel for Alpine Linux (musl), so the installer tries to compile it from source and fails.

Right now due to missing Alpine support, we can't add https://github.com/ComPWA/mirrors-taplo to our standard hooks for all projects, which I would very much like to do.

Proposed solution

Is it possible to add and maintain support for Alpine Linux?

(Alpine Linux is widely used for CI, and many people could benefit from this.)

What should the interface look like?

No response

Additional context

No response

@redeboer
Copy link
Member

Thanks for reporting! This is an upstream problem with the taplo package on PyPI, see tamasfe/taplo#658.

@redeboer
Copy link
Member

      × Preparing metadata (pyproject.toml) did not run successfully.
      │ exit code: 1
      ╰─> [6 lines of output]
          
          Cargo, the Rust package manager, is not installed or is not on PATH.
          This package requires Rust and Cargo to compile extensions. Install it through
          the system's package manager or via https://rustup.rs/
          
          Checking for Rust toolchain....
          [end of output]

Btw interesting to see that pip falls back to compiling with Rust. You can retry with cargo installed, but the build will probably take a few minutes...

@redeboer redeboer added the 🐛 Bug Something isn't working label Aug 23, 2024
@tomassebestik
Copy link
Author

Thank you, @redeboer, for the quick response and for reporting the issue to Taplo.


... You can retry with cargo installed, but the build will probably take a few minutes...

I tested it in that Alpine container with Rust installed - that fails too:

## (bind the current dir to the clean Alpine Python container)
$ docker run -it --rm -v $(pwd):/src -w /src --entrypoint=/bin/sh python:3.11-alpine3.18

## (in the container ....install Rust)
/src # apk add curl gcc
/src # curl –proto ‘=https’ –tlsv1.2 -sSf https://sh.rustup.rs | sh
/src # source $HOME/.cargo/env
/src # rustc --version
rustc 1.80.1 (3f5fd8dd4 2024-08-06)

## (set git)
/src # apk add git
/src # git init
/src # git config --global --add safe.directory /src

## (set pre-commit)
/src # pip install pre-commit
/src # pre-commit install

## (run pre-commit hook taplo-format)
/src # pre-commit run taplo-format --all-files
[INFO] Installing environment for https://github.com/ComPWA/mirrors-taplo.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/root/.cache/pre-commit/repovjupyw8e/py_env-python3.11/bin/python', '-mpip', 'install', '.')
return code: 1
stdout:
    Processing /root/.cache/pre-commit/repovjupyw8e
      Preparing metadata (setup.py): started
      Preparing metadata (setup.py): finished with status 'done'
    Collecting taplo==0.9.3 (from pre_commit_placeholder_package==0.0.0)
      Using cached taplo-0.9.3.tar.gz (102 kB)
      Installing build dependencies: started
      Installing build dependencies: finished with status 'done'
      Getting requirements to build wheel: started
      Getting requirements to build wheel: finished with status 'done'
      Preparing metadata (pyproject.toml): started
      Preparing metadata (pyproject.toml): finished with status 'error'
stderr:
      error: subprocess-exited-with-error
      
      × Preparing metadata (pyproject.toml) did not run successfully.
      │ exit code: 1
      ╰─> [17 lines of output]
          error: failed to load manifest for workspace member `/tmp/pip-install-nuxvxbqj/taplo_b4abb58585984f8f9c74160c05eb512b/crates/taplo-cli`
          referenced by workspace at `/tmp/pip-install-nuxvxbqj/taplo_b4abb58585984f8f9c74160c05eb512b/Cargo.toml`
          
          Caused by:
            failed to load manifest for dependency `taplo-lsp`
          
          Caused by:
            failed to read `/tmp/pip-install-nuxvxbqj/taplo_b4abb58585984f8f9c74160c05eb512b/crates/taplo-lsp/Cargo.toml`
          
          Caused by:
            No such file or directory (os error 2)
          💥 maturin failed
            Caused by: Cargo metadata failed. Does your crate compile with `cargo build`?
            Caused by: `cargo metadata` exited with an error:
          Error running maturin: Command '['maturin', 'pep517', 'write-dist-info', '--metadata-directory', '/tmp/pip-modern-metadata-iapqu48z', '--interpreter', '/root/.cache/pre-commit/repovjupyw8e/py_env-python3.11/bin/python']' returned non-zero exit status 1.
          Checking for Rust toolchain....
          Running `maturin pep517 write-dist-info --metadata-directory /tmp/pip-modern-metadata-iapqu48z --interpreter /root/.cache/pre-commit/repovjupyw8e/py_env-python3.11/bin/python`
          [end of output]
      
      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: metadata-generation-failed
    
    × Encountered error while generating package metadata.
    ╰─> See above for output.
    
    note: This is an issue with the package mentioned above, not pip.
    hint: See above for details.
Check the log at /root/.cache/pre-commit/pre-commit.log

@redeboer
Copy link
Member

Fix is being prepared in tamasfe/taplo#659. If you can, you could already try installing taplo by installing from the artifacts there (taplo format directly, not via pre-commit). It works in an alpine Docker container: tamasfe/taplo#659 (comment)

I tested it in that Alpine container with Rust installed

Thanks, interesting that it got some steps further at least :)

@tomassebestik
Copy link
Author

That looks good!

$ docker run -it --rm -v $(pwd):/src -w /src --entrypoint=/bin/sh -e NOPERM_GH_TOKEN python:3.11-alpine3.18

/src # apk add curl unzip
/src # curl -L -H "Authorization: token $NOPERM_GH_TOKEN" -o wheels.zip https://api.github.com/repos/ta
masfe/taplo/actions/artifacts/1847999815/zip
/src # unzip wheels.zip -d wheels

/src # pip install --no-index --find-links wheels/ taplo
  Looking in links: wheels/
  Processing ./wheels/taplo-0.9.3-py3-none-musllinux_1_1_x86_64.whl
  Installing collected packages: taplo
  Successfully installed taplo-0.9.3

/src # taplo format pyproject.toml
 INFO taplo:format_files:load_config: found configuration file path="taplo.toml"
 INFO taplo:format_files:collect_files: found files total=1 excluded=0 cwd="/src"

Thanks again for all your work on this, looking forward to working with the pre-commit hook. 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants