coloco 0.3.0__tar.gz → 0.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. {coloco-0.3.0 → coloco-0.3.2}/PKG-INFO +3 -3
  2. {coloco-0.3.0 → coloco-0.3.2}/README.md +1 -1
  3. {coloco-0.3.0 → coloco-0.3.2}/pyproject.toml +2 -2
  4. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/api.py +15 -5
  5. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/app.py +0 -3
  6. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/cli/api.py +2 -2
  7. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/cli/dev.py +6 -2
  8. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/cli/node.py +4 -18
  9. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/codegen.py +2 -4
  10. coloco-0.3.2/src/coloco/config.py +18 -0
  11. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/+node/package.json-tpl +2 -2
  12. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/example/index.svelte-tpl +1 -1
  13. {coloco-0.3.0 → coloco-0.3.2}/LICENSE +0 -0
  14. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/__init__.py +0 -0
  15. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/__main__.py +0 -0
  16. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/cli/build.py +0 -0
  17. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/cli/createapp.py +0 -0
  18. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/cli/db.py +0 -0
  19. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/cli/package.py +0 -0
  20. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/cli/serve.py +0 -0
  21. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/db.py +0 -0
  22. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/exceptions.py +0 -0
  23. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/lifespan.py +0 -0
  24. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/static.py +0 -0
  25. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/docker/.dockerignore-tpl +0 -0
  26. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/docker/Dockerfile-tpl +0 -0
  27. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/docker/docker-compose.yml-tpl +0 -0
  28. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/+app/404.svelte-tpl +0 -0
  29. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/+app/app.css-tpl +0 -0
  30. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/+app/app.svelte-tpl +0 -0
  31. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/+app/index.html-tpl +0 -0
  32. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/+app/index.svelte-tpl +0 -0
  33. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/+app/main.ts-tpl +0 -0
  34. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/+node/openapi-ts.config.ts-tpl +0 -0
  35. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/+node/svelte.config.js-tpl +0 -0
  36. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/+node/tsconfig.json-tpl +0 -0
  37. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/+node/vite-env.d.ts-tpl +0 -0
  38. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/+node/vite.config.ts-tpl +0 -0
  39. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/.gitignore-tpl +0 -0
  40. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/README.md-tpl +0 -0
  41. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/example/api.py-tpl +0 -0
  42. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/main.py-tpl +0 -0
  43. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/pyproject.toml-tpl +0 -0
  44. {coloco-0.3.0 → coloco-0.3.2}/src/coloco/templates/standard/tsconfig.json-tpl +0 -0
  45. {coloco-0.3.0 → coloco-0.3.2}/tests/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: coloco
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: A kit for creating FastAPI + Svelte applications
5
5
  Author-Email: Channel Cat <channelcat@gmail.com>
6
6
  License: MIT
@@ -9,7 +9,7 @@ Requires-Dist: aerich[toml]==0.8.1
9
9
  Requires-Dist: fastapi==0.115.0
10
10
  Requires-Dist: PyJWT==2.10.1
11
11
  Requires-Dist: tortoise-orm[asyncpg]==0.24.0
12
- Requires-Dist: type-less==0.1.4
12
+ Requires-Dist: type-less==0.1.6
13
13
  Requires-Dist: typer==0.15.2
14
14
  Requires-Dist: uvicorn==0.31.0
15
15
  Description-Content-Type: text/markdown
@@ -26,7 +26,7 @@ Example:
26
26
  from coloco import api
27
27
 
28
28
  @api
29
- def test(name: str) -> str:
29
+ def test(name: str):
30
30
  return f"Hello {name}!"
31
31
 
32
32
  ```
@@ -10,7 +10,7 @@ Example:
10
10
  from coloco import api
11
11
 
12
12
  @api
13
- def test(name: str) -> str:
13
+ def test(name: str):
14
14
  return f"Hello {name}!"
15
15
 
16
16
  ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "coloco"
3
- version = "0.3.0"
3
+ version = "0.3.2"
4
4
  description = "A kit for creating FastAPI + Svelte applications"
5
5
  authors = [
6
6
  { name = "Channel Cat", email = "channelcat@gmail.com" },
@@ -10,7 +10,7 @@ dependencies = [
10
10
  "fastapi==0.115.0",
11
11
  "PyJWT==2.10.1",
12
12
  "tortoise-orm[asyncpg]==0.24.0",
13
- "type-less==0.1.4",
13
+ "type-less==0.1.6",
14
14
  "typer==0.15.2",
15
15
  "uvicorn==0.31.0",
16
16
  ]
@@ -11,18 +11,25 @@ from .lifespan import execute_lifespan, register_lifespan
11
11
  import logging
12
12
  from os import environ
13
13
  from type_less import fill_type_hints
14
+ from threading import Thread
14
15
 
15
16
 
16
17
  logging.basicConfig(level=logging.INFO)
17
18
 
18
19
 
19
- @asynccontextmanager
20
- async def generate_openapi(app: FastAPI):
21
- logging.info("Generating OpenAPI schema...")
20
+ def _generate_openapi_thread(app: FastAPI):
21
+ logging.info("Generating OpenAPI schema in thread...")
22
22
  generate_openapi_schema(app)
23
23
  generate_openapi_code(host=f"http://localhost:5172", diff_files=True)
24
24
 
25
+
26
+ @asynccontextmanager
27
+ async def generate_openapi(app: FastAPI):
28
+ generate_api_thread = Thread(target=_generate_openapi_thread, args=(app,))
29
+ generate_api_thread.start()
25
30
  yield
31
+ # TODO: possibly use a process and terminate instead?
32
+ generate_api_thread.join()
26
33
 
27
34
 
28
35
  def create_api(is_dev: bool = False):
@@ -72,12 +79,15 @@ def api(func):
72
79
  def _add_global_route(args, kwargs, func, method: str):
73
80
  fill_type_hints(func, use_literals=True)
74
81
 
82
+ module_name = func.__module__.lstrip("src.app")
83
+
75
84
  # Prepend module name to path
76
85
  path = args[0] if args else kwargs.get("path", "")
77
86
  path = (
78
87
  # TODO: Make this configurable
79
88
  "/api/"
80
- + func.__module__.rsplit(".", 1)[0].replace(".", "/")
89
+ # TODO: Make this read project configuration, probably need to add routes after running
90
+ + module_name.rsplit(".", 1)[0].replace(".", "/")
81
91
  + ("" if path.startswith("/") else "/")
82
92
  + path
83
93
  )
@@ -90,7 +100,7 @@ def _add_global_route(args, kwargs, func, method: str):
90
100
  *args,
91
101
  **{
92
102
  **kwargs,
93
- "summary": (kwargs.get("summary", "") + f" ({func.__module__})").strip(),
103
+ "summary": (kwargs.get("summary", "") + f" ({module_name})").strip(),
94
104
  "methods": [method],
95
105
  },
96
106
  )(func)
@@ -66,9 +66,6 @@ def create_app(name: str, database_url: str = None) -> ColocoApp:
66
66
  continue
67
67
 
68
68
  api.include_router(global_router)
69
- from fastapi.staticfiles import StaticFiles
70
-
71
- api.mount("/assets", StaticFiles(directory="dist/app/assets"), name="assets")
72
69
 
73
70
  # Production mode serves dist
74
71
  if mode == "prod":
@@ -12,7 +12,7 @@ import uvicorn
12
12
  app = typer.Typer()
13
13
 
14
14
 
15
- def _verify_app(app: str = "main.app") -> ColocoApp:
15
+ def _verify_app(app: str = "src.main.app") -> ColocoApp:
16
16
  if not "." in app:
17
17
  print(
18
18
  "[red]App should be the name of a variable in a python file, example: main.py -> api = main.api[/red]"
@@ -24,7 +24,7 @@ def _verify_app(app: str = "main.app") -> ColocoApp:
24
24
  # Needed for when running the binary
25
25
  sys.path.append(os.getcwd())
26
26
  module = import_module(module_name)
27
- except ImportError:
27
+ except ModuleNotFoundError:
28
28
  print(f"[red]Module or python file {module_name} not found[/red]")
29
29
  raise typer.Abort()
30
30
 
@@ -1,11 +1,15 @@
1
1
  from .api import _verify_app, _serve
2
+ from ..config import get_coloco_config
2
3
  from .node import install, _setup_dev_env
3
4
  import os
4
5
  from rich import print
5
6
  from subprocess import Popen
6
7
 
7
8
 
8
- def dev(app: str = "main.app", host: str = "127.0.0.1"):
9
+ def dev(app: str = None, host: str = "127.0.0.1"):
10
+ if not app:
11
+ app = get_coloco_config().get("app") or "src.main.app"
12
+
9
13
  _verify_app(app)
10
14
 
11
15
  # Check Node Modules
@@ -14,7 +18,7 @@ def dev(app: str = "main.app", host: str = "127.0.0.1"):
14
18
  install()
15
19
 
16
20
  _setup_dev_env()
17
- node = Popen([f"npm run dev"], cwd="+node", shell=True)
21
+ node = Popen([f"npm run dev"], shell=True)
18
22
  _serve(
19
23
  app=app,
20
24
  host=host,
@@ -9,31 +9,17 @@ app = typer.Typer()
9
9
 
10
10
  def _run_npm(command):
11
11
  # if not exists +node/package.json, raise error
12
- if not os.path.exists("+node/package.json"):
12
+ if not os.path.exists("package.json"):
13
13
  print(
14
- "[red]Error: +node/package.json not found. Please ensure you are in a coloco project directory.[/red]"
14
+ "[red]Error: package.json not found. Please ensure you are in a coloco project directory.[/red]"
15
15
  )
16
16
  raise typer.Abort()
17
17
 
18
- # copy +node/package.json to /package.json
19
- shutil.copyfile("+node/package.json", "package.json")
20
- if os.path.exists("+node/package-lock.json"):
21
- shutil.copyfile("+node/package-lock.json", "package-lock.json")
22
-
23
18
  try:
24
19
  # run npm install
25
20
  subprocess.run(command, cwd=".")
26
-
27
- # move package.json and package-lock.json back to +node
28
- shutil.move("package.json", "+node/package.json")
29
- shutil.move("package-lock.json", "+node/package-lock.json")
30
21
  except Exception as e:
31
22
  print(f"[red]Error: {e}[/red]")
32
- try:
33
- os.remove("package.json")
34
- os.remove("package-lock.json")
35
- except Exception:
36
- pass
37
23
  raise typer.Abort()
38
24
 
39
25
 
@@ -73,7 +59,7 @@ def dev():
73
59
  """Runs the node dev server"""
74
60
  print("[green]Running node dev server...[/green]")
75
61
  _setup_dev_env()
76
- subprocess.run(["npm", "run", "dev"], cwd="+node")
62
+ subprocess.run(["npm", "run", "dev"], cwd=".")
77
63
 
78
64
 
79
65
  @app.command()
@@ -81,4 +67,4 @@ def build(dir: str = None):
81
67
  """Runs the node dev server"""
82
68
  print("[green]Building node app...[/green]")
83
69
 
84
- subprocess.run(["npm", "run", "build"], cwd="+node")
70
+ subprocess.run(["npm", "run", "build"], cwd=".")
@@ -45,20 +45,18 @@ def generate_openapi_schema(app: FastAPI, path="/tmp/openapi.json"):
45
45
  def generate_openapi_code(
46
46
  host,
47
47
  spec_path="/tmp/openapi.json",
48
- output_dir="./+app/.generated/client",
48
+ output_dir="./src/app/.generated/client",
49
49
  diff_files=False,
50
50
  ):
51
51
  temp_dir = "/tmp/backend_api"
52
52
  output_path = os.path.join(os.getcwd(), output_dir)
53
- cwd_path = os.path.join(os.getcwd(), "+node")
54
53
 
55
54
  run(
56
-
57
55
  f"npx openapi-ts "
58
56
  f"--base {host} "
59
57
  f"--input {spec_path} "
60
58
  f"--output {temp_dir if diff_files else output_path} ".split(),
61
- cwd=cwd_path,
59
+ cwd=os.getcwd(),
62
60
  )
63
61
  if diff_files:
64
62
  compare_and_copy(temp_dir, output_dir)
@@ -0,0 +1,18 @@
1
+ import tomllib
2
+ import os
3
+
4
+
5
+ def get_coloco_config():
6
+ # Read project toml
7
+ if not os.path.exists("pyproject.toml"):
8
+ raise LookupError("pyproject.toml not found")
9
+ with open("pyproject.toml", "rb") as f:
10
+ config = tomllib.load(f)
11
+
12
+ # Get coloco config
13
+ coloco_config = config.get("tool", {}).get("coloco")
14
+ if not coloco_config:
15
+ raise LookupError(
16
+ "coloco config not found in pyproject.toml under [tool.coloco]"
17
+ )
18
+ return coloco_config
@@ -10,8 +10,8 @@
10
10
  "check": "svelte-check --tsconfig ./tsconfig.app.json && tsc -p tsconfig.node.json"
11
11
  },
12
12
  "devDependencies": {
13
- "@coloco/api-client-svelte": "^0.3.0",
14
- "@coloco/router": "^0.1.5",
13
+ "@coloco/api-client-svelte": "^0.4.10",
14
+ "@coloco/router": "^0.1.15",
15
15
  "@hey-api/client-fetch": "^0.8.2",
16
16
  "@hey-api/openapi-ts": "^0.64.7",
17
17
  "@sveltejs/vite-plugin-svelte": "^5.0.3",
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { test } from "./api";
3
3
 
4
- const results = test({ query: { name: "Testy McTesterson" } });
4
+ const results = test({ name: "Testy McTesterson" });
5
5
  </script>
6
6
 
7
7
  Calling server... {$results.loading} - {$results.data} - {$results.error}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes