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

Revised activate script fails on alpine:edge #10498

Open
charliermarsh opened this issue Jan 11, 2025 · 4 comments
Open

Revised activate script fails on alpine:edge #10498

charliermarsh opened this issue Jan 11, 2025 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@charliermarsh
Copy link
Member

This change caused our CI to fail using alpine:edge image

web-1  | /srv/scripts/run.sh: /srv/.venv/bin/activate: line 81: OSTYPE: parameter not set

Originally posted by @andypost in #10397 (comment)

@charliermarsh charliermarsh changed the title This change caused our CI to fail using alpine:edge image Revised activate script fails on alpine:edge Jan 11, 2025
@charliermarsh charliermarsh added the bug Something isn't working label Jan 11, 2025
@zanieb
Copy link
Member

zanieb commented Jan 11, 2025

I can't reproduce this

FROM alpine:edge

RUN apk add --update --no-cache python3

COPY --from=ghcr.io/astral-sh/uv:0.5.17 /uv /uvx /bin/
RUN uv venv /venv
RUN . /venv/bin/activate

@zanieb
Copy link
Member

zanieb commented Jan 11, 2025

@andypost am I using a different image or shell than you?

@andypost
Copy link

andypost commented Jan 11, 2025

@zanieb the way to reproduce is set -eux before activation

FROM alpine:edge

RUN apk add --update --no-cache python3

COPY --from=ghcr.io/astral-sh/uv:0.5.17 /uv /uvx /bin/
RUN uv venv /venv
RUN set -eux && . /venv/bin/activate

the log

0.710 + . /venv/bin/activate                                                                                                                                                                                                                                 
0.712 + '[' -n  ]
0.712 + '[' -n  ]
0.712 + '[' -n  ]
0.713 + deactivate nondestructive
0.714 + unset -f pydoc
0.714 + '[' -n  ]
0.714 + '[' -n  ]
0.714 + hash -r
0.714 + '[' -n  ]
0.714 + unset VIRTUAL_ENV
0.714 + unset VIRTUAL_ENV_PROMPT
0.714 + '[' '!' nondestructive '=' nondestructive ]
0.715 + VIRTUAL_ENV=/venv
0.715 /bin/sh: /venv/bin/activate: line 81: OSTYPE: parameter not set

@zanieb
Copy link
Member

zanieb commented Jan 11, 2025

Thanks! Looks like this can be resolved with

RUN sed -i 's/if { \[ "$OSTYPE" = "cygwin" \] || \[ "$OSTYPE" = "msys" \]; }/if { [ "${OSTYPE-}" = "cygwin" ] || [ "${OSTYPE-}" = "msys" ]; }/' /venv/bin/activate

or

❯ gd
diff --git a/crates/uv-virtualenv/src/activator/activate b/crates/uv-virtualenv/src/activator/activate
index 3678ee23b..f87ca81dd 100644
--- a/crates/uv-virtualenv/src/activator/activate
+++ b/crates/uv-virtualenv/src/activator/activate
@@ -78,7 +78,7 @@ deactivate () {
 deactivate nondestructive
 
 VIRTUAL_ENV='{{ VIRTUAL_ENV_DIR }}'
-if { [ "$OSTYPE" = "cygwin" ] || [ "$OSTYPE" = "msys" ]; } && command -v cygpath > /dev/null 2>&1 ; then
+if { [ "${OSTYPE-}" = "cygwin" ] || [ "${OSTYPE-}" = "msys" ]; } && command -v cygpath > /dev/null 2>&1; then
     VIRTUAL_ENV=$(cygpath -u "$VIRTUAL_ENV")
 fi
 export VIRTUAL_ENV

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

4 participants