Skip to content

Commit

Permalink
Fix relative import errors (closes #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikitaBeloglazov committed Sep 2, 2024
1 parent 9e0810f commit daf53ac
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/ytcon/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
"""
Just placeholder for pylint. Please ignore this file
For running ytcon start yt.py file.
But when trying to call, it will try to run ytcon
"""
try:
from . import yt # pylint: disable=import-self
except (ImportError, ModuleNotFoundError) as e:
try:
import yt
except (ImportError, ModuleNotFoundError) as e:
m = "[!] [YTCON] For running YTCON, please start yt.py file, not __init__.py."
raise RuntimeError(m) from e
30 changes: 28 additions & 2 deletions src/ytcon/yt.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,36 @@

import os
import sys

import urwid

#import notify2
# - = - = - = - = - = - = - = - = - =
# Part of code, which sets the path for relative file imports
# like this: from control.variables import variables

# Unfortunately, this is a rather crooked solution,
# but unfortunately,other options simply do not work or are not acceptable

# - from .control.variables import variables
# is unacceptable because

# Traceback (most recent call last):
# File "/home/nikita/ytcon/src/ytcon/__init__.py", line 18, in <module>
# from . import yt
# File "/home/nikita/ytcon/src/ytcon/yt.py", line 64, in <module>
# from .log import init_logger, journal, logger
# File "/home/nikita/ytcon/src/ytcon/log.py", line 10, in <module>
# from .render.render import render
# File "/home/nikita/ytcon/src/ytcon/render/render.py", line 10, in <module>
# from .widgets.top_pile import widgets_tp
# ModuleNotFoundError: No module named 'ytcon.render.widgets'

# - from ytcon.control.variables import variables
# is unacceptable because git installation method will stop working

modules_path = os.path.dirname(os.path.realpath(__file__)) # get currently running script path
# print(modules_path)
sys.path.append(modules_path)
# - = - = - = - = - = - = - = - = - =

debug_that_will_be_saved_later = []
logs_that_will_be_printed_later = []
Expand Down

0 comments on commit daf53ac

Please sign in to comment.