From d926ea8cbbeee176c2d05cac4b913267cb455c33 Mon Sep 17 00:00:00 2001 From: Jan Gutsche Date: Thu, 24 Oct 2024 16:39:12 +0200 Subject: [PATCH] Create python package --- .vscode/settings.json | 5 ++++ LICENSE | 2 +- README.md | 1 + ddlitlab2024/__init__.py | 33 ++++++++++++++++++++++++ ddlitlab2024/dataset/__init__.py | 20 ++++++++++++++ {data => ddlitlab2024/dataset}/schema.py | 14 +++++++--- ddlitlab2024/ml/__init__.py | 20 ++++++++++++++ poetry.lock | 4 +-- pyproject.toml | 5 ++-- 9 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 README.md create mode 100644 ddlitlab2024/__init__.py create mode 100644 ddlitlab2024/dataset/__init__.py rename {data => ddlitlab2024/dataset}/schema.py (94%) create mode 100644 ddlitlab2024/ml/__init__.py diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..644b984 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "ddlitlab" + ] +} diff --git a/LICENSE b/LICENSE index 9e20961..a335a27 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Hamburg Bit-Bots +Copyright (c) 2024 Hamburg Bit-Bots Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md new file mode 100644 index 0000000..f510072 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# DDLitLab2024 Project Hamburg Bit-Bots diff --git a/ddlitlab2024/__init__.py b/ddlitlab2024/__init__.py new file mode 100644 index 0000000..0aab677 --- /dev/null +++ b/ddlitlab2024/__init__.py @@ -0,0 +1,33 @@ +import importlib.metadata +import os +import sys +from uuid import UUID, uuid4 + +_project_name: str = "ddlitlab2024" +__version__: str = importlib.metadata.version(_project_name) + +# Craft LOGGING PATH +# Get the log directory from the environment variable or use the default +_logging_dir: str = os.environ.get("DDLITLAB_LOG_DIR", "../logs") + +# Verify that the log directory exists and create it if it doesn't +if not os.path.exists(_logging_dir): + try: + os.makedirs(_logging_dir) + except OSError: + print(f"ERROR: Failed to create log directory {_logging_dir}. Exiting.") + sys.exit(1) + +_logging_path: str = os.path.join(_logging_dir, f"{_project_name}.log") + +# Create log file if it doesn't exist or verify that it is writable +try: + with open(_logging_path, "a"): + pass +except OSError: + print(f"ERROR: Failed to create or open log file {_logging_path}. Exiting.") + sys.exit(1) + +LOGGING_PATH: str = _logging_path + +SESSION_ID: UUID = uuid4() diff --git a/ddlitlab2024/dataset/__init__.py b/ddlitlab2024/dataset/__init__.py new file mode 100644 index 0000000..a150e0f --- /dev/null +++ b/ddlitlab2024/dataset/__init__.py @@ -0,0 +1,20 @@ +import logging +import os + +from ddlitlab2024 import LOGGING_PATH, SESSION_ID + +# Init logging +logging.basicConfig( + filename=LOGGING_PATH, + encoding="utf-8", + level=logging.DEBUG, + format=f"%(asctime)s | {SESSION_ID} | %(name)s:%(levelname)s: %(message)s", +) + +# Create additional logging config for the shell with configurable log level +console = logging.StreamHandler() +console.setLevel(os.environ.get("LOGLEVEL", "INFO")) +console.setFormatter(logging.Formatter("%(levelname)s: %(message)s")) + +logger = logging.getLogger("dataset") +logger.addHandler(console) diff --git a/data/schema.py b/ddlitlab2024/dataset/schema.py similarity index 94% rename from data/schema.py rename to ddlitlab2024/dataset/schema.py index 27aa61c..ab9a8dc 100644 --- a/data/schema.py +++ b/ddlitlab2024/dataset/schema.py @@ -1,10 +1,14 @@ +from datetime import datetime from enum import Enum +from typing import List, Optional -from sqlalchemy import create_engine, Integer, String, Float, Boolean, ForeignKey, DateTime, CheckConstraint -from sqlalchemy.orm import relationship, sessionmaker, declarative_base, Mapped, mapped_column +from sqlalchemy import Boolean, CheckConstraint, DateTime, Float, ForeignKey, Integer, String, create_engine +from sqlalchemy.orm import Mapped, declarative_base, mapped_column, relationship, sessionmaker from sqlalchemy.types import LargeBinary -from typing import List, Optional -from datetime import datetime + +from ddlitlab2024.dataset import logger + +logger.info("Creating database schema") Base = declarative_base() @@ -158,3 +162,5 @@ class GameState(Base): Base.metadata.create_all(engine) Session = sessionmaker(bind=engine) session = Session() + +logger.info("Database schema created") diff --git a/ddlitlab2024/ml/__init__.py b/ddlitlab2024/ml/__init__.py new file mode 100644 index 0000000..ab610a0 --- /dev/null +++ b/ddlitlab2024/ml/__init__.py @@ -0,0 +1,20 @@ +import logging +import os + +from ddlitlab2024 import LOGGING_PATH, SESSION_ID + +# Init logging +logging.basicConfig( + filename=LOGGING_PATH, + encoding="utf-8", + level=logging.DEBUG, + format=f"%(asctime)s | {SESSION_ID} | %(name)s:%(levelname)s: %(message)s", +) + +# Create additional logging config for the shell with configurable log level +console = logging.StreamHandler() +console.setLevel(os.environ.get("LOGLEVEL", "INFO")) +console.setFormatter(logging.Formatter("%(levelname)s: %(message)s")) + +logger = logging.getLogger("ml") +logger.addHandler(console) diff --git a/poetry.lock b/poetry.lock index 9d2ab32..30cdfe8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -194,5 +194,5 @@ files = [ [metadata] lock-version = "2.0" -python-versions = "^3.8" -content-hash = "609b34c673990c805f20e5f89814d9612ab24fbf6d25457176eebd55b427c5e6" +python-versions = "^3.12" +content-hash = "27f99822cd23327d94482bc6e3b9f86564b7cd533347d98b39fff53d686f36db" diff --git a/pyproject.toml b/pyproject.toml index c135c97..4b8bcee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" [tool.poetry] -name = "ddlitlab" +name = "ddlitlab2024" version = "0.0.1" readme = "README.md" repository = "https://github.com/bit-bots/ddlitlab2024" @@ -13,10 +13,9 @@ authors = [ "Joern Griepenburg", ] description = "" -package-mode = false [tool.poetry.dependencies] -python = "^3.8" +python = "^3.12" sqlalchemy = "^2.0.36" [tool.ruff]