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

fix(install): improve powershell script (Issue #372) #409

Merged
merged 9 commits into from
Jul 25, 2023

Conversation

KrishPatel13
Copy link
Collaborator

@KrishPatel13 KrishPatel13 commented Jul 19, 2023

What kind of change does this PR introduce?
This PR resolves the bugs numbered here #372 (comment)

Summary
Bug Number fixed:

Checklist

  • My code follows the style guidelines of OpenAdapt
  • I have performed a self-review of my code
  • If applicable, I have added tests to prove my fix is functional/effective
  • I have linted my code locally prior to submission
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (e.g. README.md, requirements.txt)
  • New and existing unit tests pass locally with my changes

How can your code be run and tested?

Other information

Krish Patel added 3 commits July 19, 2023 14:51
Remove-Item : Cannot remove the item at 'C:\Users\Krish Patel\hi' because it is in
use.
At line:1 char:9
+         Remove-Item -LiteralPath $setupdir -Force -Recurse
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Remove-Item], PSInvalidOperation
   Exception
    + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RemoveIt
   emCommand
"..runnning scripts is disabled on the command line"
@KrishPatel13 KrishPatel13 self-assigned this Jul 19, 2023
 to support multiple version of python (acc. to OpenAdapt standards)
@KrishPatel13
Copy link
Collaborator Author

KrishPatel13 commented Jul 19, 2023

Bug 4 (from #372 (comment))
image

Resolution Transcript (f39c583):

PS C:\Users\Krish Patel> python -V
Python 3.10.11
PS C:\Users\Krish Patel> $pythonMinVersion = "3.10.0" # Change this if a different Lower version are supported by OpenAdapt
PS C:\Users\Krish Patel> $pythonMaxVersion = "3.10.12" # Change this if a different HIgher version are supported by OpenAdapt
PS C:\Users\Krish Patel> function ComparePythonVersion($version) {
>>     $v = [version]::new($version)
>>     $min = [version]::new($pythonMinVersion)
>>     $max = [version]::new($pythonMaxVersion)
>>
>>     return $v -ge $min -and $v -le $max
>> }
PS C:\Users\Krish Patel> $res = Invoke-Expression "python -V"
PS C:\Users\Krish Patel>         $versionString = $res.Split(' ')[-1]
PS C:\Users\Krish Patel> $res
Python 3.10.11
PS C:\Users\Krish Patel> $versionString
3.10.11
PS C:\Users\Krish Patel> if (ComparePythonVersion $versionString  $pythonMaxVersion) {
>>             return $true
>>         }
True
PS C:\Users\Krish Patel> if (ComparePythonVersion $versionString  $pythonMaxVersion) {
>>             return "correct version found"
>>         }
correct version found
PS C:\Users\Krish Patel> $versionString = "3.11.0"
PS C:\Users\Krish Patel> if (ComparePythonVersion $versionString  $pythonMaxVersion) {
>>             return "correct version found"
>>         }
PS C:\Users\Krish Patel> if (ComparePythonVersion $versionString  $pythonMaxVersion) {
>>             return "correct version found"
>>         } else {
>> return "incorrect version found"
>> }
incorrect version found
PS C:\Users\Krish Patel> $versionString = "3.9.99"
PS C:\Users\Krish Patel> if (ComparePythonVersion $versionString  $pythonMaxVersion) {
>>             return "correct version found"
>>         } else {
>> return "incorrect version found"
>> }
incorrect version found
PS C:\Users\Krish Patel> $versionString = "3.10.0001"
PS C:\Users\Krish Patel> if (ComparePythonVersion $versionString  $pythonMaxVersion) {
>>             return "correct version found"
>>         } else {
>> return "incorrect version found"
>> }
correct version found
PS C:\Users\Krish Patel> $versionString = "3.10.12"
PS C:\Users\Krish Patel> if (ComparePythonVersion $versionString  $pythonMaxVersion) {
>>             return "correct version found"
>>         } else {
>> return "incorrect version found"
>> }
correct version found

@KrishPatel13
Copy link
Collaborator Author

KrishPatel13 commented Jul 19, 2023

Bug 1 and 2 (from #372 (comment)):
image

Resolution Commit: ed7f3e0

Resolution Transcript:
Issue 1&2 Resolution Documentation:

Some Improvement in CheckCMDExists function:

Old Function Terminal Transcript:

PS C:\Users\Krish Patel> function CheckCMDExists {
>>     Param
>>     (
>>         [Parameter(Mandatory = $true)] [string] $command
>>     )
>>
>>     Get-Command $command -errorvariable getErr -erroraction 'silentlycontinue'
>>     if ($null -eq $getErr) {
>>         return $true
>>     }
>>     return $false
>> }
PS C:\Users\Krish Patel> CheckCMDExists "got"
False
PS C:\Users\Krish Patel> CheckCMDExists "git"

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     git.exe                                            2.41.0.1   C:\Program Files\Git\cmd\git.exe
False


PS C:\Users\Krish Patel> CheckCMDExists "tesseract"

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     tesseract.exe                                      0.0.0.0    C:\Program Files\Tesseract-OCR\tessera...
False


PS C:\Users\Krish Patel> CheckCMDExists "python"

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     python.exe                                         3.10.11... C:\Program Files\Python310\python.exe
False


Updated Function Code for Terminal Transcript:

PS C:\Users\Krish Patel> function CheckCMDExists {
>>     Param
>>     (
>>         [Parameter(Mandatory = $true)] [string] $command
>>     )
>>
>>     $result = Get-Command $command -errorvariable getErr -erroraction 'silentlycontinue'
>>     if ($null -eq $result) {
>>         return $false
>>     }
>>     return $true
>> }
PS C:\Users\Krish Patel> CheckCMDExists "got"
False
PS C:\Users\Krish Patel> CheckCMDExists "git"
True
PS C:\Users\Krish Patel> CheckCMDExists "tesseract"
True
PS C:\Users\Krish Patel> CheckCMDExists "python"
True
PS C:\Users\Krish Patel> CheckCMDExists "python 3.10"
False
PS C:\Users\Krish Patel> CheckCMDExists "py"
True
PS C:\Users\Krish Patel> CheckCMDExists "tess"
False

Updated code for the function:

function CheckCMDExists {
    Param
    (
        [Parameter(Mandatory = $true)] [string] $command
    )

    $result = Get-Command $command -errorvariable getErr -erroraction 'silentlycontinue'
    if ($null -eq $result) {
        return $false
    }
    return $true
}

Conclusion: The previous old function was incorrect and did not work as expected on Unit Testing as shown in the transcripts.

@KrishPatel13
Copy link
Collaborator Author

Bug 5 and 6 (from #372 (comment)):
image
image

Resolution Commit: cf0d21d

Resolution Documentation:
microsoft/vscode-python#2559 (comment)

@KrishPatel13 KrishPatel13 linked an issue Jul 19, 2023 that may be closed by this pull request
 why sometimes the installtion command exits
@KrishPatel13
Copy link
Collaborator Author

KrishPatel13 commented Jul 19, 2023

Bug 3:
image

Update:

Commit: 56cf2c1

 is not set to the OpenAdapt folder that was installed
@KrishPatel13
Copy link
Collaborator Author

@abrichr Ready for review!

@KrishPatel13
Copy link
Collaborator Author

@abrichr Ready for Final Review and merging! :)

@abrichr abrichr merged commit fb3ae1e into OpenAdaptAI:main Jul 25, 2023
R-ohit-B-isht pushed a commit to R-ohit-B-isht/OpenAdapt that referenced this pull request Jun 21, 2024
…AdaptAI#409)

* fix: git reinstallation even if it si present

* fix: Error Message:

Remove-Item : Cannot remove the item at 'C:\Users\Krish Patel\hi' because it is in
use.
At line:1 char:9
+         Remove-Item -LiteralPath $setupdir -Force -Recurse
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Remove-Item], PSInvalidOperation
   Exception
    + FullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RemoveIt
   emCommand

* fix: issue that poetry shell gives
"..runnning scripts is disabled on the command line"

* fix: bug #4 issue
 to support multiple version of python (acc. to OpenAdapt standards)

* add start mesage to know
 why sometimes the installtion command exits

* fix the edge case where the new terminal PWD
 is not set to the OpenAdapt folder that was installed

* Update install/install_openadapt.ps1

---------

Co-authored-by: Richard Abrich <richard.abrich@gmail.com>
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.

[Bug]: windows install script is brittle
2 participants