having fun with paths

This commit is contained in:
Stefan Harmuth 2021-11-26 07:53:56 +01:00
parent 96dbd7a323
commit 263b343b24
2 changed files with 20 additions and 1 deletions

3
aoc.py
View File

@ -1,7 +1,8 @@
import os
import tools
from typing import List, Any, Type
BASE_PATH = os.path.dirname(os.path.dirname(__file__))
BASE_PATH = tools.get_script_dir()
INPUTS_PATH = os.path.join(BASE_PATH, 'inputs')

18
tools.py Normal file
View File

@ -0,0 +1,18 @@
import inspect
import os.path
import sys
def get_script_dir(follow_symlinks=True):
if getattr(sys, 'frozen', False):
path = os.path.abspath(sys.executable)
else:
if '__main__' in sys.modules and hasattr(sys.modules['__main__'], '__file__'):
path = sys.modules['__main__'].__file__
else:
path = inspect.getabsfile(get_script_dir)
if follow_symlinks:
path = os.path.realpath(path)
return os.path.dirname(path)