Skip to content

Commit

Permalink
__main__ can run routes too
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Feb 25, 2024
1 parent d22aa5d commit afa3488
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
15 changes: 13 additions & 2 deletions htag/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,30 @@ def init(self):
htagfile=os.path.realpath(sys.argv[1])

try:
from htag.runners import Runner
import importlib.util
module_name=os.path.basename(htagfile)[:-3]
spec = importlib.util.spec_from_file_location(module_name, htagfile)
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)

if hasattr(module,"app"):
app=getattr(module,"app")
if isinstance(app,Runner):
print("Found 'app' (new Runner), will run it")
print(app)
# run part (like defined in file, and open a tab/browser)
app.run()
sys.exit(0)

if hasattr(module,"App"):
print("Found 'App' (tag class), will run it")
tagClass=getattr(module,"App")

# run part (here FULL DEV)
from htag.runners import Runner
# run part (here FULL DEV, and open a tab/browser)
app=Runner(tagClass,reload=True,dev=True)
print(app)
app.run()
else:
print("ERROR",htagfile,"doesn't contain 'App' (tag class)")
Expand Down
3 changes: 2 additions & 1 deletion htag/runners/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,6 @@ def serve(self, request, tagClass) -> HTTPResponse:

return self.server.doGet( path, tagClass, init )


def __str__(self):
return f"<Runner dev:{self._dev} reload:{self._reload} routes:{self._routes}>"

20 changes: 0 additions & 20 deletions main.py

This file was deleted.

0 comments on commit afa3488

Please sign in to comment.