ChartBoost / ruff-action

A GitHub Action for Ruff
Apache License 2.0
121 stars 21 forks source link

FileNotFoundError: [Errno 2] No such file or directory: 'pipx' #4

Closed johanneszellinger closed 5 months ago

johanneszellinger commented 1 year ago

I have the following workflow yml:

name: Code Checking

on:
  workflow_dispatch:
  pull_request:

jobs:
  code-analysis:
    name: Code analysis, linting, pytest
    runs-on: [ self-hosted ]
    permissions:
      contents: read

    steps:
      - name: Check out the repo
        uses: actions/checkout@v3

      - name: Setup Python Environment
        uses: actions/setup-python@v4
        with:
          python-version: '3.11' 

      - name: Install project and dependencies
        run: |
          pip install mydependencypackage/.
          pip install mypythonproject/.

      - name: Run Ruff
        uses: chartboost/ruff-action@v1

Which will lead to the following error:

Run if [ "$RUNNER_OS" == "Windows" ]; then Traceback (most recent call last): File "/home/larry/actions-runner/_work/_actions/chartboost/ruff-action/v1/action/main.py", line 23, in proc = run(["pipx", "run", req, shlex.split(ARGS), shlex.split(SRC)]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/larry/actions-runner/_work/_tool/Python/3.11.4/x64/lib/python3.11/subprocess.py", line 548, in run with Popen(*popenargs, **kwargs) as process: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/larry/actions-runner/_work/_tool/Python/3.11.4/x64/lib/python3.11/subprocess.py", line 1026, in init self._execute_child(args, executable, preexec_fn, close_fds, File "/home/larry/actions-runner/_work/_tool/Python/3.11.4/x64/lib/python3.11/subprocess.py", line 1950, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'pipx' Error: Process completed with exit code 1.

Which seems to be fixed by changing the step before running ruff to

      - name: Install project and dependencies
        run: |
          pip install mydependencypackage/.
          pip install mypythonproject/.
          pip install pipx

Not sure if I even should install pipx, but in any case, shouldn't the whole setup be done by the github action anyway? Apart from that the action seems to run perfectly fine (it fails telling me about all my code issues :D ).

brucearctor commented 1 year ago

Not sure about the windows problem, if that comes first, or is definitely related.

GH Actions [ on GH hosted runners ] comes preinstalled with software. If you're using self-hosted runner, why not have those runners already have the things [ like pipx ] installed for you, so you aren't installing on each run?

https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners

johanneszellinger commented 1 year ago

Thanks for the fast response! :) I don't think Windows is the issue here, all our runners are Linux based. The thing is, the runners are actually Kubernetes PODs which are spun up for each triggered action and destroyed afterwards. Since these are used by many of my colleagues for very different use cases we have to install all we need on the fly, unfortunately.

brucearctor commented 10 months ago

Actually, am leaning towards closing this issue -- pipx comes by default with the default GitHub actions, which is why it is believed to be there [ assumed 'dependency' ]. Therefore, I should probably update docs to that pipx is a requirement of this action. As an alternative, we could probably add some additional logic in the action to run relevant commands in other ways and/or install pipx if it doesn't already exist.

DSNJTurtle commented 6 months ago

I have the same issue on GitHub enterprise runners, which also do not seem to have pipx installed by default. Would be great if the ruff action could include this as a required dependency.

jamiekt commented 5 months ago

I agree it would be nice if pipx could be installed by the action. Our org uses self-hosted runners which do not (yet) have pipx installed upon them. Its easily worked around using

      - name: Install pipx # required dependency for chartboost/ruff-action
        run: python -m pip install --upgrade pip pipx

but it would be more elegant if I didn't have to.

brucearctor commented 5 months ago

I expect most users have pipx either installed on their self-hosted runner. Otherwise, I can't even assume all users have pip. It would be hard to extend to address ALL of the scenarios that might be needed to get the required dependencies. It would also be silly to install pipx again, if it were already installed [ would slow down existing users ].

Marking this as closed. But, would be happy to continue discussion on a new issue/design-doc [ if anyone wants to create ] towards determining whether there are sane ways to address this while also not bloating this targeted/limited-purpose GH Action.