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

tools,win: fix find_python error #22797

Merged
merged 0 commits into from
Sep 18, 2018
Merged

tools,win: fix find_python error #22797

merged 0 commits into from
Sep 18, 2018

Conversation

kfarnung
Copy link
Contributor

On a machine without python.exe in the PATH the script was failing
with:

> .\vcbuild.bat
Looking for Python 2.x
2> was unexpected at this time.

Escaping the > seems to resolve it.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@kfarnung kfarnung self-assigned this Sep 10, 2018
@nodejs-github-bot nodejs-github-bot added install Issues and PRs related to the installers. tools Issues and PRs related to the tools directory. windows Issues and PRs related to the Windows platform. labels Sep 10, 2018
@richardlau
Copy link
Member

cc @nodejs/platform-windows

@refack
Copy link
Contributor

refack commented Sep 11, 2018

I did some local testing and found that b6e991d is required as well.

@kfarnung
Copy link
Contributor Author

Oh, interesting, what was the symptom there? I only have Python 2.7 installed on this machine (but not in the PATH), so it's possible that I didn't run into that issue.

@refack
Copy link
Contributor

refack commented Sep 11, 2018

Oh, interesting, what was the symptom there? I only have Python 2.7 installed on this machine (but not in the PATH), so it's possible that I didn't run into that issue.

I had both 3.7 & 2.7 (and none in the Path), and I found that the path is not propagated

FOR /F "tokens=3*" %b IN ('REG QUERY HKEY_CURRENT_USER\Software\Python\PythonCore\2.7\InstallPath /ve') DO (
SET pt=%b
 IF NOT ERRORLEVEL 1 SET p=
 EXIT /B 0
)

in the full

D:\code\node>call tools\msvs\find_python.cmd

echo Looking for Python 2.x
Looking for Python 2.x

SETLOCAL

FOR /F "delims=" %a IN ('where python 2> NUL') DO (
SET need_path=0
 SET p=%~dpa
 IF NOT ERRORLEVEL 1 GOTO :validate
)

FOR %K IN ("HKCU\Software" "HKLM\SOFTWARE" "HKLM\Software\Wow6432Node") DO (
SET need_path=1
 CALL :find-main-branch %K
 IF NOT ERRORLEVEL 1 GOTO :validate
)

(
SET need_path=1
 CALL :find-main-branch "HKCU\Software"
 IF NOT ERRORLEVEL 1 GOTO :validate
)

SET main_key="HKCU\Software\Python\PythonCore"

REG QUERY "HKCU\Software\Python\PythonCore" /s   2>NUL  | findstr "2."   | findstr InstallPath  1>NUL 2>NUL

IF NOT ERRORLEVEL 1 CALL :find-key "HKCU\Software\Python\PythonCore"

FOR /F "delims=" %a IN ('REG QUERY "HKCU\Software\Python\PythonCore" /s 2> NUL | findstr "2." | findstr InstallPath') DO IF NOT ERRORLEVEL 1 CALL :find-path %a

IF NOT ERRORLEVEL 1 CALL :find-path HKEY_CURRENT_USER\Software\Python\PythonCore\2.7\InstallPath

FOR /F "tokens=3*" %b IN ('REG QUERY HKEY_CURRENT_USER\Software\Python\PythonCore\2.7\InstallPath /ve') DO (
SET pt=%b
 IF NOT ERRORLEVEL 1 SET p=
 EXIT /B 0
)

(
SET pt=D:\bin\dev\python27\
 IF NOT ERRORLEVEL 1 SET p=
 EXIT /B 0
)

EXIT /B

EXIT /B

IF NOT EXIST "python.exe" goto :no-python

echo Could not find Python.
Could not find Python.

exit /B 1

P.S. Let me test it a little bit more...

@kfarnung
Copy link
Contributor Author

I appreciate the help testing this out, I suspect this code doesn't get too much exercise.

@addaleax
Copy link
Member

@kfarnung @refack What’s the status? Is this good to go?

@kfarnung
Copy link
Contributor Author

I think my fix is good either way, AFAICT the script is completely broken without the fix (if you don't have python.exe in your path).

@refack, did you get a chance to determine whether your fix was necessary? Any issues you've come across.

I'm inclined to land this today as long as the CI looks good and there are no objections. We can tweak this further if people hit other issues.

@kfarnung
Copy link
Contributor Author

Rebased and merged @refack's commits together. Will kick off a CI if Jenkins responds.

@kfarnung
Copy link
Contributor Author

@refack, trying it out again today, it seems like your change causes my machine to not find Python at all.

@kfarnung
Copy link
Contributor Author

@kfarnung
Copy link
Contributor Author

@nodejs/platform-windows @refack any issues with this change? I'd like to get another sign-off and check this in today if there are no objections. We can circle back on @refack's issue in a future PR.

@refack
Copy link
Contributor

refack commented Sep 17, 2018

We can circle back on @refack's issue in a future PR.

Ok.

@refack
Copy link
Contributor

refack commented Sep 17, 2018

@kfarnung does the > .\vcbuild.bat hint that you are running this from PowerShell?
For me to test this further, could you also paste your set before running, so I can reproduce. Also might help a run of vcbuild with set DEFINED DEBUG_HELPER=1, and reg QUERY HKEY_CURRENT_USER\Software\Python /S

@kfarnung
Copy link
Contributor Author

I do use PowerShell most of the time, but both CMD and PowerShell exhibit the same behavior (that's fixed by my change). I have Python 2.7 installed in C:\Python27 and Python 3.7 installed to my user folder. I ran the reg queries for HKCU and HKLM: reg_python.txt.

Here's the output of before (vcbuild_before.txt) and after (vcbuild_fixed.txt) my fix.

@kfarnung
Copy link
Contributor Author

kfarnung commented Sep 17, 2018

@refack
Copy link
Contributor

refack commented Sep 17, 2018

I ran the reg queries for HKCU and HKLM: reg_python.txt.

That was wise, I see the edge case, you have 3.7 only in HKCU and 2.7 only in HKLM...
I think the search loops cascade, and not nest. It's a good test case.

@kfarnung
Copy link
Contributor Author

I suspected that might be the case. Given that I have a clean CI now, would you be ok with my landing this PR?

@refack
Copy link
Contributor

refack commented Sep 17, 2018

I suspected that might be the case. Given that I have a clean CI now, would you be ok with my landing this PR?

Sure, if it fixes your system, it's definatly an improvement.

@kfarnung kfarnung changed the title tools,windows: fix find_python error tools,win: fix find_python error Sep 17, 2018
@kfarnung
Copy link
Contributor Author

Thanks! Just for reference, how do you have Python installed? Are they both under HKCU?

@refack
Copy link
Contributor

refack commented Sep 18, 2018

Just for reference, how do you have Python installed? Are they both under HKCU?

Yes, but I hand roll my setup. I use
Python.reg.txt
And xcopy the files (sometimes I need to use https://github.com/Bioruebe/UniExtract2)

P.S.
I usually remove those entries when I do test, but I'm going to mock out reg.exe for a test harness.

@kfarnung
Copy link
Contributor Author

Landed in 988be43

@kfarnung kfarnung deleted the python branch September 18, 2018 00:25
targos pushed a commit that referenced this pull request Sep 18, 2018
On a machine without `python.exe` in the PATH the script was failing
with:

```console
> .\vcbuild.bat
Looking for Python 2.x
2> was unexpected at this time.
```

Escaping the `>` seems to resolve it.

PR-URL: #22797
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
targos pushed a commit that referenced this pull request Sep 19, 2018
On a machine without `python.exe` in the PATH the script was failing
with:

```console
> .\vcbuild.bat
Looking for Python 2.x
2> was unexpected at this time.
```

Escaping the `>` seems to resolve it.

PR-URL: #22797
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
targos pushed a commit that referenced this pull request Sep 20, 2018
On a machine without `python.exe` in the PATH the script was failing
with:

```console
> .\vcbuild.bat
Looking for Python 2.x
2> was unexpected at this time.
```

Escaping the `>` seems to resolve it.

PR-URL: #22797
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
install Issues and PRs related to the installers. tools Issues and PRs related to the tools directory. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants