Skip to content

Commit d8b79bf

Browse files
committed
Initialize Python project for Nucleoid
1 parent 9ee81c3 commit d8b79bf

File tree

10 files changed

+443
-0
lines changed

10 files changed

+443
-0
lines changed

python/.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
exclude = venv,__pycache__,migrations

python/.gitignore

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Byte-compiled / optimized / compiled files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Virtual environments
10+
venv/
11+
env/
12+
*.env
13+
*.venv
14+
15+
# Distribution / packaging
16+
.Python
17+
build/
18+
develop-eggs/
19+
dist/
20+
downloads/
21+
eggs/
22+
.eggs/
23+
lib/
24+
lib64/
25+
parts/
26+
sdist/
27+
var/
28+
*.egg-info/
29+
.installed.cfg
30+
*.egg
31+
32+
# Installer logs
33+
pip-log.txt
34+
pip-delete-this-directory.txt
35+
36+
# Unit test / coverage reports
37+
htmlcov/
38+
.tox/
39+
.nox/
40+
coverage.*
41+
.cache
42+
nosetests.xml
43+
coverage.xml
44+
*.cover
45+
*.py,cover
46+
.hypothesis/
47+
48+
# Pytest cache
49+
.pytest_cache/
50+
51+
# Django stuff:
52+
*.log
53+
*.pot
54+
*.pyc
55+
db.sqlite3
56+
db.sqlite3-journal
57+
58+
# Flask stuff:
59+
instance/
60+
.webassets-cache
61+
62+
# Scrapy stuff:
63+
.scrapy
64+
65+
# Sphinx documentation
66+
docs/_build/
67+
68+
# Jupyter Notebook
69+
.ipynb_checkpoints
70+
71+
# PyCharm
72+
.idea/
73+
74+
# VS Code
75+
.vscode/
76+
77+
# macOS
78+
.DS_Store
79+
80+
# Windows
81+
Thumbs.db
82+
ehthumbs.db
83+
84+
# Linux
85+
*~
86+
87+
# Logs and temporary files
88+
*.log
89+
*.tmp
90+
*.bak
91+
*.swp
92+
*.swo
93+
94+
# Docker
95+
*.stackdump
96+
docker-compose.override.yml
97+
98+
# Specific to project
99+
.envrc
100+
.env
101+
.mypy_cache/

python/nucleoid/Calculator.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from .logger import setup_logger
2+
3+
4+
class Calculator:
5+
def __init__(self):
6+
self.result = 0
7+
self.logger = setup_logger(__name__)
8+
self.logger.info("Calculator initialized")
9+
10+
def add(self, x, y):
11+
self.logger.debug(f"Adding numbers: {x} + {y}")
12+
self.result = x + y
13+
self.logger.info(f"Addition result: {self.result}")
14+
return self.result
15+
16+
def subtract(self, x, y):
17+
self.logger.debug(f"Subtracting numbers: {x} - {y}")
18+
self.result = x - y
19+
self.logger.info(f"Subtraction result: {self.result}")
20+
return self.result
21+
22+
def multiply(self, x, y):
23+
self.logger.debug(f"Multiplying numbers: {x} * {y}")
24+
self.result = x * y
25+
self.logger.info(f"Multiplication result: {self.result}")
26+
return self.result
27+
28+
def divide(self, x, y):
29+
self.logger.debug(f"Dividing numbers: {x} / {y}")
30+
if y == 0:
31+
self.logger.error("Division by zero attempted")
32+
raise ValueError("Division by zero is not allowed")
33+
self.result = x / y
34+
self.logger.info(f"Division result: {self.result}")
35+
return self.result

python/nucleoid/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Nucleoid Package
3+
"""

python/nucleoid/logger.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import logging
2+
3+
4+
def setup_logger(name: str) -> logging.Logger:
5+
"""
6+
Set up a logger with console handler only
7+
8+
Args:
9+
name: The name of the logger
10+
11+
Returns:
12+
logging.Logger: Configured logger instance
13+
"""
14+
logger = logging.getLogger(name)
15+
logger.setLevel(logging.DEBUG)
16+
17+
if logger.handlers:
18+
return logger
19+
20+
console_formatter = logging.Formatter("%(levelname)s - %(message)s")
21+
22+
console_handler = logging.StreamHandler()
23+
console_handler.setLevel(logging.INFO)
24+
console_handler.setFormatter(console_formatter)
25+
26+
logger.addHandler(console_handler)
27+
28+
return logger

python/nucleoid/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def main():
2+
print("Welcome to Nucleoid!")
3+
4+
5+
if __name__ == "__main__":
6+
main()

python/poetry.lock

Lines changed: 180 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/pyproject.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[tool.poetry]
2+
name = "nucleoid"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["NucTeam"]
6+
readme = "README.md"
7+
8+
[tool.poetry.dependencies]
9+
python = "^3.8.1"
10+
11+
[tool.poetry.group.dev.dependencies]
12+
flake8 = "^7.0"
13+
pytest = "^8.3.4"
14+
15+
[build-system]
16+
requires = ["poetry-core"]
17+
build-backend = "poetry.core.masonry.api"
18+
19+
[tool.poetry.scripts]
20+
test = "pytest:main"

python/tests/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Tests for Nucleoid
3+
"""

0 commit comments

Comments
 (0)