pygame-web / pygbag

python and pygame wasm for everyone ( packager + test server + simulator )
https://github.com/pygame-web
MIT License
335 stars 39 forks source link

How to add a (stdlib) module? #85

Closed raventan95 closed 1 year ago

raventan95 commented 1 year ago

Python 3.10 Pygbag 0.7.1

Trying to run pygbag on a pygame, in debug windows see stdlib module optparse not found. I did not use the module anywhere in my code, not sure why pygbag needs it??? I don't know how to disable importing this module

So, I try copy these 3 files from stdlib installation path to the folder containing main.py. image

It work! but another module not found, this time is regex. Again, I did not use this module anywhere in my code, so not sure why pygbag needs it.

I try to do the same thing, by copying these files to main.py, but it did not work this time :( image

I understand I can request the package to be included in #63 , but this is stdlib, surely others will face the same problem?

This is the debug terminal logs

sys._emscripten_info(emscripten_version=(3, 1, 33), runtime='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36', pthreads=False, shared_memory=False)
pygame-ce 2.1.4.dev1 (SDL 2.24.2, Python 3.11.2)
284: assets found : 0
341: EventTarget delayed by loader
622: possibly synchronous code found
1020: import scan filename='<stdin>' len(code)=391 ['nltk', 'numpy', 'game', 'settings']
1044: requesting module want='nltk' for file='<stdin>' 
1055: module want='nltk' requested
1044: requesting module want='numpy' for file='<stdin>' 
1055: module want='numpy' requested
1044: requesting module want='game' for file='<stdin>' 
1063: repo['-CDN-']='http://localhost:8000/archives/repo/' does not provide want='game'
1044: requesting module want='settings' for file='<stdin>' 
1063: repo['-CDN-']='http://localhost:8000/archives/repo/' does not provide want='settings'
1202: want='numpy' found : True
pkg : http://localhost:8000/archives/repo/pkg/numpy-1.22.4-cp311-cp311-wasm32_mvp_emscripten.whl
 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| 100.0% 
1202: want='sqlite3' found : False
PKG NOT FOUND : want='sqlite3', resume=None, ex=None
1202: want='regex' found : False
PKG NOT FOUND : want='regex', resume=None, ex=None
1291: {req=} in {cls.ignore=} or sys.modules
1202: want='nltk' found : True
pkg : http://localhost:8000/archives/repo/pkg/nltk-3.7-py3-none-any.whl
 |XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| 100.0% 
646: starting shell
996: 20 lines queued for async eval
going interactive
643: TODO detect input/print to select repl debug
181: FIXME dependency table for manually built modules
1202: want='regex._regex_core' found : False
PKG NOT FOUND : want='regex._regex_core', resume=<function <module> at 0xfee300>, ex=ModuleNotFoundError("No module named 'regex._regex_core'; 'regex' is not a package")

Also, I have 2 local imports which my main program will import scripts from, the directory tree looks like

groword
 |-- game.py
 |-- settings.py
 |-- main.py

Will this also cause problem because I see repo['-CDN-']='http://localhost:8000/archives/repo/' does not provide want='game'

pmp-p commented 1 year ago

you can add modules directly in the game folder, all extra modules that may be imported by submodules must be imported first in main.py

nltk requires regex module which is not provided yet. You should make a request for it in https://github.com/pygame-web/pkg-porting-wasm

raventan95 commented 1 year ago

Thanks @pmp-p

May I know why nltk module is already provided in pkg-porting-wasm, but not regex? How can one use nltk if the module will always import regex? So, strictly speaking, nltk is also not supported yet?

Also, is socket module supported? I want to make pygame on pygbag run as a multiplayer game

pmp-p commented 1 year ago

regex ( wheel from pyodide 3.11 python-wasm-sdk build ) is now staging, but i see that nltk also require xml.sax which is not in the minimal stdlib runtime so you will need to copy it from a full 3.11 stdlib

client sockets are supported, that means server must use websocket protocol or lives behind a tool like websockify

pmp-p commented 1 year ago

most of stdlib should not be required to make games, extra modules - if not games engines - are outside pygbag scope for now.