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

Open project after exporting -- improve iteration on lovejs builds #12

Open
idbrii opened this issue Mar 29, 2021 · 3 comments
Open

Open project after exporting -- improve iteration on lovejs builds #12

idbrii opened this issue Mar 29, 2021 · 3 comments

Comments

@idbrii
Copy link
Contributor

idbrii commented Mar 29, 2021

Since lovejs seems to be tricky to get working, it would be nice to have a better flow for testing it.

Currently:

  1. modify project to try to fix
  2. makelove
  3. unzip output zip file
  4. python -m http.server
  5. open served page, test
  6. repeat

lovejs doesn't have an "artifacts" option for creating unzipped packages.

In theory, you could do something like this:

[hooks]
postbuild = [
    "unzip {build_directory}/lovejs/projectname-lovejs.zip -d {build_directory}/lovejs",
    "python -m http.server 8000 --bind 127.0.0.1 --directory {build_directory}/lovejs/projectname",
]

However, I've found that when makelove executes commands it doesn't seem to have the same PATH as where makelove is executed from, so unzip.exe and python.exe are not in the PATH (I'm on Win10 and both are installed via scoop). Using absolute paths fixes unzip, but I cannot get python to execute -- it always fails with "Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers to initialize Python".

However, since makelove is python, these steps should be doable entirely internally. An --open command that would launch the executable for desktop platforms and unzip and open an http.server for lovejs.

@idbrii
Copy link
Contributor Author

idbrii commented May 20, 2021

#14 fixes that Fatal Python error, and it allows me to use this config to improve testing:

postbuild = [
    "unzip {build_directory}/lovejs/projectname-lovejs.zip -d {build_directory}/lovejs",
    "start http://127.0.0.1:8000", # use open or xdg-open on macos/linux
    "python -m http.server 8000 --bind 127.0.0.1 --directory {build_directory}/lovejs/projectname",
]

Iteration is now much quicker:

  1. modify project to try to fix
  2. makelove
  3. test in opened page
  4. repeat

An --open flag would be nice to make this more accessible, but this workaround works well.

@pfirsich
Copy link
Owner

pfirsich commented Aug 27, 2021

What exactly would that --open flag do?
Maybe there should be a switch like --run that simply executes commands in a new kind of optional postbuild action. Did you have something like that in mind? If makelove was Linux only, I would absolutely just suggest to use a Makefile/shell wrapper for that, but the fact that most people probably don't have make installed on their Windows machines and don't like to mess around with batch or powershell files, I think that might be a good addition.

@idbrii
Copy link
Contributor Author

idbrii commented Aug 30, 2021

Passing --open would do different steps depending on the requested config. Not sure how it should interact with multiple targets. This is something that could be done from postbuild, but testing makelove's output seems relevant enough to include in the project.

desktop

unzip the package and do subprocess.run(path_to_executable). I think this should work for all platforms?

lovejs

unzip the package and do:

import http.server
import socketserver
import webbrowser
import os

PORT = 8000

# open first because serve_forever blocks
webbrowser.open(f'http://127.0.0.1:{PORT}')

# SimpleHTTPRequestHandler hosts cwd
os.chdir("{build_directory}/lovejs/{projectname}".format(**get_makelove_params())) # TODO

Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
    print("serving at port", PORT)
    try:
        httpd.serve_forever()
    except Exception:
        httpd.shutdown()

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

No branches or pull requests

2 participants