Add windows support (#96)
This commit is contained in:
parent
40542cb0eb
commit
209f490bfc
@ -6,7 +6,8 @@
|
|||||||
"prod": "next start"
|
"prod": "next start"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@chakra-ui/icons": "^2.0.10",
|
"@chakra-ui/system": "1.12.1",
|
||||||
|
"@chakra-ui/icons": "1.1.7",
|
||||||
"@chakra-ui/react": "1.8.8",
|
"@chakra-ui/react": "1.8.8",
|
||||||
"@emotion/react": "^11.9.0",
|
"@emotion/react": "^11.9.0",
|
||||||
"@emotion/styled": "^11.8.1",
|
"@emotion/styled": "^11.8.1",
|
||||||
|
@ -11,7 +11,6 @@ PCCONFIG = f"""import pynecone as pc
|
|||||||
|
|
||||||
config = pc.Config(
|
config = pc.Config(
|
||||||
app_name="{{app_name}}",
|
app_name="{{app_name}}",
|
||||||
bun_path="{constants.BUN_PATH}",
|
|
||||||
db_url="{constants.DB_URL}",
|
db_url="{constants.DB_URL}",
|
||||||
env=pc.Env.DEV,
|
env=pc.Env.DEV,
|
||||||
)
|
)
|
||||||
|
@ -39,14 +39,14 @@ class DataTable(Gridjs):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, *children, **props):
|
def create(cls, *children, **props):
|
||||||
"""Create a datable component.
|
"""Create a datatable component.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
*children: The children of the component.
|
*children: The children of the component.
|
||||||
**props: The props to pass to the component.
|
**props: The props to pass to the component.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The datable component.
|
The datatable component.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: If a pandas dataframe is passed in and columns are also provided.
|
ValueError: If a pandas dataframe is passed in and columns are also provided.
|
||||||
|
@ -6,7 +6,6 @@ import httpx
|
|||||||
import typer
|
import typer
|
||||||
|
|
||||||
from pynecone import constants, utils
|
from pynecone import constants, utils
|
||||||
from pynecone.compiler import templates
|
|
||||||
|
|
||||||
# Create the app.
|
# Create the app.
|
||||||
cli = typer.Typer()
|
cli = typer.Typer()
|
||||||
@ -35,31 +34,16 @@ def init():
|
|||||||
raise typer.Exit()
|
raise typer.Exit()
|
||||||
|
|
||||||
with utils.console.status(f"[bold]Initializing {app_name}"):
|
with utils.console.status(f"[bold]Initializing {app_name}"):
|
||||||
# Only create the app directory if it doesn't exist.
|
# Set up the web directory.
|
||||||
|
utils.install_bun()
|
||||||
|
utils.initialize_web_directory()
|
||||||
|
|
||||||
|
# Set up the app directory, only if the config doesn't exist.
|
||||||
if not os.path.exists(constants.CONFIG_FILE):
|
if not os.path.exists(constants.CONFIG_FILE):
|
||||||
# Create a configuration file.
|
utils.create_config(app_name)
|
||||||
with open(constants.CONFIG_FILE, "w") as f:
|
utils.initialize_app_directory(app_name)
|
||||||
f.write(templates.PCCONFIG.format(app_name=app_name))
|
|
||||||
utils.console.log("Initialize the app directory.")
|
|
||||||
|
|
||||||
# Initialize the app directory.
|
# Finish initializing the app.
|
||||||
utils.cp(constants.APP_TEMPLATE_DIR, app_name)
|
|
||||||
utils.mv(
|
|
||||||
os.path.join(app_name, constants.APP_TEMPLATE_FILE),
|
|
||||||
os.path.join(app_name, app_name + constants.PY_EXT),
|
|
||||||
)
|
|
||||||
utils.cp(constants.ASSETS_TEMPLATE_DIR, constants.APP_ASSETS_DIR)
|
|
||||||
|
|
||||||
# Install bun if it isn't already installed.
|
|
||||||
if not os.path.exists(utils.get_bun_path()):
|
|
||||||
utils.console.log("Installing bun...")
|
|
||||||
os.system(constants.INSTALL_BUN)
|
|
||||||
|
|
||||||
# Initialize the web directory.
|
|
||||||
utils.console.log("Initializing the web directory.")
|
|
||||||
utils.rm(os.path.join(constants.WEB_TEMPLATE_DIR, constants.NODE_MODULES))
|
|
||||||
utils.rm(os.path.join(constants.WEB_TEMPLATE_DIR, constants.PACKAGE_LOCK))
|
|
||||||
utils.cp(constants.WEB_TEMPLATE_DIR, constants.WEB_DIR)
|
|
||||||
utils.console.log(f"[bold green]Finished Initializing: {app_name}")
|
utils.console.log(f"[bold green]Finished Initializing: {app_name}")
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ from __future__ import annotations
|
|||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
@ -291,16 +292,19 @@ def get_config() -> Config:
|
|||||||
sys.path.append(os.getcwd())
|
sys.path.append(os.getcwd())
|
||||||
try:
|
try:
|
||||||
return __import__(constants.CONFIG_MODULE).config
|
return __import__(constants.CONFIG_MODULE).config
|
||||||
except:
|
except ImportError:
|
||||||
return Config(app_name="")
|
return Config(app_name="")
|
||||||
|
|
||||||
|
|
||||||
def get_bun_path():
|
def get_bun_path() -> str:
|
||||||
"""Get the path to the bun executable.
|
"""Get the path to the bun executable.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The path to the bun executable.
|
The path to the bun executable.
|
||||||
"""
|
"""
|
||||||
|
# On windows, we use npm instead of bun.
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
return str(which("npm"))
|
||||||
return os.path.expandvars(get_config().bun_path)
|
return os.path.expandvars(get_config().bun_path)
|
||||||
|
|
||||||
|
|
||||||
@ -316,16 +320,65 @@ def get_app() -> Any:
|
|||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
def create_config(app_name: str):
|
||||||
|
"""Create a new pcconfig file.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
app_name: The name of the app.
|
||||||
|
"""
|
||||||
|
# Import here to avoid circular imports.
|
||||||
|
from pynecone.compiler import templates
|
||||||
|
|
||||||
|
with open(constants.CONFIG_FILE, "w") as f:
|
||||||
|
f.write(templates.PCCONFIG.format(app_name=app_name))
|
||||||
|
|
||||||
|
|
||||||
|
def initialize_app_directory(app_name: str):
|
||||||
|
"""Initialize the app directory on pc init.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
app_name: The name of the app.
|
||||||
|
"""
|
||||||
|
console.log("Initializing the app directory.")
|
||||||
|
cp(constants.APP_TEMPLATE_DIR, app_name)
|
||||||
|
mv(
|
||||||
|
os.path.join(app_name, constants.APP_TEMPLATE_FILE),
|
||||||
|
os.path.join(app_name, app_name + constants.PY_EXT),
|
||||||
|
)
|
||||||
|
cp(constants.ASSETS_TEMPLATE_DIR, constants.APP_ASSETS_DIR)
|
||||||
|
|
||||||
|
|
||||||
|
def initialize_web_directory():
|
||||||
|
"""Initialize the web directory on pc init."""
|
||||||
|
console.log("Initializing the web directory.")
|
||||||
|
rm(os.path.join(constants.WEB_TEMPLATE_DIR, constants.NODE_MODULES))
|
||||||
|
rm(os.path.join(constants.WEB_TEMPLATE_DIR, constants.PACKAGE_LOCK))
|
||||||
|
cp(constants.WEB_TEMPLATE_DIR, constants.WEB_DIR)
|
||||||
|
|
||||||
|
|
||||||
|
def install_bun():
|
||||||
|
"""Install bun onto the user's system."""
|
||||||
|
# Bun is not supported on Windows.
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
console.log("Skipping bun installation on Windows.")
|
||||||
|
return
|
||||||
|
|
||||||
|
# Only install if bun is not already installed.
|
||||||
|
if not os.path.exists(get_bun_path()):
|
||||||
|
console.log("Installing bun...")
|
||||||
|
os.system(constants.INSTALL_BUN)
|
||||||
|
|
||||||
|
|
||||||
def install_frontend_packages():
|
def install_frontend_packages():
|
||||||
"""Install the frontend packages."""
|
"""Install the frontend packages."""
|
||||||
# Install the base packages.
|
# Install the base packages.
|
||||||
subprocess.call([get_bun_path(), "install"], cwd=constants.WEB_DIR, stdout=PIPE)
|
subprocess.call([get_bun_path(), "install"], cwd=constants.WEB_DIR, stdout=PIPE)
|
||||||
|
|
||||||
# Install the app packages.
|
# Install the app packages.
|
||||||
for package in get_config().frontend_packages:
|
packages = get_config().frontend_packages
|
||||||
subprocess.call(
|
subprocess.call(
|
||||||
[get_bun_path(), "add", package], cwd=constants.WEB_DIR, stdout=PIPE
|
[get_bun_path(), "add", *packages], cwd=constants.WEB_DIR, stdout=PIPE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def is_initialized() -> bool:
|
def is_initialized() -> bool:
|
||||||
|
Loading…
Reference in New Issue
Block a user