Custom configuration support (#792)
This commit is contained in:
parent
3c4fb256a2
commit
fc9b03ebd7
@ -8,7 +8,10 @@ from pynecone.utils import path_ops
|
|||||||
# Template for the Pynecone config file.
|
# Template for the Pynecone config file.
|
||||||
PCCONFIG = f"""import pynecone as pc
|
PCCONFIG = f"""import pynecone as pc
|
||||||
|
|
||||||
config = pc.Config(
|
class {{config_name}}(pc.Config):
|
||||||
|
pass
|
||||||
|
|
||||||
|
config = {{config_name}}(
|
||||||
app_name="{{app_name}}",
|
app_name="{{app_name}}",
|
||||||
db_url="{constants.DB_URL}",
|
db_url="{constants.DB_URL}",
|
||||||
env=pc.Env.DEV,
|
env=pc.Env.DEV,
|
||||||
|
@ -5,6 +5,7 @@ from __future__ import annotations
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -147,8 +148,9 @@ def create_config(app_name: str):
|
|||||||
# Import here to avoid circular imports.
|
# Import here to avoid circular imports.
|
||||||
from pynecone.compiler import templates
|
from pynecone.compiler import templates
|
||||||
|
|
||||||
|
config_name = f"{re.sub(r'[^a-zA-Z]', '', app_name).capitalize()}Config"
|
||||||
with open(constants.CONFIG_FILE, "w") as f:
|
with open(constants.CONFIG_FILE, "w") as f:
|
||||||
f.write(templates.PCCONFIG.format(app_name=app_name))
|
f.write(templates.PCCONFIG.format(app_name=app_name, config_name=config_name))
|
||||||
|
|
||||||
|
|
||||||
def create_web_directory(root: Path) -> str:
|
def create_web_directory(root: Path) -> str:
|
||||||
|
@ -312,3 +312,28 @@ def test_format_upload_event(upload_event_spec):
|
|||||||
'upload_state.files, "upload_state.handle_upload1",'
|
'upload_state.files, "upload_state.handle_upload1",'
|
||||||
"UPLOAD)"
|
"UPLOAD)"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"app_name,expected_config_name",
|
||||||
|
[
|
||||||
|
("appname", "AppnameConfig"),
|
||||||
|
("app_name", "AppnameConfig"),
|
||||||
|
("app-name", "AppnameConfig"),
|
||||||
|
("appname2.io", "AppnameioConfig"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_create_config(app_name, expected_config_name, mocker):
|
||||||
|
"""Test templates.PCCONFIG is formatted with correct app name and config class name.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
app_name: App name.
|
||||||
|
expected_config_name: Expected config name.
|
||||||
|
mocker: Mocker object.
|
||||||
|
"""
|
||||||
|
mocker.patch("builtins.open")
|
||||||
|
tmpl_mock = mocker.patch("pynecone.compiler.templates.PCCONFIG")
|
||||||
|
prerequisites.create_config(app_name)
|
||||||
|
tmpl_mock.format.assert_called_with(
|
||||||
|
app_name=app_name, config_name=expected_config_name
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user