astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
13.6k stars 466 forks source link

`IO error: not a terminal` in GitHub Actions from `rye publish` #1258

Open jamesbraza opened 2 months ago

jamesbraza commented 2 months ago

Steps to Reproduce

I have a GitHub Action that looks like so with Python 3.12.4:

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: eifinger/setup-rye@v4
        with:
          enable-cache: true
      - run: rye sync --no-lock
      - run: rye build --sdist --wheel
      - run: rye publish --token ${{ secrets.PYPI_API_TOKEN }}

When I run it, the rye publish step fails with error: IO error: not a terminal

Expected Result

I expected this publish job to work

Actual Result

The below error during rye publish:

Run rye publish --token ***
  rye publish --token ***
  shell: /usr/bin/bash -e {0}
  env:
    RYE_HOME: /opt/hostedtoolcache/setup-rye-2024-03-04/0.37.0/x86_64

error: IO error: not a terminal

Caused by:
    not a terminal

Error: Process completed with exit code 1.

https://github.com/astral-sh/rye/issues/246 seems to have the same error

Version Info

0.37.0 via https://github.com/eifinger/setup-rye

Stacktrace

No response

jamesbraza commented 2 months ago

Also cc @eifinger if he has seen this before

eifinger commented 2 months ago

Also cc @eifinger if he has seen this before

I have not seen this before. I usually use pypi-publish to publish to PyPi.

Can you replace my action with

run: curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash

To make sure the bug is with rye itself instead of eifinger/setup-rye?

jamesbraza commented 2 months ago

Okay actually I am having a tough time getting the manual install to work. The URL you shared gives a "301 Moved Permanently" error. I am now using:

    steps:
      - uses: actions/checkout@v4
      - run: |
          curl -sSf https://rye.astral.sh/get | RYE_INSTALL_OPTION="--yes" bash
          echo "$HOME/.rye/env" >> $GITHUB_PATH
      - run: rye sync --no-lock

But this still gives line 1: rye: command not found in the last run step. Do you know what I am doing wrong here?

charliermarsh commented 2 months ago

Not sure what's going on but it does look like you're being prompted. I doubt it's a bug in the Action.

charliermarsh commented 2 months ago

Not clear if twine is prompting you or Rye.

jamesbraza commented 2 months ago

Okay gotchu. Can you give any tips on how to discern if twine or Rye is prompting? Sorry I am just not sure how to take the root causing further here without your or @eifinger 's help as I don't know the internals

charliermarsh commented 2 months ago

No worries. If you run that sequence of commands locally with (1) an invalid token, and then (2) a valid token, what do you see?

jamesbraza commented 2 months ago

Okay, I have figured it out thanks to @charliermarsh's comment:

Not sure what's going on but it does look like you're being prompted.

The fix was specifying --yes to rye publish, to not have Rye prompt the user:

---      - run: rye publish --token ${{ secrets.PYPI_API_TOKEN }}
+++      - run: rye publish --token ${{ secrets.PYPI_API_TOKEN }} --yes

So to follow up, there was nothing wrong with setup-rye (cc @eifinger).

Now for a fix here, is there some way we can make this failure "nicer" towards humans? E.g. is there some way Rye can check if an input terminal is available before prompting then crashing with the current obscure error?

charliermarsh commented 2 months ago

Yeah can definitely be improved... Do you have any idea what the prompt was?

jamesbraza commented 2 months ago

Yeah the prompt was asking for a password encryption:

? Encrypt with passphrase (optional) ›

I guess it's worth pointing out that we aren't using a password, so maybe this prompt can be eliminated entirely

charliermarsh commented 2 months ago

I think it's still relevant because Rye is trying to encrypt whatever plaintext secret (password or token) you provide on disk. But we should either skip that step when you're not attached to a TTY or provide a better error message with a mention of --yes.

jamesbraza commented 2 months ago

I follow and that sounds great. Maybe also adjust the prompt from "Encrypt with passphrase" to say what being encrypted, so perhaps "Encrypt token with passphrase" to be more explicit