From 1e7c70078b8af67064dc9287506fc21f33f27a3b Mon Sep 17 00:00:00 2001 From: ilyazheprog Date: Sun, 10 Dec 2023 23:04:17 +0700 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=B8=D0=BC=D0=BF=D0=BE=D1=80=D1=82=D1=8B?= =?UTF-8?q?=20=D0=B2=D0=BD=D1=83=D1=82=D1=80=D0=B8=20=D0=BC=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BB=D0=B5=D0=B9,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B:=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB?= =?UTF-8?q?=D1=8C=20=D0=B4=D0=BB=D1=8F=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D0=B9,=20=D1=81=D0=BA=D1=80=D0=B8?= =?UTF-8?q?=D0=BF=D1=82=20=D0=B8=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BF=D1=83=D1=82=D0=B5=D0=B9?= =?UTF-8?q?,=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=20=D0=B1=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- init.py | 15 ++++++ run_tests | 4 ++ src/__init__.py | 1 + src/core/main.py | 10 ++-- src/modules/standard/__init__.py | 1 + src/modules/standard/config/__init__.py | 1 + src/modules/standard/config/config.py | 15 ++++++ .../{standart => standard}/config/info.json | 0 .../config/tests/config.yaml | 0 .../config/tests/test_config.py | 4 +- src/modules/standard/database/__init__.py | 1 + .../{standart => standard}/database/api.py | 25 ++++++++-- .../{standart => standard}/database/info.json | 0 .../standard/database/models/__init__.py | 1 + .../database/models/chats.py | 6 +-- .../database/models/messages.py | 6 +-- .../database/models/users.py | 6 +-- .../database/tests}/__init__.py | 0 .../database/tests/database/file | 0 .../database/tests/test_db.py | 25 ++++++++-- src/modules/standard/exceptions/__init__.py | 1 + src/modules/standard/exceptions/info.json | 6 +++ .../standard/exceptions/module_exceptions.py | 13 +++++ .../config => standard/roles}/__init__.py | 0 .../{standart => standard}/roles/api.py | 6 +-- .../{standart => standard}/roles/info.json | 0 .../roles}/tests/__init__.py | 0 .../roles/tests/config.yaml | 0 .../standard/roles/tests/test_roles.py | 50 +++++++++++++++++++ src/modules/standart/config/config.py | 5 -- src/modules/standart/database/__init__.py | 3 -- .../standart/database/models/__init__.py | 1 - src/modules/standart/database/models/base.py | 8 --- src/modules/standart/roles/__init__.py | 0 src/modules/standart/roles/tests/__init__.py | 0 .../standart/roles/tests/test_roles.py | 35 ------------- src/service.py | 23 +++++++++ 38 files changed, 198 insertions(+), 77 deletions(-) create mode 100644 init.py create mode 100644 run_tests create mode 100644 src/modules/standard/__init__.py create mode 100644 src/modules/standard/config/__init__.py create mode 100644 src/modules/standard/config/config.py rename src/modules/{standart => standard}/config/info.json (100%) rename src/modules/{standart => standard}/config/tests/config.yaml (100%) rename src/modules/{standart => standard}/config/tests/test_config.py (93%) create mode 100644 src/modules/standard/database/__init__.py rename src/modules/{standart => standard}/database/api.py (76%) rename src/modules/{standart => standard}/database/info.json (100%) create mode 100644 src/modules/standard/database/models/__init__.py rename src/modules/{standart => standard}/database/models/chats.py (76%) rename src/modules/{standart => standard}/database/models/messages.py (74%) rename src/modules/{standart => standard}/database/models/users.py (83%) rename src/modules/{standart => standard/database/tests}/__init__.py (100%) rename src/modules/{standart => standard}/database/tests/database/file (100%) rename src/modules/{standart => standard}/database/tests/test_db.py (79%) create mode 100644 src/modules/standard/exceptions/__init__.py create mode 100644 src/modules/standard/exceptions/info.json create mode 100644 src/modules/standard/exceptions/module_exceptions.py rename src/modules/{standart/config => standard/roles}/__init__.py (100%) rename src/modules/{standart => standard}/roles/api.py (91%) rename src/modules/{standart => standard}/roles/info.json (100%) rename src/modules/{standart/database => standard/roles}/tests/__init__.py (100%) rename src/modules/{standart => standard}/roles/tests/config.yaml (100%) create mode 100644 src/modules/standard/roles/tests/test_roles.py delete mode 100644 src/modules/standart/config/config.py delete mode 100644 src/modules/standart/database/__init__.py delete mode 100644 src/modules/standart/database/models/__init__.py delete mode 100644 src/modules/standart/database/models/base.py delete mode 100644 src/modules/standart/roles/__init__.py delete mode 100644 src/modules/standart/roles/tests/__init__.py delete mode 100644 src/modules/standart/roles/tests/test_roles.py create mode 100644 src/service.py diff --git a/.gitignore b/.gitignore index 7cb22bc..cd8d226 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ env venv __pycache__ -OCAB.db \ No newline at end of file +OCAB.db +paths.json \ No newline at end of file diff --git a/init.py b/init.py new file mode 100644 index 0000000..f830f57 --- /dev/null +++ b/init.py @@ -0,0 +1,15 @@ +from pathlib import Path +from json import dumps + +pwd = Path().cwd() +dir_core = pwd / "src" / "core" +dir_modules_standard = pwd / "src" / "modules" / "standard" +dir_modules_custom = pwd / "src" / "modules" / "custom" + +json = { + 'core': str(dir_core), + 'modules standard': str(dir_modules_standard), + 'modules custom': str(dir_modules_custom), +} +with open("paths.json", "w", encoding="utf8") as f: + f.write(dumps(json, indent=4)) diff --git a/run_tests b/run_tests new file mode 100644 index 0000000..1fcea0e --- /dev/null +++ b/run_tests @@ -0,0 +1,4 @@ +#! /bin/sh +cd src +python -m unittest discover -v +cd .. \ No newline at end of file diff --git a/src/__init__.py b/src/__init__.py index e69de29..bcc746e 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -0,0 +1 @@ +import service \ No newline at end of file diff --git a/src/core/main.py b/src/core/main.py index f83a1de..dad0530 100644 --- a/src/core/main.py +++ b/src/core/main.py @@ -1,18 +1,22 @@ -from src.modules.standart.config.config import yaml_load +from src.modules.standard.config.config import get_config +from src.modules.standard.database.models.base import database +from src.modules.standard.database.api import connect_database from asyncio import run from aiogram import Bot, Dispatcher - async def main(): try: - bot = Bot(token=yaml_load["TELEGRAM"]["TOKEN"]) + database = connect_database() + bot = Bot(token=get_config()["TELEGRAM"]["TOKEN"]) + dp = Dispatcher() await dp.start_polling(bot) finally: await bot.session.close() + database.close() if __name__ == "__main__": diff --git a/src/modules/standard/__init__.py b/src/modules/standard/__init__.py new file mode 100644 index 0000000..686a317 --- /dev/null +++ b/src/modules/standard/__init__.py @@ -0,0 +1 @@ +from . import config, database, exceptions, roles \ No newline at end of file diff --git a/src/modules/standard/config/__init__.py b/src/modules/standard/config/__init__.py new file mode 100644 index 0000000..d63bc18 --- /dev/null +++ b/src/modules/standard/config/__init__.py @@ -0,0 +1 @@ +from . import config diff --git a/src/modules/standard/config/config.py b/src/modules/standard/config/config.py new file mode 100644 index 0000000..f8f78e4 --- /dev/null +++ b/src/modules/standard/config/config.py @@ -0,0 +1,15 @@ +import yaml +from service import paths + + +def get_config(is_test: bool = False) -> dict: + if is_test: + path = f"{paths.modules_standard}/config/tests" + else: + path = paths.core + path = f"{path}/config.yaml" + + with open(path, 'r') as file: + return yaml.full_load(file) + + diff --git a/src/modules/standart/config/info.json b/src/modules/standard/config/info.json similarity index 100% rename from src/modules/standart/config/info.json rename to src/modules/standard/config/info.json diff --git a/src/modules/standart/config/tests/config.yaml b/src/modules/standard/config/tests/config.yaml similarity index 100% rename from src/modules/standart/config/tests/config.yaml rename to src/modules/standard/config/tests/config.yaml diff --git a/src/modules/standart/config/tests/test_config.py b/src/modules/standard/config/tests/test_config.py similarity index 93% rename from src/modules/standart/config/tests/test_config.py rename to src/modules/standard/config/tests/test_config.py index 12b891f..d60777e 100644 --- a/src/modules/standart/config/tests/test_config.py +++ b/src/modules/standard/config/tests/test_config.py @@ -1,6 +1,8 @@ -from src.modules.standart.config.config import yaml_load +from src.modules.standard.config.config import get_config import unittest +yaml_load = get_config(is_test=True) + class TestConfig(unittest.TestCase): def test_yaml_load_correctness(self): diff --git a/src/modules/standard/database/__init__.py b/src/modules/standard/database/__init__.py new file mode 100644 index 0000000..dcf9355 --- /dev/null +++ b/src/modules/standard/database/__init__.py @@ -0,0 +1 @@ +from . import api, models \ No newline at end of file diff --git a/src/modules/standart/database/api.py b/src/modules/standard/database/api.py similarity index 76% rename from src/modules/standart/database/api.py rename to src/modules/standard/database/api.py index 3b8ea66..ae6cbdf 100644 --- a/src/modules/standart/database/api.py +++ b/src/modules/standard/database/api.py @@ -1,9 +1,26 @@ -from src.modules.standart.database.models.chats import Chats -from src.modules.standart.database.models.messages import Messages -from src.modules.standart.database.models.users import Users - +from .models.chats import Chats +from .models.messages import Messages +from .models.users import Users +from service import paths +from ..exceptions.module_exceptions import MissingModuleName, NotExpectedModuleName import peewee as pw +def connect_database(is_test: bool = False, module: str | None = None): + if is_test: + if not module: + raise MissingModuleName() + db_path = f"{paths.modules_standard}/{module}/tests/database" + else: + if module: + raise NotExpectedModuleName() + db_path = f"{paths.core}/database" + + _database = pw.SqliteDatabase(f"{db_path}/OCAB.db") + Chats._meta.database = _database + Messages._meta.database = _database + Users._meta.database = _database + + return _database, f"{db_path}/OCAB.db" def create_tables(db: pw.SqliteDatabase): """Создание таблиц""" diff --git a/src/modules/standart/database/info.json b/src/modules/standard/database/info.json similarity index 100% rename from src/modules/standart/database/info.json rename to src/modules/standard/database/info.json diff --git a/src/modules/standard/database/models/__init__.py b/src/modules/standard/database/models/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/modules/standard/database/models/__init__.py @@ -0,0 +1 @@ + diff --git a/src/modules/standart/database/models/chats.py b/src/modules/standard/database/models/chats.py similarity index 76% rename from src/modules/standart/database/models/chats.py rename to src/modules/standard/database/models/chats.py index c3a2e6d..00f783c 100644 --- a/src/modules/standart/database/models/chats.py +++ b/src/modules/standard/database/models/chats.py @@ -1,9 +1,9 @@ -from .base import BaseModel - import peewee as pw -class Chats(BaseModel): +class Chats(pw.Model): + class Meta: + ... chat_role = pw.IntegerField(null=False, default=1) chat_stats = pw.IntegerField(null=False) chat_federation = pw.IntegerField(null=False) diff --git a/src/modules/standart/database/models/messages.py b/src/modules/standard/database/models/messages.py similarity index 74% rename from src/modules/standart/database/models/messages.py rename to src/modules/standard/database/models/messages.py index da18879..1f22f3d 100644 --- a/src/modules/standart/database/models/messages.py +++ b/src/modules/standard/database/models/messages.py @@ -1,9 +1,9 @@ -from .base import BaseModel - import peewee as pw -class Messages(BaseModel): +class Messages(pw.Model): + class Meta: + ... message_text = pw.TextField(null=False) message_id_sender = pw.IntegerField(null=False) answer_to_id = pw.IntegerField(null=True) diff --git a/src/modules/standart/database/models/users.py b/src/modules/standard/database/models/users.py similarity index 83% rename from src/modules/standart/database/models/users.py rename to src/modules/standard/database/models/users.py index 802d73e..eac3f31 100644 --- a/src/modules/standart/database/models/users.py +++ b/src/modules/standard/database/models/users.py @@ -1,9 +1,9 @@ -from .base import BaseModel - import peewee as pw -class Users(BaseModel): +class Users(pw.Model): + class Meta: + ... user_name = pw.CharField(null=False) # до 255 символов user_tag = pw.CharField(null=True) user_role = pw.IntegerField(null=True) diff --git a/src/modules/standart/__init__.py b/src/modules/standard/database/tests/__init__.py similarity index 100% rename from src/modules/standart/__init__.py rename to src/modules/standard/database/tests/__init__.py diff --git a/src/modules/standart/database/tests/database/file b/src/modules/standard/database/tests/database/file similarity index 100% rename from src/modules/standart/database/tests/database/file rename to src/modules/standard/database/tests/database/file diff --git a/src/modules/standart/database/tests/test_db.py b/src/modules/standard/database/tests/test_db.py similarity index 79% rename from src/modules/standart/database/tests/test_db.py rename to src/modules/standard/database/tests/test_db.py index c0b4bda..a44f86d 100644 --- a/src/modules/standart/database/tests/test_db.py +++ b/src/modules/standard/database/tests/test_db.py @@ -1,12 +1,24 @@ import unittest +import os -from src.modules.standart.database.api import * -from src.modules.standart.database.models.base import database - -create_tables(database) +from ..api import * +from ...exceptions.module_exceptions import MissingModuleName, NotExpectedModuleName class TestDatabaseAPI(unittest.TestCase): + database = None + path = None + + @classmethod + def setUpClass(cls): + cls.database, cls.path = connect_database(is_test=True, module="database") + create_tables(cls.database) + def test_fail_connect(cls): + with cls.assertRaises(MissingModuleName): + cls.database, cls.path = connect_database(is_test=True) + + with cls.assertRaises(NotExpectedModuleName): + cls.database, cls.path = connect_database(module="database") def test_add_and_get_chat(self): add_chat(chat_id=21, chat_role=0, chat_stats=0, chat_federation=0) @@ -71,6 +83,11 @@ class TestDatabaseAPI(unittest.TestCase): updated_user2 = get_user(105) self.assertEqual(updated_user2.user_name, "NewName2") + @classmethod + def tearDownClass(cls): + cls.database.close() + os.system(f"rm {cls.path}") + if __name__ == '__main__': unittest.main() diff --git a/src/modules/standard/exceptions/__init__.py b/src/modules/standard/exceptions/__init__.py new file mode 100644 index 0000000..0fe936f --- /dev/null +++ b/src/modules/standard/exceptions/__init__.py @@ -0,0 +1 @@ +from . import module_exceptions \ No newline at end of file diff --git a/src/modules/standard/exceptions/info.json b/src/modules/standard/exceptions/info.json new file mode 100644 index 0000000..28d6bdd --- /dev/null +++ b/src/modules/standard/exceptions/info.json @@ -0,0 +1,6 @@ +{ + "name": "Exceptions", + "description": "Модуль с исключениями", + "author": "OCAB Team", + "version": "1.0" +} \ No newline at end of file diff --git a/src/modules/standard/exceptions/module_exceptions.py b/src/modules/standard/exceptions/module_exceptions.py new file mode 100644 index 0000000..89f3718 --- /dev/null +++ b/src/modules/standard/exceptions/module_exceptions.py @@ -0,0 +1,13 @@ +class MissingModuleName(BaseException): + def __init__(self): + self.message = "Пропущено название директории модуля" + + super().__init__(self.message) + + +class NotExpectedModuleName(BaseException): + def __init__(self): + self.message = "Не ожидалось название директории модуля" + + super().__init__(self.message) + diff --git a/src/modules/standart/config/__init__.py b/src/modules/standard/roles/__init__.py similarity index 100% rename from src/modules/standart/config/__init__.py rename to src/modules/standard/roles/__init__.py diff --git a/src/modules/standart/roles/api.py b/src/modules/standard/roles/api.py similarity index 91% rename from src/modules/standart/roles/api.py rename to src/modules/standard/roles/api.py index 06dbc12..1a76e63 100644 --- a/src/modules/standart/roles/api.py +++ b/src/modules/standard/roles/api.py @@ -1,7 +1,7 @@ -from src.modules.standart.database import get_user_role -from src.modules.standart.config.config import yaml_load - +from ..database.api import get_user_role +from ..config.config import get_config +yaml_load = get_config() class Roles: user = "USER" moderator = "MODERATOR" diff --git a/src/modules/standart/roles/info.json b/src/modules/standard/roles/info.json similarity index 100% rename from src/modules/standart/roles/info.json rename to src/modules/standard/roles/info.json diff --git a/src/modules/standart/database/tests/__init__.py b/src/modules/standard/roles/tests/__init__.py similarity index 100% rename from src/modules/standart/database/tests/__init__.py rename to src/modules/standard/roles/tests/__init__.py diff --git a/src/modules/standart/roles/tests/config.yaml b/src/modules/standard/roles/tests/config.yaml similarity index 100% rename from src/modules/standart/roles/tests/config.yaml rename to src/modules/standard/roles/tests/config.yaml diff --git a/src/modules/standard/roles/tests/test_roles.py b/src/modules/standard/roles/tests/test_roles.py new file mode 100644 index 0000000..7748e81 --- /dev/null +++ b/src/modules/standard/roles/tests/test_roles.py @@ -0,0 +1,50 @@ +import os +import unittest +from ...database.api import create_tables, connect_database, add_user +from ..api import Roles + + +class TestRoles(unittest.IsolatedAsyncioTestCase): + database = None + path = None + + @classmethod + def setUpClass(cls): + cls.roles = Roles() + cls.database, cls.path = connect_database(is_test=True, module="roles") + create_tables(cls.database) + + add_user(user_id=1, user_name="TestUser1", user_tag="TestTag1", user_role=0, user_stats=30, user_rep=15) + add_user(user_id=2, user_name="TestUser3", user_tag="TestTag3", user_role=1, user_stats=30, user_rep=15) + add_user(user_id=3, user_name="TestUser4", user_tag="TestTag4", user_role=2, user_stats=30, user_rep=15) + add_user(user_id=4, user_name="TestUser2", user_tag="TestTag2", user_role=3, user_stats=30, user_rep=15) + async def test_check_admin_permission(cls): + cls.assertTrue(await cls.roles.check_admin_permission(1)) + cls.assertFalse(await cls.roles.check_admin_permission(2)) + cls.assertFalse(await cls.roles.check_admin_permission(3)) + cls.assertFalse(await cls.roles.check_admin_permission(4)) + + async def test_check_moderator_permission(cls): + cls.assertTrue(await cls.roles.check_moderator_permission(2)) + cls.assertFalse(await cls.roles.check_moderator_permission(0)) + cls.assertFalse(await cls.roles.check_moderator_permission(1)) + cls.assertFalse(await cls.roles.check_moderator_permission(3)) + + async def test_get_role_name(cls): + cls.assertEqual(await cls.roles.get_role_name(cls.roles.admin_role_id), "ADMIN") + cls.assertEqual(await cls.roles.get_role_name(cls.roles.moderator_role_id), "MODERATOR") + cls.assertEqual(await cls.roles.get_role_name(cls.roles.user_role_id), "USER") + cls.assertEqual(await cls.roles.get_role_name(cls.roles.bot_role_id), "BOT") + with cls.assertRaises(ValueError): + await cls.roles.get_role_name(999) # Несуществующий ID роли + + @classmethod + def tearDownClass(cls): + cls.database.close() + os.system(f"rm {cls.path}") + + + + +if __name__ == '__main__': + unittest.main() diff --git a/src/modules/standart/config/config.py b/src/modules/standart/config/config.py deleted file mode 100644 index 2591a84..0000000 --- a/src/modules/standart/config/config.py +++ /dev/null @@ -1,5 +0,0 @@ -import yaml - - -with open('config.yaml', 'r') as file: - yaml_load = yaml.full_load(file) diff --git a/src/modules/standart/database/__init__.py b/src/modules/standart/database/__init__.py deleted file mode 100644 index 7dc6621..0000000 --- a/src/modules/standart/database/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .api import * -from .models import * -from .models.base import database diff --git a/src/modules/standart/database/models/__init__.py b/src/modules/standart/database/models/__init__.py deleted file mode 100644 index 7a14cda..0000000 --- a/src/modules/standart/database/models/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .base import BaseModel diff --git a/src/modules/standart/database/models/base.py b/src/modules/standart/database/models/base.py deleted file mode 100644 index d0e4e40..0000000 --- a/src/modules/standart/database/models/base.py +++ /dev/null @@ -1,8 +0,0 @@ -import peewee as pw - -database = pw.SqliteDatabase("database/OCAB.db") - - -class BaseModel(pw.Model): - class Meta: - database = database diff --git a/src/modules/standart/roles/__init__.py b/src/modules/standart/roles/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/modules/standart/roles/tests/__init__.py b/src/modules/standart/roles/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/modules/standart/roles/tests/test_roles.py b/src/modules/standart/roles/tests/test_roles.py deleted file mode 100644 index cb93ba4..0000000 --- a/src/modules/standart/roles/tests/test_roles.py +++ /dev/null @@ -1,35 +0,0 @@ -import unittest -from src.modules.standart.database.api import create_tables, add_user -from src.modules.standart.database.models.base import database -from src.modules.standart.roles.api import Roles -import asyncio - -create_tables(database) - -class TestRoles(unittest.IsolatedAsyncioTestCase): - async def asyncSetUp(self): - self.roles = Roles() - - async def test_check_admin_permission(self): - self.assertTrue(await self.roles.check_admin_permission(1)) - self.assertFalse(await self.roles.check_admin_permission(2)) - self.assertFalse(await self.roles.check_admin_permission(3)) - self.assertFalse(await self.roles.check_admin_permission(4)) - - async def test_check_moderator_permission(self): - self.assertTrue(await self.roles.check_moderator_permission(2)) - self.assertFalse(await self.roles.check_moderator_permission(0)) - self.assertFalse(await self.roles.check_moderator_permission(1)) - self.assertFalse(await self.roles.check_moderator_permission(3)) - - async def test_get_role_name(self): - self.assertEqual(await self.roles.get_role_name(self.roles.admin_role_id), "ADMIN") - self.assertEqual(await self.roles.get_role_name(self.roles.moderator_role_id), "MODERATOR") - self.assertEqual(await self.roles.get_role_name(self.roles.user_role_id), "USER") - self.assertEqual(await self.roles.get_role_name(self.roles.bot_role_id), "BOT") - with self.assertRaises(ValueError): - await self.roles.get_role_name(999) # Несуществующий ID роли - - -if __name__ == '__main__': - unittest.main() diff --git a/src/service.py b/src/service.py new file mode 100644 index 0000000..b539ea9 --- /dev/null +++ b/src/service.py @@ -0,0 +1,23 @@ +import os.path +from dataclasses import dataclass +from json import loads + +@dataclass +class Path: + core: str + modules_standard: str + modules_custom: str + +def _get_paths(path_to_json: str): + with open(path_to_json, encoding="utf8") as f: + paths = loads(f.read()) + return Path( + core=paths["core"], + modules_standard=paths["modules standard"], + modules_custom=paths["modules custom"] + ) + +cwd = os.getcwd() +cwd = cwd[:cwd.index('/src')] + +paths = _get_paths(f"{cwd}/paths.json")