Skip to content

Commit

Permalink
Update abstra-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
abstra-bot committed Nov 12, 2024
1 parent f53516a commit 0ef8fe7
Show file tree
Hide file tree
Showing 236 changed files with 471 additions and 565 deletions.
34 changes: 5 additions & 29 deletions abstra/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,14 @@ def deploy(self, root_dir: Optional[str] = None):
SettingsController.set_root_path(root_dir or select_dir())
deploy()

def editor(
self,
root_dir: Optional[str] = None,
port: int = 3000,
debug=False,
load_dotenv=True,
reloading=False,
):
def editor(self, root_dir: Optional[str] = None, port: int = 3000, headless=False):
SettingsController.set_root_path(root_dir or select_dir())
SettingsController.set_server_port(port)
editor(
debug=debug,
load_dotenv=load_dotenv,
reloading=reloading,
)

def serve(
self,
root_dir: Optional[str] = None,
port: int = 3000,
debug=False,
load_dotenv=True,
reloading=False,
):
editor(headless=headless)

def serve(self, root_dir: Optional[str] = None, port: int = 3000, headless=False):
print("This command is deprecated. Please use 'abstra editor' instead.")
self.editor(
root_dir=root_dir,
port=port,
debug=debug,
load_dotenv=load_dotenv,
reloading=reloading,
)
self.editor(root_dir=root_dir, port=port, headless=headless)

def dump(self, root_dir: str = "."):
SettingsController.set_root_path(root_dir)
Expand Down
5 changes: 5 additions & 0 deletions abstra/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import logging

logger = logging.getLogger("abstra")

__all__ = ["logger"]
50 changes: 0 additions & 50 deletions abstra_internals/editor_reloader.py

This file was deleted.

29 changes: 11 additions & 18 deletions abstra_internals/environment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import os

LOGLEVEL = os.getenv("ABSTRA_LOGLEVEL", "WARNING")
LOGFORMAT = "[%(name)s][%(levelname)s][%(process)d]%(message)s"
DEFAULT_LOGLEVEL = "WARNING"
LOGLEVEL = lambda: os.getenv("ABSTRA_LOGLEVEL", DEFAULT_LOGLEVEL) # noqa: E731

PROCESS_LOGFORMAT = "[%(asctime)s][%(levelname)s][%(name)s][%(process)d]%(message)s"
DEFAULT_LOGFORMAT = "[%(asctime)s][%(levelname)s][%(name)s] %(message)s"
LOGFORMAT = lambda: os.getenv("ABSTRA_LOGFORMAT", DEFAULT_LOGFORMAT) # noqa: E731

WORKERS = os.getenv("ABSTRA_WORKERS", 2)
THREADS = os.getenv("ABSTRA_THREADS", 20)
Expand Down Expand Up @@ -37,31 +41,20 @@
RABBITMQ_CONNECTION_URI = os.getenv("ABSTRA_RABBITMQ_CONNECTION_URI")
QUEUE_CONCURRENCY = int(os.getenv("ABSTRA_QUEUE_CONCURRENCY", 2))

__WORKER_UUID_ENV__ = "ABSTRA_WORKER_UUID"

OIDC_CLIENT_ID = lambda: os.getenv("ABSTRA_OIDC_CLIENT_ID") # noqa: E731
OIDC_AUTHORITY = lambda: os.getenv("ABSTRA_OIDC_AUTHORITY") # noqa: E731

def WORKER_UUID():
return os.getenv(__WORKER_UUID_ENV__)
__WORKER_UUID_ENV__ = "ABSTRA_WORKER_UUID"
WORKER_UUID = lambda: os.getenv(__WORKER_UUID_ENV__) # noqa: E731


def set_WORKER_UUID(worker_uuid: str):
os.environ[__WORKER_UUID_ENV__] = worker_uuid


__SERVER_UUID_ENV__ = "ABSTRA_SERVER_UUID"


def SERVER_UUID():
return os.getenv(__SERVER_UUID_ENV__)
SERVER_UUID = lambda: os.getenv(__SERVER_UUID_ENV__) # noqa: E731


def set_SERVER_UUID(server_uuid: str):
os.environ[__SERVER_UUID_ENV__] = server_uuid


def OIDC_CLIENT_ID():
return os.getenv("ABSTRA_OIDC_CLIENT_ID")


def OIDC_AUTHORITY():
return os.getenv("ABSTRA_OIDC_AUTHORITY")
5 changes: 3 additions & 2 deletions abstra_internals/fs_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from watchdog.observers import Observer

from abstra_internals.modules import reload_project_local_modules
from abstra_internals.settings import Settings

IGNORED_FILES = [".abstra/resources.dat", ".abstra/", "abstra.json"]
DEBOUNCE_DELAY = 0.5
Expand Down Expand Up @@ -39,11 +40,11 @@ def reload_files_on_change(self):
pass


def watch_file_change_events(path: str):
def watch_file_change_events():
event_handler = FileChangeEventHandler()

observer = Observer()
observer.schedule(event_handler, path=path, recursive=True)
observer.schedule(event_handler, path=str(Settings.root_path), recursive=True)
observer.start()

try:
Expand Down
35 changes: 8 additions & 27 deletions abstra_internals/interface/cli/editor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import logging
import threading

from dotenv import load_dotenv as _load_dotenv
from werkzeug.debug import DebuggedApplication
from dotenv import load_dotenv
from werkzeug.serving import make_server

from abstra_internals.controllers.execution_consumer import ExecutionConsumer
from abstra_internals.controllers.main import MainController
from abstra_internals.editor_reloader import LocalReloader
from abstra_internals.environment import HOST
from abstra_internals.fs_watcher import watch_file_change_events
from abstra_internals.interface.cli.messages import serve_message
Expand Down Expand Up @@ -46,51 +43,35 @@ def start_file_watcher():
daemon=True,
name="file_watcher",
target=watch_file_change_events,
kwargs=dict(path=str(Settings.root_path)),
).start()


def start_resources_watcher(controller: MainController):
def start_resources_watcher():
threading.Thread(
daemon=True,
name="resources_watcher",
target=resources_polling_loop,
kwargs=dict(controller=controller),
).start()


def editor(
debug: bool,
load_dotenv: bool,
reloading: bool,
):
def editor(headless: bool):
load_dotenv(Settings.root_path / ".env")
serve_message()
check_latest_version()
AbstraLogger.init("local")

controller = MainController(repositories=get_editor_repositories())
controller.reset_repositories()
StdioPatcher.apply(controller)
AbstraLogger.init("local")

start_consumer(controller)
start_file_watcher()
start_resources_watcher(controller)

if load_dotenv:
_load_dotenv(Settings.root_path / ".env")
start_resources_watcher()
start_consumer(controller)

app = get_local_app(controller)
if not debug:
log = logging.getLogger("werkzeug")
log.setLevel(logging.WARNING)
else:
app = DebuggedApplication(app, evalex=True)

server = make_server(host=HOST, port=Settings.server_port, threaded=True, app=app)

LocalReloader.set_server(server)

if not reloading:
if not headless:
browser_open_editor()

server.serve_forever()
25 changes: 13 additions & 12 deletions abstra_internals/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
from abstra_internals.environment import LOGFORMAT, LOGLEVEL
from abstra_internals.utils import is_dev_env, is_test_env


def abstra_logger():
return logging.getLogger("abstra")
internal_logger = lambda: logging.getLogger("abstra_internal") # noqa: E731


class DevSDK:
Expand All @@ -20,13 +18,13 @@ def init(cls, *args, **kwargs):

@classmethod
def capture_exception(cls, exception: BaseException):
abstra_logger().exception(
internal_logger().exception(
msg=f"[ABSTRA_LOGGER] Exception captured: {exception}"
)

@classmethod
def capture_message(cls, message):
abstra_logger().info(f"[ABSTRA_LOGGER] Message captured: {message}")
internal_logger().info(f"[ABSTRA_LOGGER] Message captured: {message}")

@classmethod
def flush(cls):
Expand All @@ -42,8 +40,11 @@ class AbstraLogger:
@classmethod
def init(cls, environment: Optional[Environment]):
cls.environment = environment or "local"
logging.basicConfig(level=LOGLEVEL, format=LOGFORMAT)
logging.getLogger("pika").setLevel(logging.WARNING) # TEMP
logging.basicConfig(level=LOGLEVEL(), format=LOGFORMAT())

# Silence verbose dependencies
logging.getLogger("pika").setLevel(logging.WARNING)
logging.getLogger("werkzeug").setLevel(logging.WARNING)

try:
cls.get_sdk().init(
Expand All @@ -59,7 +60,7 @@ def init(cls, environment: Optional[Environment]):
],
)
except Exception:
abstra_logger().error(
internal_logger().error(
"[ABSTRA_LOGGER] Error reporting has been turned off."
)

Expand All @@ -75,19 +76,19 @@ def capture_message(cls, message: str):

@classmethod
def warning(cls, message: str):
abstra_logger().warning(message)
internal_logger().warning(message)

@classmethod
def info(cls, message: str):
abstra_logger().info(message)
internal_logger().info(message)

@classmethod
def debug(cls, message: str):
abstra_logger().debug(message)
internal_logger().debug(message)

@classmethod
def error(cls, message: str):
abstra_logger().error(message)
internal_logger().error(message)

@classmethod
def get_sdk(cls):
Expand Down
3 changes: 1 addition & 2 deletions abstra_internals/resources_watcher.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import time

from abstra_internals.controllers.main import MainController
from abstra_internals.services.resources import ResourcesRepository


def resources_polling_loop(*, controller: MainController):
def resources_polling_loop():
ResourcesRepository.clear_resources()
while True:
try:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Loading

0 comments on commit 0ef8fe7

Please sign in to comment.