Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions cli/src/stacksync_cli/commands/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,24 @@ def dev(api_key: str, stacksync_yml: dict) -> None:
and uses the local bridge to route traffic to the application.
"""
click.echo("Creating build folder...")
build_dir = _create_build_folder(stacksync_yml)
click.echo("Build folder created.")
build_dir = _create_build_folder()
click.echo("Build folder created. Installing dependencies...")
result = subprocess.run(
[sys.executable, "-m", "pip", "install", "-r", "requirements.txt"],
cwd=build_dir,
capture_output=True,
text=True,
)
if result.returncode != 0:
detail = (result.stderr or result.stdout or "").strip()
raise click.ClickException(
"pip install failed:\n" + detail if detail else "pip install failed."
)
click.echo("Starting application on http://127.0.0.1:2323 (Ctrl+C to stop)")
_start_application(build_dir)


def _create_build_folder(stacksync_yml: dict) -> str:
def _create_build_folder() -> str:
"""
Generates a .stacksync_build folder in the current working directory.
"""
Expand Down
36 changes: 29 additions & 7 deletions cli/src/stacksync_cli/generator_files/app_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
MODULES_DIR = os.path.join(ROOT, "modules")



def load_stacksync_yml() -> dict[str, Any]:
path = os.path.join(ROOT, "stacksync.yml")
with open(path, "r", encoding="utf-8") as f:
Expand All @@ -37,8 +36,23 @@ def import_module_from_path(module_name: str, file_path: str):


def create_app() -> Flask:
print(
"\033[36m"
+ r""" _ _ _ _
| | | | | | |
___| |_ __ _ ___| | _____ _ _ _ __ ___ ___ __| | | __
/ __| __/ _` |/ __| |/ / __| | | | '_ \ / __| / __/ _` | |/ /
\__ \ || (_| | (__| <\__ \ |_| | | | | (__ | (_| (_| | <
|___/\__\__,_|\___|_|\_\___/\__, |_| |_|\___| \___\__,_|_|\_\
__/ |
|___/
"""
+ "\033[0m",
)
if not logging.root.handlers:
logging.basicConfig(level=logging.INFO, format="%(levelname)s %(name)s: %(message)s")
logging.basicConfig(
level=logging.INFO, format="%(levelname)s %(name)s: %(message)s"
)

app = Flask(__name__)
app.logger.info("Initializing connector (root=%s)", ROOT)
Expand All @@ -58,7 +72,9 @@ def create_app() -> Flask:
for module_id, module_meta in modules_cfg.items():
package_dir = os.path.join(MODULES_DIR, module_id)
if not os.path.isdir(package_dir):
app.logger.warning("Skipping module %r: no directory at %s", module_id, package_dir)
app.logger.warning(
"Skipping module %r: no directory at %s", module_id, package_dir
)
continue

prefix = f"/modules/{module_id}"
Expand All @@ -81,7 +97,9 @@ def schema_route(
credentials = payload.get("credentials")
result = _smod.schema_handler(form_data, credentials)
# schema_handler may return a Schema (dict subclass) or plain dict
return jsonify({"schema": dict(result) if hasattr(result, "keys") else result})
return jsonify(
{"schema": dict(result) if hasattr(result, "keys") else result}
)

registered.append("schema")

Expand All @@ -92,7 +110,9 @@ def schema_route(

@app.route(f"{prefix}/content", methods=["POST"])
def content_route(_cmod=cmod, _module_id=module_id):
current_app.logger.info("Content handler called (module=%s)", _module_id)
current_app.logger.info(
"Content handler called (module=%s)", _module_id
)
payload = request.get_json(silent=True) or {}
form_data = payload.get("form_data") or {}
credentials = payload.get("credentials")
Expand All @@ -109,7 +129,9 @@ def content_route(_cmod=cmod, _module_id=module_id):

@app.route(f"{prefix}/execute", methods=["POST"])
def execute_route(_emod=emod, _module_id=module_id):
current_app.logger.info("Execute handler called (module=%s)", _module_id)
current_app.logger.info(
"Execute handler called (module=%s)", _module_id
)
payload = request.get_json(silent=True) or {}
data = payload.get("data") or {}
credentials = payload.get("credentials") or {}
Expand Down Expand Up @@ -141,4 +163,4 @@ def health():
app = create_app()

if __name__ == "__main__":
app.run(host="127.0.0.1", port=5000, debug=True)
app.run(host="127.0.0.1", port=5000, debug=True)
2 changes: 2 additions & 0 deletions templates/connector/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
git+https://github.com/stacksyncdata/cdk.git@prod#subdirectory=lib
requests>=2.31.0
Loading