manatlan / guy

Graphics User Ynterface : a simple module for making GUI applications (with html/js) for py3 ... to target windows, linux, mac & android
Apache License 2.0
202 stars 23 forks source link

Can't find 'static' directory #3

Closed bendub closed 4 years ago

bendub commented 4 years ago

Hello manatlan, I package an app using setuptools. The app is installed in the user environment:

$ python3 -m pip install --user mypkg.tar.gz

My main script located in ~/.local/bin and the package itself is located in ~/.local/lib/python3.X/site-packages/MyPkg/. When I execute my script, my browser returns a page containing:

ERROR: can't find /home/USER/.local/bin/static/APP.html

The directory 'static' is actually located in ~/.local/lib/python3.X/site-packages/MyPkg/ui/static.

Thank you

manatlan commented 4 years ago

it's the same bug as #2 ;-)

bendub commented 4 years ago

Two bugs resolved in one action \o/

manatlan commented 4 years ago

In fact ... it's a lot more complex ... I've made the "os.chdir()" (when server starts) to be sure to place the CWD where the 'exe' (freezed one) sits. (to be able to locate static & config.json). It works very well ... on "windows" with freezed one (because static files are embedded in the freezed exe) or simple py-files ... But it's not really adapted for people who wants to release pypi packages ...

How do you embed your files (setuptools with "package_data" ? or data_files)

For packaged one, I will need to deal with pkg_ressource ... or let the user/packager a way to setup the desired path

bendub commented 4 years ago

Hello Manatlan, I embed my files in a package using setuptools with "package_data":

package_data={
          '': ['ui/static/*.html',
               'ui/static/*.png']
      }
manatlan commented 4 years ago

thks ...

and, to build your package : you did :

 python3.7 setup.py sdist

?

bendub commented 4 years ago

Yes, to be precise:

python3 setup.py sdist bdist_wheel

manatlan commented 4 years ago

I don't reach to include static files in my sdist tar.gz ;-(

bendub commented 4 years ago

Could you use my tar.gz?

manatlan commented 4 years ago

Can't reach to embbed static files ... perhaps you will see my trouble ?! test_app.zip

manatlan commented 4 years ago

please, can you try that (replace your guy.py with this one guy.txt )... do you have got better result ? (sorry, can't test here .. because can't reproduce)

manatlan commented 4 years ago

Could you use my tar.gz?

yes .. I could

manatlan commented 4 years ago

First ... forgot all I said before ^^ ;-)

I've reach to embbed data in a package (bdist_wheel) ... using the marvelous "poetry" ;-) And reach to reproduce exactly your problem !

Try this future version of guy guy.txt (don't wanna to release yet ... because I should test on windows, with frozen exe (to be sure that there are no regression) ... I could test/release on monday evening) (and currently : no regression on android/apk !)

Now ... guy doesn't change/enforce "current directory" (it's a lot better like that !) ... and it can see if it's executed from a python package ... and rewrite the good path to the data ! So now : you can build pypi package ;-)

In your case : perhaps you should change your static folder ... because it seems that you have prefixed it with "ui" (set guy.FOLDERSTATIC = "ui/static") ...

BTW, it works, like a charm, for me ... using poetry to build my wheel ... in your case, with pure setuptools ... it should work too ... but not sure at 100%

BTW2 : I will add a page, in the docs, to explain how to embbed a guy app in a pypi package (using poetry only ... )

manatlan commented 4 years ago

btw, the new tuto is here : https://guy-docs.glitch.me/howto_build_whl_package/

manatlan commented 4 years ago

btw, i've comitted the 0.4.0 version, on github, with is "pip-packageable" (but not on pypi ... need more tests yet)

bendub commented 4 years ago

Thanks Manatlan. I'll try it tomorrow.

manatlan commented 4 years ago

the 0.4.0 is out, on pypi ... should fix this issue I close it

bendub commented 4 years ago

Sorry for the late. I packaged my app using poetry and I have the same problem again.

manatlan commented 4 years ago

In your case : perhaps you should change your static folder ... because it seems that you have prefixed it with "ui" (set guy.FOLDERSTATIC = "ui/static") ...

what the msg ?

bendub commented 4 years ago

To avoid problem, following your advice, I move 'static' directory in "myapp/myapp/static". The error reported in my browser is:

ERROR: can't find '/home/USER/.../cloc_venv/bin/static/ClocGui.html'

It seems it look for 'static' directory in the place where

__name=="__main"

PS : I test my project in a virtualenv

manatlan commented 4 years ago

You're right .. I've got the same kind of troubles, when using venv place (with poetry shell) ... So I was doing all my tests without using venv ....

If you look : https://github.com/manatlan/guy/blob/98c41e3a48f7f99dbcf1666e7b0431797c112480/guy.py#L65 It's the way it (try) to resolv where static sits ...

In fact, it will certainly work for you if you release your whl, and install it ... and execute from package.

I really need to found a new (AND SIMPLE) way to resolv this things, in all cases ... (In my the "old guy" : wuy ... devs needed to set a "wuy.path" to specify where static were ... and I don't want to do that in "guy" ...)

manatlan commented 4 years ago

Please ... try the new "0.4.1" ... It will be able to find the "static" associated with the class, in all cases ... and it should work, as expected, using venv too

bendub commented 4 years ago

It works! Thanks you Manatlan. I can access my UI now. However I had errors when I play with the config.json file. But I need to test more, perhaps the problem is from my side.

manatlan commented 4 years ago

With 0.4.1 there were trouble with config... The 0.4.2 seems ok for me

Le ven. 31 janv. 2020 à 18:37, bdubois notifications@github.com a écrit :

It works! Thanks you Manatlan. I can access my UI now. However I had errors when I play with the config.json file. But I need to test more, perhaps the problem is from my side.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/manatlan/guy/issues/3?email_source=notifications&email_token=AABEZQUBL7M4IBGL7LPOCB3RAROVZA5CNFSM4J5FPZJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKPM6OA#issuecomment-580833080, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABEZQQ6XUT6BC32MPRCHV3RAROVZANCNFSM4J5FPZJA .