Skip to content

Commit

Permalink
update files
Browse files Browse the repository at this point in the history
 update doc string

fix build issue
  • Loading branch information
DeleMike committed Jul 3, 2023
1 parent 807be47 commit e5b390c
Show file tree
Hide file tree
Showing 11 changed files with 891 additions and 874 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@ dist
test-application/__pycache__/
test-application/dist/*
test-application/starfyre-dist/*

# dev file
starfyre/run_test.py
6 changes: 5 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/bin/sh

python3 starfyre --dev=True --path="test-application/" && python -m starfyre --build=True --path="test-application/"
<<<<<<< HEAD
python3 starfyre --path="test-application"
=======
python3 starfyre --build --path="my-first-app"
>>>>>>> 97c7e17... fix build issue
76 changes: 38 additions & 38 deletions starfyre/__init__.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import inspect
from starfyre.dom_methods import render, render_root
from .compiler import compile

from starfyre.component import Component
from .transpiler import transpile

from .parser import RootParser


def create_component(pyml="", css="", js="", client_side_python=""):
if client_side_python:
new_js = transpile(client_side_python) + js
js = new_js

local_variables = inspect.currentframe().f_back.f_back.f_locals.copy()
global_variables = inspect.currentframe().f_back.f_back.f_globals.copy()

parser = RootParser(local_variables, global_variables, css, js)
pyml = pyml.strip("\n").strip()
parser.feed(pyml)
parser.close()
pyml_root = parser.get_root()

if pyml_root is None:
return Component("div", {}, [], {}, {}, uuid="store", js=js)

return pyml_root


__all__ = [
"create_component",
"render",
"render_root",
"compile",
"transpile",
"Component",
]
import inspect
from starfyre.dom_methods import render, render_root
from .compiler import compile

from starfyre.component import Component
from .transpiler import transpile

from .parser import RootParser


def create_component(pyml="", css="", js="", client_side_python=""):
if client_side_python:
new_js = transpile(client_side_python) + js
js = new_js

local_variables = inspect.currentframe().f_back.f_back.f_locals.copy()
global_variables = inspect.currentframe().f_back.f_back.f_globals.copy()

parser = RootParser(local_variables, global_variables, css, js)
pyml = pyml.strip("\n").strip()
parser.feed(pyml)
parser.close()
pyml_root = parser.get_root()

if pyml_root is None:
return Component("div", {}, [], {}, {}, uuid="store", js=js)

return pyml_root


__all__ = [
"create_component",
"render",
"render_root",
"compile",
"transpile",
"Component",
]
137 changes: 73 additions & 64 deletions starfyre/__main__.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,73 @@
from starfyre import compile
from pathlib import Path
import sys
import os
import shutil
import subprocess
import click
import importlib.resources as pkg_resources


def write_js_file(path):
dist_path = Path(path) / "dist"
dist_path.mkdir(exist_ok=True)
js_store = pkg_resources.path("starfyre.js", "store.js")
shutil.copy(str(js_store), path + "/dist/store.js")


def create_main_file(path):
output_file_path = path + "/build/__main__.py"
write_js_file(path)

with open(output_file_path, "w") as f:
f.write(
"""
from . import app
import os
from pathlib import Path
if __name__ == '__main__':
path_ = os.path.dirname(os.path.abspath(__file__))
directory = Path(path_ ) / ".." / "dist"
if not directory.exists():
directory.mkdir()
with open(f"{directory}/index.html", "w") as f:
f.write("<script src='store.js'></script>")
f.write(app)
"""
)


@click.command()
@click.option("--path", default=".", help="Path to the project")
@click.option("--dev", default=False, help="Start the compilation and generate the build package.")
@click.option("--build", default=False, help="Start the build package")
def main(path, dev, build):
if dev:
path_ = path + "/__init__.py"
# get absolute path
path = os.path.abspath(path_)
compile(path)
create_main_file(os.path.dirname(path))
if build:
subprocess.run(
[sys.executable, "-m", "build"],
cwd=path,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)


if __name__ == "__main__":
main()
from starfyre import compile
from pathlib import Path
import sys
import os
import shutil
import subprocess
import click
import importlib.resources as pkg_resources


def write_js_file(path):
dist_path = Path(path) / "dist"
dist_path.mkdir(exist_ok=True)
js_store = pkg_resources.path("starfyre.js", "store.js")
shutil.copy(str(js_store), path + "/dist/store.js")


def create_main_file(path):
output_file_path = path + "/build/__main__.py"
write_js_file(path)

with open(output_file_path, "w") as f:
f.write(
"""
from . import app
import os
from pathlib import Path
if __name__ == '__main__':
path_ = os.path.dirname(os.path.abspath(__file__))
directory = Path(path_ ) / ".." / "dist"
if not directory.exists():
directory.mkdir()
with open(f"{directory}/index.html", "w") as f:
f.write("<script src='store.js'></script>")
f.write(app)
"""
)


@click.command()
@click.option("--path", default=".", help="Path to the project")
@click.option("--build", is_flag=True, help="Compile and build package")
def main(path, build):
"""
Command-line interface to compile and build a project.
Args:
path (str): Path to the project directory.
build (bool): Whether to start the build package.
"""
# Convert path to absolute path
path = os.path.abspath(path)

# Compile and build project
compile(os.path.join(path, "__init__.py"))
create_main_file(path)

if build:
# Start/run project
build_dir = os.path.join(path, "build")
subprocess.run(
[sys.executable, "-m", "build"],
cwd=build_dir,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)


if __name__ == "__main__":
main()

0 comments on commit e5b390c

Please sign in to comment.