Skip to content

Commit

Permalink
chore(release): 0.0.18a1
Browse files Browse the repository at this point in the history
feat: `dosei run`
feat: `dosei dev`
  • Loading branch information
Alw3ys authored Feb 6, 2024
2 parents 8c5efb4 + d716949 commit 9e9a187
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 250 deletions.
10 changes: 7 additions & 3 deletions dosei/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import inspect
import json
import os
from typing import List
from typing import List, Optional

from dosei_util import dosei_util
from croniter import croniter
Expand All @@ -27,9 +27,13 @@ def validate_schedule(cls, value):


class Dosei(BaseModel):

_app_export_path: str = ".dosei/app.json"
cron_jobs: List[CronJob] = []

name: Optional[str] = None
command: Optional[str] = None
dev: Optional[str] = None
port: Optional[int] = None
cron_jobs: Optional[List[CronJob]] = []

def cron_job(self, schedule: str):

Expand Down
27 changes: 24 additions & 3 deletions dosei/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
import subprocess
import sys

import click

from dosei import Dosei
from dosei.importer import import_from_string
from dosei.importer import import_from_string, ImportFromStringError

# Add current dir to PYTHONPATH
sys.path.insert(0, "")
Expand All @@ -15,9 +17,28 @@ def cli():


@cli.command()
@click.argument("func")
@click.argument("func", required=False)
def run(func):
Dosei.call_func(import_from_string(func))
if func:
return Dosei.call_func(import_from_string(func))
try:
app: Dosei = import_from_string("dosei:dosei")
except ImportFromStringError:
raise click.ClickException(f"Couldn't find a dosei.py file in \"{os.getcwd()}\"")
if app.dev is None:
raise click.ClickException('Command "run" not found.')
subprocess.check_call(app.command)


@cli.command()
def dev():
try:
app: Dosei = import_from_string("dosei:dosei")
except ImportFromStringError:
raise click.ClickException(f"Couldn't find a dosei.py file in \"{os.getcwd()}\"")
if app.dev is None:
raise click.ClickException('Command "dev" not found.')
subprocess.check_call(app.dev)


@cli.command()
Expand Down
447 changes: 211 additions & 236 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dosei"
version = "0.0.17"
version = "0.0.18a1"
description = "Dosei Python SDK"
authors = ["Alvaro Molina <[email protected]>"]
license = "Apache-2.0"
Expand All @@ -11,12 +11,12 @@ dosei = 'dosei.main:cli'

[tool.poetry.dependencies]
python = "^3.11"
fastapi = "^0.104.1"
fastapi = "^0.109.2"
pytest-trio = "^0.8.0"
click = "^8.1.7"
croniter = "^2.0.1"
pydantic = "^2.5.1"
dosei-util = "^0.0.1"
pydantic = "^2.6.1"
dosei-util = "^0.0.13"


[tool.poetry.group.dev.dependencies]
Expand Down
Empty file added tests/fastapi/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions tests/fastapi/dosei.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os
from dosei import Dosei

port = os.getenv('PORT', 8080)
dosei = Dosei(
name="hello-world",
command=f"uvicorn helloworld.main:app --host 0.0.0.0 --port {port}",
dev=f"uvicorn tests.fastapi.helloworld.main:app --port {port} --reload",
port=port
)
Empty file.
15 changes: 15 additions & 0 deletions tests/fastapi/hello_world/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Union

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
9 changes: 9 additions & 0 deletions tests/fastapi/test_fastapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from dosei import Dosei
from dosei.importer import import_from_string


def test_fastapi():
app: Dosei = import_from_string("tests.fastapi.dosei:dosei")
assert app.name == "hello-world"
assert app.port == 8080
assert app.command == "uvicorn helloworld.main:app --host 0.0.0.0"
6 changes: 2 additions & 4 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ async def test_async_run_cron_job():
await async_cron_job()


def test_find_init():
init_path = Dosei.find_init("./")
assert f'{__name__}:dosei' == init_path
app: Dosei = import_from_string(init_path)
def test_cron_jobs():
app: Dosei = import_from_string("tests.test_app:dosei")
assert len(app.cron_jobs) == 2

0 comments on commit 9e9a187

Please sign in to comment.