Skip to content

Commit

Permalink
Create python package
Browse files Browse the repository at this point in the history
  • Loading branch information
jaagut committed Oct 24, 2024
1 parent fd0a534 commit d926ea8
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"ddlitlab"
]
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# DDLitLab2024 Project Hamburg Bit-Bots
33 changes: 33 additions & 0 deletions ddlitlab2024/__init__.py
Original file line number Diff line number Diff line change
@@ -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()
20 changes: 20 additions & 0 deletions ddlitlab2024/dataset/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 10 additions & 4 deletions data/schema.py → ddlitlab2024/dataset/schema.py
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -158,3 +162,5 @@ class GameState(Base):
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()

logger.info("Database schema created")
20 changes: 20 additions & 0 deletions ddlitlab2024/ml/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions poetry.lock

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

5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]
Expand Down

0 comments on commit d926ea8

Please sign in to comment.