python-eel / Eel

A little Python library for making simple Electron-like HTML/JS GUI apps
MIT License
6.44k stars 587 forks source link

React AssertionError When running out of build directory #316

Closed rpm886 closed 4 years ago

rpm886 commented 4 years ago

When testing out your example React App Create-React-App . Everything works as expected when running in develop mode out of the "src" directory. However, when running out of the "build" directory I get this error:

Traceback (most recent call last): File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1438, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "/Users/rpm886/Documents/ZoomRoomsProjects/zoom_test/eel_CRA.py", line 120, in start_eel(develop=len(sys.argv) == 2) File "/Users/rpm886/Documents/ZoomRoomsProjects/zoom_test/eel_CRA.py", line 79, in start_eel eel.init(directory,['.tsx', '.ts', '.jsx', '.js', '.html']) File #"/Users/rpm886/Documents/ZoomRoomsProjects/zoom_test/venv/lib/python2.7/site-packages/eel/init.py", line 106, in init assert rgx.findall(r'[(=]', expose_call) == [], msg

AssertionError

: eel.expose() call contains '(' or '=' Python side:

global some_free_port
some_free_port
"""Start Eel with either production or development configuration."""
if develop:
    directory = 'src'
    app =  'chrome-app'
    page = {'port': 3000}
else:
    directory = 'build'
    app = 'chrome-app'
    page = 'index.html'

eel_kwargs = dict(
    host='localhost',
    port=8081,
    size=(1280, 800),
)
logger.debug("Initializing Eel with dir  %s  ", directory)
eel.init(directory,['.tsx', '.ts', '.jsx', '.js', '.html'])

# These will be queued until the first connection is made, but won't be repeated on a page reload
say_hello_py('Python World!')
eel.say_hello_js('Python World!')   # Call a JavaScript function (must be after `eel.init()`)

try:
    eel.start(page, mode=app, **eel_kwargs)
    # eel.start(page, port=8081, size=(1400, 720),  block=True)
except Exception as e:
    logger.error("Exception Happened : %s", str(e))
    pass

Java Script side:

// Point Eel web socket to the instance export const eel = window.eel eel.set_host( 'ws://localhost:8081')

// Expose the sayHelloJS function to Python as say_hello_js function sayHelloJS( x ) { console.log( 'Hello from ' + x ) } // WARN: must use window.eel to keep parse-able eel.expose{...} window.eel.expose( sayHelloJS, 'say_hello_js' )

// Test calling sayHelloJS, then call the corresponding Python function sayHelloJS( 'Javascript World!' ) eel.say_hello_py( 'Javascript World!' )

@KyleKing , any suggestions?

KyleKing commented 4 years ago

@rpm886 I'll take a look when I get back from work. This issue can be assigned to me

KyleKing commented 4 years ago

@rpm886, I wasn't able to recreate the error message you reported

Can you check that you also updated the port to 8081 in public/index.html to load the eel.js file? See the note for public/index.html in the 07 Example README

If that wasn't the issue, can you create a fork with the changes you've made to the example? This is the local version that I am working with: https://github.com/KyleKing/Eel/commit/c615c0b40196103f5c2974c317f885addffe762c

Additionally, what platform are you using (Linux, Mac, version, etc.) Can you run pip freeze?

rpm886 commented 4 years ago

Thanks for the response. Yes the port in public/index.html is correct: <script type="text/javascript" src="http://localhost:8081/eel.js"></script> When running in develop mode in uses this file and works fine. It's just when it uses the build directory that it fails. And I read the note 07 Example README many times.

I'm running on a Mac.

pip freeze:

backports.functools-lru-cache==1.6.1
blessed==1.17.6
bottle==0.12.18
bottle-websocket==0.2.9
coloredlogs==14.0
dis3==0.1.3
Eel==0.12.4
future==0.18.2
gevent==20.6.1
gevent-websocket==0.10.1
greenlet==0.4.16
humanfriendly==8.2
inquirer==2.7.0
macholib==1.14
monotonic==1.5
msgpack==1.0.0
PyInstaller==3.6
python-editor==1.0.4
readchar==2.0.1
six==1.15.0
wcwidth==0.2.4
whichcraft==0.6.1
zope.event==4.4
zope.interface==5.1.0

I don't think this matters but I'm running off a PyCharm IDE with a local env setup.

I made I ton of changes since this post so I'll get the older version and post it.

Thanks for your help. I really like this eel library. This is the first time I'm using it with react.

rpm886 commented 4 years ago

So... when I rebuilt the project from scratch the problem went away. I'm not sure what the issue was, I deleted the old build folder from the file system manually. It might have been some stale data in the build folder ... IDK. But when it works don't fix it....

You can close this issue obviously.

Thank you for the help.