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

pyenv-win compatibility #16265

Closed
wants to merge 1 commit into from
Closed

pyenv-win compatibility #16265

wants to merge 1 commit into from

Conversation

w-e-w
Copy link
Collaborator

@w-e-w w-e-w commented Jul 26, 2024

webui.bat does not work for users using pyenv-win
the is because when using pyenv-win the python actually points to a bat script and so it needs to be call to function

credit to
@stevenengland for bringing this to attention and providing a possible solution

@viking1304 for providing the reason of the issue

important I'm not sure if this fix should be applied

@viking1304 also provides an alternative (user side) fix by adding

set PYTHON=call python

this means that it is totally possible that other users of pyenvv are doing similar thing to get it working

if this PR is merged, it will allow NEW user of webui using pyenv-win to work but may break it for existing users


maybe there's a way of making work for both, something like

pseudo code

where %PYTHON%
if the first line of result of where %PYTHON% points to a bat then add `call` to the command
if not found (when the value is `call python`) or endes with .exe then do nothing

Checklist:

%PYTHON% -> call %PYTHON%

Co-Authored-By: viking1304 <28989870+viking1304@users.noreply.github.com>
Co-Authored-By: Steven England <github@steven-england.info>
@viking1304
Copy link
Contributor

viking1304 commented Jul 27, 2024

I haven't used Windows scripting for a few years, but let's try to jog my memory and do something useful.

Since Windows does not have the file command, the best implementation of your pseudo code I can think of would be this:

for /f "delims=" %%A in ('where python ^| findstr /n . ^| findstr ^^1:') do (
  if /i "%%~xA" == ".exe" (
    set python_is_exe=true
  ) else (
    set python_is_exe=false
  )
)

findstr /n . will convert this

C:\Users\Aleksandar\.pyenv\pyenv-win\shims\python
C:\Users\Aleksandar\.pyenv\pyenv-win\shims\python.bat
C:\Users\Aleksandar\AppData\Local\Microsoft\WindowsApps\python.exe

into

1:C:\Users\Aleksandar\.pyenv\pyenv-win\shims\python
2:C:\Users\Aleksandar\.pyenv\pyenv-win\shims\python.bat
3:C:\Users\Aleksandar\AppData\Local\Microsoft\WindowsApps\python.exe

findstr ^^1: will get the first line from there

1:C:\Users\Aleksandar\.pyenv\pyenv-win\shims\python

%%~xA will get the extension

so it will be an empty string in this example, but if the last one were first, it would be .exe

I tested if this works correctly by changing 1: to 3: and restoring it to 1: again.

If anyone has a better suggestion than this, please share your idea.

With that code as a base, we can probably do something like this:

Instead of

if not defined PYTHON (set PYTHON=python)

we can just use

if not defined PYTHON (
  for /f "delims=" %%A in ('where python ^| findstr /n . ^| findstr ^^1:') do (
    if /i "%%~xA" == ".exe" (
      set PYTHON=python
    ) else (
      set PYTHON=call python
    )
  )
)

EDIT: I forgot to mention that this eliminates the need for other changes and that the remaining code can stay as it is. There is no need to use calls all over the script this way.

@catboxanon catboxanon closed this Oct 29, 2024
@catboxanon catboxanon deleted the pyenv-win-compatibility branch October 29, 2024 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants