-
Notifications
You must be signed in to change notification settings - Fork 4
/
__init__.py
74 lines (48 loc) · 2.03 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
Copyright (C) 2024 Michael Piazza
This file is part of Smart Notes.
Smart Notes is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Smart Notes is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Smart Notes. If not, see <https://www.gnu.org/licenses/>.
"""
def update_path() -> None:
import os
import sys
from .env import environment
# Local and prod builds have different package directories
# Can't use `is_production` b/c utils requires dotenv to load, and this has to run before we import an deps
relative_packages_dir = (
"vendor" if environment == "PROD" else "env/lib/python3.11/site-packages"
)
packages_dir = os.path.join(
os.path.dirname(os.path.realpath(__file__)), relative_packages_dir
)
sys.path.append(packages_dir)
update_path()
import os
from dotenv import load_dotenv
from .src.utils import get_file_path
if not os.getenv("IS_TEST"):
load_dotenv(dotenv_path=get_file_path(".env"))
from .src.logger import logger
def setup_platform_specific_functionality() -> None:
import asyncio
import platform
# https://stackoverflow.com/questions/45600579/asyncio-event-loop-is-closed-when-getting-loop
# https://github.com/piazzatron/anki-smart-notes/issues/5
if platform.system() == "Windows":
logger.debug(
"Running in windows environment, setting event loop to selector policy"
)
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) # type: ignore
setup_platform_specific_functionality()
# Import this after setting the correct path
from .src.main import main
main()