feenkcom / gtoolkit

Glamorous Toolkit is the Moldable Development environment. It empowers you to make systems explainable through experiences tailored for each problem.
https://gtoolkit.com
MIT License
1.11k stars 48 forks source link

Pipenv Install Timeout Error #2863

Open seandenigris opened 1 year ago

seandenigris commented 1 year ago

v 0.8.2105.

Screen Shot 2022-11-01 at 10 04 48 AM

When trying to run a Python snippet for the first time, I'm getting an obscure error. IIUC PBApplication>>#waitInitialization is timing out before pipenv is finished setting up, probably because I now have about a dozen additional packages in my Pipfile and it appears the timeout is hardcoded.

Possible Solutions

Workaround

On the command line, ./PythonBridgeRuntime/install_env.sh before using Python in the image.

svenvc commented 8 months ago

We now have https://github.com/feenkcom/gtoolkit/issues/3604

In practice, yes initial pipenv based install takes a couple of noticeable seconds, but for me it works within the existing timeout limits.

Of course, a better indication of what is happening would always be welcome, but we are talking about an external subprocess here, I am not sure this is easy to solve.

svenvc commented 8 months ago

Closing for now, feel free to reopen if you think this is necessary.

seandenigris commented 7 months ago

I will see if #3604 helps here. In regards to whether the timeout is long enough, it is contextual because it all depends on how many packages the user is loading. For me, this pipfile for example has routinely exceeded the timeout and caused problems:

[[source]]
'name' = 'pypi'
'url' = 'https://pypi.org/simple'
'verify_ssl' = true

[dev-packages]

[packages]
pandas = '*'
ofxtools = '*'
phonenumbers = '*'
python-docx = '*'
titlecase = '*'
geopy = '*'
msgpack = '*'
msal = '*'
requests = '*'
html2text = '*'
playwright = '*'
mpv-silence = '*'
fuzzywuzzy = '*'
speedtest-cli = '*'
nextstep-plist = '*'
flask = '*'

[requires]
python_version = '3.10'
svenvc commented 7 months ago

In the new approach (PBNewPharoPipenvProcess) we use our own PyPI package (gtoolkit_bridge). Installation from scratch involves 3 steps:

2024-02-17T13:48:57.818872+01:00 pipenv install 777ms
2024-02-17T13:48:59.627451+01:00 pipenv install gtoolkit_bridge 1808ms
2024-02-17T13:49:01.48127+01:00 pipenv install debugpy 1854ms

Installation happens into a pipenv virtual environment inside an otherwise empty PythonBridgeRuntime directory.

If you need more modules, I see two approaches:

1.

Manually outside GT:

2.

Programmatically from GT:

#(pandas ofxtools ... speedtest-cli nextstep-plist) do: [ :each | 
    PBApplication uniqueInstance installModule: each ]
svenvc commented 7 months ago

Here is a quick & dirty script to parse a requirements.txt file into module names (skipping versions).

'/tmp/requirements.txt' asFileReference contents lines 
  reject: [ :line | line isEmptyOrNil or: [ ('#-./' includes: line first) or: [ line beginsWith: #http ] ] ]
  thenCollect: [ :line | (line findTokens: Character separators, '=') first ]

And a similar one to parse a Pipfile into module names (ignoring versions).

lines := '/tmp/Pipfile' asFileReference contents lines readStream.
[ lines next = '[packages]' ] whileFalse.
packages := OrderedCollection new.
[ (line := lines next) isEmptyOrNil ] whileFalse: [ packages add: (line findTokens: '=') first ].
packages

This is all in the assumption that you want to stay in GT.

seandenigris commented 7 months ago

I have been hacking the PB load behavior to round up all the Pipfiles in loaded repos (under pharo-local) along with GT's default Pipfile and merge them into one big Pipfile. It relies on a basic Pipfile parser that covered the syntax I needed for my projects. The hook is here:

Screenshot 2024-03-10 at 12 51 00 PM