diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 8360a6e33..dcd9395db 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -59,8 +59,8 @@ jobs: - name: Set up Python Dependencies run: | - python -m pip install --upgrade pip setuptools - python -m pip install -r requirements-dev.txt --no-warn-script-location + python -m pip install --upgrade pip setuptools wheel + python -m pip install -r requirements-dev.txt - name: Compile Locale Translations run: | @@ -108,7 +108,7 @@ jobs: --tb=native \ --verbose \ --color=yes \ - --cov=pyra \ + --cov=src \ tests - name: Upload coverage diff --git a/.gitignore b/.gitignore index 7d88bf59b..07e92ee33 100644 --- a/.gitignore +++ b/.gitignore @@ -155,8 +155,6 @@ cython_debug/ node_modules/ *package-lock.json -# RetroArcher directories +# project files and directories logs/ - -# RetroArcher files *config.ini diff --git a/Dockerfile b/Dockerfile index 6ea14975f..4da75effa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -62,7 +62,7 @@ RUN groupadd -g 1000 retroarcher && \ RUN mkdir -p /config VOLUME /config -CMD ["python", "retroarcher.py"] +CMD ["python", "./src/retroarcher.py"] EXPOSE 9696 HEALTHCHECK --start-period=90s CMD python retroarcher.py --docker_healthcheck || exit 1 diff --git a/docs/source/conf.py b/docs/source/conf.py index 3078cc453..76ac9c5d1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -19,11 +19,13 @@ script_dir = os.path.dirname(os.path.abspath(__file__)) # the directory of this file source_dir = os.path.dirname(script_dir) # the source folder directory root_dir = os.path.dirname(source_dir) # the root folder directory +src_dir = os.path.join(root_dir, 'src') # the src folder directory try: - sys.path.insert(0, root_dir) - from pyra import definitions # put this in a try/except to prevent flake8 warning -except Exception: + sys.path.insert(0, src_dir) + from common import definitions # put this in a try/except to prevent flake8 warning +except Exception as e: + print(f"Unable to import definitions from {root_dir}: {e}") sys.exit(1) # -- Project information ----------------------------------------------------- diff --git a/docs/source/contributing/localization.rst b/docs/source/contributing/localization.rst index 56c5fc4a0..48bab51f1 100644 --- a/docs/source/contributing/localization.rst +++ b/docs/source/contributing/localization.rst @@ -43,7 +43,7 @@ situations. For example the system tray icon is user interfacing and therefore s - In order for strings to be extracted from python code, the following lines must be added. .. code-block:: python - from pyra import locales + from common import locales _ = locales.get_text() - Wrap the string to be extracted in a function as shown. @@ -76,8 +76,7 @@ any of the following paths are modified. .. code-block:: yaml - - 'retroarcher.py' - - 'pyra/**.py' + - 'src/**.py' - 'web/templates/**' When testing locally it may be desirable to manually extract, initialize, update, and compile strings. diff --git a/docs/source/pyra_docs/config.rst b/docs/source/pyra_docs/config.rst deleted file mode 100644 index 27d12371a..000000000 --- a/docs/source/pyra_docs/config.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. include:: ../global.rst - -:modname:`pyra.config` ----------------------- -.. automodule:: pyra.config - :members: - :show-inheritance: diff --git a/docs/source/pyra_docs/hardware.rst b/docs/source/pyra_docs/hardware.rst deleted file mode 100644 index 7c5a1c8a6..000000000 --- a/docs/source/pyra_docs/hardware.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. include:: ../global.rst - -:modname:`pyra.hardware` ---------------------------- -.. automodule:: pyra.hardware - :members: - :show-inheritance: diff --git a/docs/source/pyra_docs/helpers.rst b/docs/source/pyra_docs/helpers.rst deleted file mode 100644 index a5f116a8d..000000000 --- a/docs/source/pyra_docs/helpers.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. include:: ../global.rst - -:modname:`pyra.helpers` ------------------------ -.. automodule:: pyra.helpers - :members: - :show-inheritance: diff --git a/docs/source/pyra_docs/locales.rst b/docs/source/pyra_docs/locales.rst deleted file mode 100644 index db2754c90..000000000 --- a/docs/source/pyra_docs/locales.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. include:: ../global.rst - -:modname:`pyra.locales` ------------------------ -.. automodule:: pyra.locales - :members: - :show-inheritance: diff --git a/docs/source/pyra_docs/logger.rst b/docs/source/pyra_docs/logger.rst deleted file mode 100644 index c4c38a92b..000000000 --- a/docs/source/pyra_docs/logger.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. include:: ../global.rst - -:modname:`pyra.logger` ----------------------- -.. automodule:: pyra.logger - :members: - :show-inheritance: diff --git a/docs/source/pyra_docs/threads.rst b/docs/source/pyra_docs/threads.rst deleted file mode 100644 index 0d29f9d2f..000000000 --- a/docs/source/pyra_docs/threads.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. include:: ../global.rst - -:modname:`pyra.threads` ------------------------ -.. automodule:: pyra.threads - :members: - :show-inheritance: diff --git a/docs/source/pyra_docs/webapp.rst b/docs/source/pyra_docs/webapp.rst deleted file mode 100644 index c8f3dcdf2..000000000 --- a/docs/source/pyra_docs/webapp.rst +++ /dev/null @@ -1,7 +0,0 @@ -.. include:: ../global.rst - -:modname:`pyra.webapp` ----------------------- -.. automodule:: pyra.webapp - :members: - :show-inheritance: diff --git a/docs/source/src/common/common.rst b/docs/source/src/common/common.rst new file mode 100644 index 000000000..0f301a6a3 --- /dev/null +++ b/docs/source/src/common/common.rst @@ -0,0 +1,7 @@ +.. include:: ../global.rst + +:modname:`common.__init__` +-------------------------- +.. automodule:: common + :members: + :show-inheritance: diff --git a/docs/source/pyra_docs/pyra.rst b/docs/source/src/common/config.rst similarity index 62% rename from docs/source/pyra_docs/pyra.rst rename to docs/source/src/common/config.rst index 1355c9f68..30f6b6c99 100644 --- a/docs/source/pyra_docs/pyra.rst +++ b/docs/source/src/common/config.rst @@ -1,7 +1,7 @@ .. include:: ../global.rst -:modname:`pyra.__init__` +:modname:`common.config` ------------------------ -.. automodule:: pyra +.. automodule:: common.config :members: :show-inheritance: diff --git a/docs/source/src/common/definitions.rst b/docs/source/src/common/definitions.rst new file mode 100644 index 000000000..86c964650 --- /dev/null +++ b/docs/source/src/common/definitions.rst @@ -0,0 +1,7 @@ +.. include:: ../global.rst + +:modname:`common.definitions` +----------------------------- +.. automodule:: common.definitions + :members: + :show-inheritance: diff --git a/docs/source/src/common/hardware.rst b/docs/source/src/common/hardware.rst new file mode 100644 index 000000000..66e9c33a1 --- /dev/null +++ b/docs/source/src/common/hardware.rst @@ -0,0 +1,7 @@ +.. include:: ../global.rst + +:modname:`common.hardware` +-------------------------- +.. automodule:: common.hardware + :members: + :show-inheritance: diff --git a/docs/source/pyra_docs/tray_icon.rst b/docs/source/src/common/helpers.rst similarity index 61% rename from docs/source/pyra_docs/tray_icon.rst rename to docs/source/src/common/helpers.rst index e4fc34c28..9f08d062f 100644 --- a/docs/source/pyra_docs/tray_icon.rst +++ b/docs/source/src/common/helpers.rst @@ -1,7 +1,7 @@ .. include:: ../global.rst -:modname:`pyra.tray_icon` +:modname:`common.helpers` ------------------------- -.. automodule:: pyra.tray_icon +.. automodule:: common.helpers :members: :show-inheritance: diff --git a/docs/source/src/common/locales.rst b/docs/source/src/common/locales.rst new file mode 100644 index 000000000..f6a1776ce --- /dev/null +++ b/docs/source/src/common/locales.rst @@ -0,0 +1,7 @@ +.. include:: ../global.rst + +:modname:`common.locales` +------------------------- +.. automodule:: common.locales + :members: + :show-inheritance: diff --git a/docs/source/src/common/logger.rst b/docs/source/src/common/logger.rst new file mode 100644 index 000000000..5451e66a2 --- /dev/null +++ b/docs/source/src/common/logger.rst @@ -0,0 +1,7 @@ +.. include:: ../global.rst + +:modname:`common.logger` +------------------------ +.. automodule:: common.logger + :members: + :show-inheritance: diff --git a/docs/source/src/common/threads.rst b/docs/source/src/common/threads.rst new file mode 100644 index 000000000..dda872f9e --- /dev/null +++ b/docs/source/src/common/threads.rst @@ -0,0 +1,7 @@ +.. include:: ../global.rst + +:modname:`common.threads` +------------------------- +.. automodule:: common.threads + :members: + :show-inheritance: diff --git a/docs/source/pyra_docs/definitions.rst b/docs/source/src/common/tray_icon.rst similarity index 60% rename from docs/source/pyra_docs/definitions.rst rename to docs/source/src/common/tray_icon.rst index 7902f1ab2..ea83144d3 100644 --- a/docs/source/pyra_docs/definitions.rst +++ b/docs/source/src/common/tray_icon.rst @@ -1,7 +1,7 @@ .. include:: ../global.rst -:modname:`pyra.definitions` +:modname:`common.tray_icon` --------------------------- -.. automodule:: pyra.definitions +.. automodule:: common.tray_icon :members: :show-inheritance: diff --git a/docs/source/src/common/webapp.rst b/docs/source/src/common/webapp.rst new file mode 100644 index 000000000..68ce33887 --- /dev/null +++ b/docs/source/src/common/webapp.rst @@ -0,0 +1,7 @@ +.. include:: ../global.rst + +:modname:`common.webapp` +------------------------ +.. automodule:: common.webapp + :members: + :show-inheritance: diff --git a/docs/source/main/retroarcher.rst b/docs/source/src/retroarcher.rst similarity index 100% rename from docs/source/main/retroarcher.rst rename to docs/source/src/retroarcher.rst diff --git a/docs/source/toc.rst b/docs/source/toc.rst index c03f6a46a..5d0dd24c2 100644 --- a/docs/source/toc.rst +++ b/docs/source/toc.rst @@ -22,14 +22,14 @@ :caption: Code :titlesonly: - main/retroarcher - pyra_docs/pyra - pyra_docs/config - pyra_docs/definitions - pyra_docs/hardware - pyra_docs/helpers - pyra_docs/locales - pyra_docs/logger - pyra_docs/threads - pyra_docs/tray_icon - pyra_docs/webapp + src/retroarcher + src/common/common + src/common/config + src/common/definitions + src/common/hardware + src/common/helpers + src/common/locales + src/common/logger + src/common/threads + src/common/tray_icon + src/common/webapp diff --git a/scripts/build.py b/scripts/build.py index 773b010ab..c99d3e962 100644 --- a/scripts/build.py +++ b/scripts/build.py @@ -14,7 +14,7 @@ def build(): """Sets arguments for pyinstaller, creates spec, and builds binaries.""" pyinstaller_args = [ - 'retroarcher.py', + './src/retroarcher.py', '--onefile', '--noconfirm', '--paths=./', diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/pyra/__init__.py b/src/common/__init__.py similarity index 95% rename from pyra/__init__.py rename to src/common/__init__.py index e1473cc7b..15fde9d37 100644 --- a/pyra/__init__.py +++ b/src/common/__init__.py @@ -15,10 +15,10 @@ from typing import Union # local imports -from pyra import config -from pyra import definitions -from pyra import helpers -from pyra import logger +from common import config +from common import definitions +from common import helpers +from common import logger # get logger log = logger.get_logger(name=__name__) @@ -121,7 +121,7 @@ def stop(exit_code: Union[int, str] = 0, restart: bool = False): >>> stop(exit_code=0, restart=False) """ # stop the tray icon - from pyra.tray_icon import tray_end + from common.tray_icon import tray_end try: tray_end() except AttributeError: diff --git a/pyra/config.py b/src/common/config.py similarity index 98% rename from pyra/config.py rename to src/common/config.py index c01b67da8..f13a75f0d 100644 --- a/pyra/config.py +++ b/src/common/config.py @@ -13,9 +13,9 @@ from validate import Validator, ValidateError # local imports -from pyra import definitions -from pyra import logger -from pyra import locales +from common import definitions +from common import logger +from common import locales # get log log = logger.get_logger(name=__name__) @@ -47,14 +47,14 @@ def on_change_tray_toggle() -> bool: See Also -------- - pyra.tray_icon.tray_toggle : ``on_change_tray_toggle`` is an alias of this function. + common.tray_icon.tray_toggle : ``on_change_tray_toggle`` is an alias of this function. Examples -------- >>> on_change_tray_toggle() True """ - from pyra import tray_icon + from common import tray_icon return tray_icon.tray_toggle() diff --git a/pyra/definitions.py b/src/common/definitions.py similarity index 92% rename from pyra/definitions.py rename to src/common/definitions.py index e0fc24288..4960334b0 100644 --- a/pyra/definitions.py +++ b/src/common/definitions.py @@ -124,8 +124,10 @@ class Paths: The purpose of this class is to ensure consistency when using these paths. - PYRA_DIR : str - The directory containing the retroarcher python files. + COMMON_DIR : str + The directory containing the common python files. + SRC_DIR : str + The directory containing the application python files ROOT_DIR : str The root directory of the application. This is where the source files exist. DATA_DIR : str @@ -139,11 +141,12 @@ class Paths: Examples -------- - >>> Paths.logs + >>> Paths.LOG_DIR '.../logs' """ - PYRA_DIR = os.path.dirname(os.path.abspath(__file__)) - ROOT_DIR = os.path.dirname(PYRA_DIR) + COMMON_DIR = os.path.dirname(os.path.abspath(__file__)) + SRC_DIR = os.path.dirname(COMMON_DIR) + ROOT_DIR = os.path.dirname(SRC_DIR) DATA_DIR = ROOT_DIR BINARY_PATH = os.path.abspath(os.path.join(DATA_DIR, 'retroarcher.py')) diff --git a/pyra/hardware.py b/src/common/hardware.py similarity index 98% rename from pyra/hardware.py rename to src/common/hardware.py index 44b885d78..9ad556de2 100644 --- a/pyra/hardware.py +++ b/src/common/hardware.py @@ -12,10 +12,10 @@ import psutil # local imports -from pyra import definitions -from pyra import helpers -from pyra import locales -from pyra import logger +from common import definitions +from common import helpers +from common import locales +from common import logger try: cpu_name = cpuinfo.cpu.info[0]['ProcessorNameString'].strip() @@ -335,7 +335,7 @@ def chart_data() -> dict: See Also -------- - pyra.webapp.callback_dashboard : A callback called by javascript to get this data. + common.webapp.callback_dashboard : A callback called by javascript to get this data. Examples -------- diff --git a/pyra/helpers.py b/src/common/helpers.py similarity index 100% rename from pyra/helpers.py rename to src/common/helpers.py diff --git a/pyra/locales.py b/src/common/locales.py similarity index 97% rename from pyra/locales.py rename to src/common/locales.py index 0e97027e3..f88afbd06 100644 --- a/pyra/locales.py +++ b/src/common/locales.py @@ -27,9 +27,9 @@ from babel import localedata # local imports -from pyra import config -from pyra.definitions import Paths -from pyra import logger +from common import config +from common.definitions import Paths +from common import logger default_domain = 'retroarcher' default_locale = 'en' diff --git a/pyra/logger.py b/src/common/logger.py similarity index 96% rename from pyra/logger.py rename to src/common/logger.py index 6c1601b30..3bb970e41 100644 --- a/pyra/logger.py +++ b/src/common/logger.py @@ -25,12 +25,12 @@ from configobj import ConfigObj # local imports -import pyra -from pyra import definitions -from pyra import helpers +import common +from common import definitions +from common import helpers # These settings are for file logging only -py_name = 'pyra' +py_name = 'common' MAX_SIZE = 5000000 # 5 MB MAX_FILES = 5 @@ -67,7 +67,7 @@ def blacklist_config(config: ConfigObj): Examples -------- - >>> config_object = pyra.config.create_config(config_file='config.ini') + >>> config_object = common.config.create_config(config_file='config.ini') >>> blacklist_config(config=config_object) """ blacklist = set() @@ -102,7 +102,7 @@ class NoThreadFilter(logging.Filter): Examples -------- >>> NoThreadFilter('main') - + """ def __init__(self, threadName): @@ -152,7 +152,7 @@ class BlacklistFilter(logging.Filter): Examples -------- >>> BlacklistFilter() - + """ def __init__(self): @@ -223,7 +223,7 @@ class RegexFilter(logging.Filter): Examples -------- >>> RegexFilter() - + """ def __init__(self): @@ -301,7 +301,7 @@ class PublicIPFilter(RegexFilter): Examples -------- >>> PublicIPFilter() - + """ def __init__(self): @@ -358,7 +358,7 @@ class EmailFilter(RegexFilter): Examples -------- >>> EmailFilter() - + """ def __init__(self): @@ -414,7 +414,7 @@ class PlexTokenFilter(RegexFilter): Examples -------- >>> PlexTokenFilter() - + """ def __init__(self): @@ -568,7 +568,7 @@ def setup_loggers(): """ loggers_list = [py_name, 'werkzeug'] - submodules = pkgutil.iter_modules(pyra.__path__) + submodules = pkgutil.iter_modules(common.__path__) for submodule in submodules: loggers_list.append(f'{py_name}.{submodule[1]}') @@ -613,7 +613,7 @@ def init_logger(log_name: str) -> logging.Logger: # Configure the logger to accept all messages logger.propagate = False - logger.setLevel(logging.DEBUG if pyra.DEBUG else logging.INFO) + logger.setLevel(logging.DEBUG if common.DEBUG else logging.INFO) # Setup file logger file_formatter = logging.Formatter('%(asctime)s - %(levelname)-7s :: %(threadName)s : %(message)s', @@ -631,7 +631,7 @@ def init_logger(log_name: str) -> logging.Logger: logger.addHandler(file_handler) # Setup console logger - if not pyra.QUIET: + if not common.QUIET: console_formatter = logging.Formatter('%(asctime)s - %(levelname)s :: %(threadName)s : %(message)s', '%Y-%m-%d %H:%M:%S') console_handler = logging.StreamHandler() @@ -643,7 +643,7 @@ def init_logger(log_name: str) -> logging.Logger: # Add filters to log handlers # Only add filters after the config file has been initialized # Nothing prior to initialization should contain sensitive information - if not pyra.DEV and pyra.CONFIG: + if not common.DEV and common.CONFIG: log_handlers = logger.handlers for handler in log_handlers: handler.addFilter(BlacklistFilter()) @@ -652,7 +652,7 @@ def init_logger(log_name: str) -> logging.Logger: handler.addFilter(PlexTokenFilter()) # Install exception hooks - if log_name == py_name: # all tracebacks go to 'pyra.log' + if log_name == py_name: # all tracebacks go to 'common.log' _init_hooks(logger) # replace warn diff --git a/pyra/threads.py b/src/common/threads.py similarity index 84% rename from pyra/threads.py rename to src/common/threads.py index 10dd23785..2af452c9c 100644 --- a/pyra/threads.py +++ b/src/common/threads.py @@ -11,15 +11,15 @@ Examples -------- ->>> from pyra import config, threads, tray_icon +>>> from common import config, threads, tray_icon >>> config_object = config.create_config(config_file='config.ini') >>> tray_icon.icon = tray_icon.tray_initialize() >>> threads.run_in_thread(target=tray_icon.tray_run, name='pystray', daemon=True).start() ->>> from pyra import config, threads, webapp +>>> from common import config, threads, webapp >>> config_object = config.create_config(config_file='config.ini') >>> threads.run_in_thread(target=webapp.start_webapp, name='Flask', daemon=True).start() - * Serving Flask app 'pyra.webapp' (lazy loading) + * Serving Flask app 'common.webapp' (lazy loading) ... * Running on http://.../ (Press CTRL+C to quit) """ diff --git a/pyra/tray_icon.py b/src/common/tray_icon.py similarity index 95% rename from pyra/tray_icon.py rename to src/common/tray_icon.py index 6b7baee68..f6a8a411b 100644 --- a/pyra/tray_icon.py +++ b/src/common/tray_icon.py @@ -12,13 +12,13 @@ from PIL import Image # local imports -import pyra -from pyra import config -from pyra import definitions -from pyra import helpers -from pyra import locales -from pyra import logger -from pyra import threads +import common +from common import config +from common import definitions +from common import helpers +from common import locales +from common import logger +from common import threads # setup _ = locales.get_text() @@ -197,7 +197,7 @@ def tray_run_threaded() -> bool: -------- tray_initialize : This function first, initializes the tray icon using ``tray_initialize()``. tray_run : Then, ``tray_run`` is executed in a thread. - pyra.threads.run_in_thread : Run a method within a thread. + common.threads.run_in_thread : Run a method within a thread. Examples -------- @@ -243,26 +243,26 @@ def tray_quit(): """ Shutdown RetroArcher. - Set the 'pyra.SIGNAL' variable to 'shutdown'. + Set the 'common.SIGNAL' variable to 'shutdown'. Examples -------- >>> tray_quit() """ - pyra.SIGNAL = 'shutdown' + common.SIGNAL = 'shutdown' def tray_restart(): """ Restart RetroArcher. - Set the 'pyra.SIGNAL' variable to 'restart'. + Set the 'common.SIGNAL' variable to 'restart'. Examples -------- >>> tray_restart() """ - pyra.SIGNAL = 'restart' + common.SIGNAL = 'restart' def tray_run(): diff --git a/pyra/webapp.py b/src/common/webapp.py similarity index 94% rename from pyra/webapp.py rename to src/common/webapp.py index 713127322..ba24147fe 100644 --- a/pyra/webapp.py +++ b/src/common/webapp.py @@ -14,12 +14,12 @@ from flask_babel import Babel # local imports -import pyra -from pyra import config -from pyra import hardware -from pyra.definitions import Paths -from pyra import locales -from pyra import logger +import common +from common import config +from common import hardware +from common.definitions import Paths +from common import locales +from common import logger # localization _ = locales.get_text() @@ -85,7 +85,7 @@ def render_template(template_name_or_list, **context): -------- >>> render_template(template_name_or_list='home.html', title=_('Home')) """ - context['ui_config'] = pyra.CONFIG['User_Interface'].copy() + context['ui_config'] = common.CONFIG['User_Interface'].copy() return flask_render_template(template_name_or_list=template_name_or_list, **context) @@ -134,7 +134,7 @@ def callback_dashboard() -> Response: See Also -------- - pyra.hardware.chart_data : This function sets up the data in the proper format. + common.hardware.chart_data : This function sets up the data in the proper format. Examples -------- @@ -177,7 +177,7 @@ def settings(configuration_spec: Optional[str]) -> render_template: -------- >>> settings() """ - config_settings = pyra.CONFIG + config_settings = common.CONFIG if not configuration_spec: config_spec = config._CONFIG_SPEC_DICT @@ -273,7 +273,7 @@ def test_logger() -> str: """ Test logging functions. - Check `./logs/pyra.webapp.log` for output. + Check `./logs/common.webapp.log` for output. Returns ------- @@ -395,19 +395,19 @@ def start_webapp(): Examples -------- >>> start_webapp() - * Serving Flask app 'pyra.webapp' (lazy loading) + * Serving Flask app 'common.webapp' (lazy loading) ... * Running on http://.../ (Press CTRL+C to quit) - >>> from pyra import webapp, threads + >>> from common import webapp, threads >>> threads.run_in_thread(target=webapp.start_webapp, name='Flask', daemon=True).start() - * Serving Flask app 'pyra.webapp' (lazy loading) + * Serving Flask app 'common.webapp' (lazy loading) ... * Running on http://.../ (Press CTRL+C to quit) """ app.run( host=config.CONFIG['Network']['HTTP_HOST'], port=config.CONFIG['Network']['HTTP_PORT'], - debug=pyra.DEV, + debug=common.DEV, use_reloader=False # reloader doesn't work when running in a separate thread ) diff --git a/retroarcher.py b/src/retroarcher.py similarity index 84% rename from retroarcher.py rename to src/retroarcher.py index 0b3edac8f..97280679c 100644 --- a/retroarcher.py +++ b/src/retroarcher.py @@ -16,15 +16,15 @@ from typing import Union # local imports -import pyra -from pyra import config -from pyra import definitions -from pyra import helpers -from pyra import locales -from pyra import logger -from pyra import threads +import common +from common import config +from common import definitions +from common import helpers +from common import locales +from common import logger +from common import threads -py_name = 'pyra' +py_name = 'common' # locales _ = locales.get_text() @@ -153,16 +153,16 @@ def main(): else: config_file = os.path.join(definitions.Paths.DATA_DIR, definitions.Files.CONFIG) if args.debug: - pyra.DEBUG = True + common.DEBUG = True if args.dev: - pyra.DEV = True + common.DEV = True if args.quiet: - pyra.QUIET = True + common.QUIET = True # initialize retroarcher # logging should not occur until after initialize # any submodules that require translations need to be imported after config is initialize - pyra.initialize(config_file=config_file) + common.initialize(config_file=config_file) if args.config: log.info(msg=f"RetroArcher is using custom config file: {config_file}.") @@ -178,7 +178,7 @@ def main(): config.CONFIG.write() if config.CONFIG['General']['SYSTEM_TRAY']: - from pyra import tray_icon # submodule requires translations so importing after initialization + from common import tray_icon # submodule requires translations so importing after initialization # also do not import if not required by config options tray_icon.tray_run_threaded() @@ -188,7 +188,7 @@ def main(): pyi_splash.update_text("Starting the webapp") time.sleep(3) # show splash screen for a min of 3 seconds pyi_splash.close() # close the splash screen - from pyra import webapp # import at use due to translations + from common import webapp # import at use due to translations threads.run_in_thread(target=webapp.start_webapp, name='Flask', daemon=True).start() # this should be after starting flask app @@ -203,35 +203,35 @@ def wait(): """ Wait for signal. - Endlessly loop while `pyra.SIGNAL = None`. - If `pyra.SIGNAL` is changed to `shutdown` or `restart` `pyra.stop()` will be executed. - If KeyboardInterrupt signal is detected `pyra.stop()` will be executed. + Endlessly loop while `common.SIGNAL = None`. + If `common.SIGNAL` is changed to `shutdown` or `restart` `common.stop()` will be executed. + If KeyboardInterrupt signal is detected `common.stop()` will be executed. Examples -------- >>> wait() """ - from pyra import hardware # submodule requires translations so importing after initialization + from common import hardware # submodule requires translations so importing after initialization log.info("RetroArcher is ready!") while True: # wait endlessly for a signal - if not pyra.SIGNAL: + if not common.SIGNAL: hardware.update() # update dashboard resource values try: time.sleep(1) except KeyboardInterrupt: - pyra.SIGNAL = 'shutdown' + common.SIGNAL = 'shutdown' else: - log.info(f'Received signal: {pyra.SIGNAL}') + log.info(f'Received signal: {common.SIGNAL}') - if pyra.SIGNAL == 'shutdown': - pyra.stop() - elif pyra.SIGNAL == 'restart': - pyra.stop(restart=True) + if common.SIGNAL == 'shutdown': + common.stop() + elif common.SIGNAL == 'restart': + common.stop(restart=True) else: log.error('Unknown signal. Shutting down...') - pyra.stop() + common.stop() break diff --git a/tests/conftest.py b/tests/conftest.py index f65567ad7..5c83f99d9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,15 +6,22 @@ """ # standard imports import os +import sys # lib imports import pytest -# local imports -import pyra -from pyra import config -from pyra import definitions -from pyra import webapp +root_dir = os.path.abspath(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +src_dir = os.path.join(root_dir, 'src') + +if os.path.isdir(src_dir): # avoid flake8 E402 warning + sys.path.insert(0, src_dir) + + # local imports + import src.common + from src.common import config + from src.common import definitions + from src.common import webapp @pytest.fixture(scope='function') @@ -36,17 +43,17 @@ def test_config_object(test_config_file): @pytest.fixture(scope='function') -def test_pyra_init(test_config_file): - test_pyra_init = pyra.initialize(config_file=test_config_file) +def test_common_init(test_config_file): + test_common_init = src.common.initialize(config_file=test_config_file) - yield test_pyra_init + yield test_common_init - pyra._INITIALIZED = False - pyra.SIGNAL = 'shutdown' + src.common._INITIALIZED = False + src.common.SIGNAL = 'shutdown' @pytest.fixture(scope='function') -def test_client(test_pyra_init): +def test_client(test_common_init): """Create a test client for testing webapp endpoints""" app = webapp.app app.testing = True diff --git a/tests/functional/test_webapp.py b/tests/functional/test_webapp.py index 57ea98ee5..cfb43e555 100644 --- a/tests/functional/test_webapp.py +++ b/tests/functional/test_webapp.py @@ -2,7 +2,7 @@ .. test_webapp.py -Functional tests for pyra.webapp. +Functional tests for src.common.webapp. """ # standard imports import json diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index d8052f018..a5b7deb67 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -2,7 +2,7 @@ .. test_config.py -Unit tests for pyra.config. +Unit tests for src.common.config. """ # standard imports import time @@ -12,7 +12,7 @@ import pytest # local imports -from pyra import config +from src.common import config def test_create_config(test_config_file): @@ -45,7 +45,7 @@ def test_convert_config(): def test_on_change_tray_toggle(): """Tests the on_change_tray_toggle function""" - from pyra import tray_icon + from src.common import tray_icon if not tray_icon.icon_supported: pytest.skip("tray icon not supported") diff --git a/tests/unit/test_definitions.py b/tests/unit/test_definitions.py index d8cab3870..91e313584 100644 --- a/tests/unit/test_definitions.py +++ b/tests/unit/test_definitions.py @@ -2,10 +2,10 @@ .. test_definitions.py -Unit tests for pyra.definitions.py. +Unit tests for src.common.definitions.py. """ # local imports -from pyra import definitions +from src.common import definitions def test_names(): @@ -52,7 +52,8 @@ def test_paths(): """Tests Paths class""" paths = definitions.Paths - assert paths.PYRA_DIR + assert paths.COMMON_DIR + assert paths.SRC_DIR assert paths.ROOT_DIR assert paths.DATA_DIR assert paths.BINARY_PATH diff --git a/tests/unit/test_hardware.py b/tests/unit/test_hardware.py index 83d41b382..34c23d394 100644 --- a/tests/unit/test_hardware.py +++ b/tests/unit/test_hardware.py @@ -2,13 +2,13 @@ .. test_hardware.py -Unit tests for pyra.hardware.py. +Unit tests for src.common.hardware.py. """ # lib imports import pytest # local imports -from pyra import hardware +from src.common import hardware def test_update(): diff --git a/tests/unit/test_helpers.py b/tests/unit/test_helpers.py index 86d2b60bc..8d481ec11 100644 --- a/tests/unit/test_helpers.py +++ b/tests/unit/test_helpers.py @@ -9,7 +9,7 @@ import logging # local imports -from pyra import helpers +from src.common import helpers def test_check_folder_writeable(): @@ -22,7 +22,7 @@ def test_check_folder_writeable(): def test_get_logger(): """Test that logger object can be created""" - test_logger = helpers.get_logger(name='pyra') + test_logger = helpers.get_logger(name='common') assert isinstance(test_logger, logging.Logger) diff --git a/tests/unit/test_init.py b/tests/unit/test_init.py index 69ae5f979..993a95b6e 100644 --- a/tests/unit/test_init.py +++ b/tests/unit/test_init.py @@ -2,15 +2,15 @@ .. test_init.py -Unit tests for pyra.__init__.py. +Unit tests for src.common.__init__.py. """ import pytest -def test_initialize(test_pyra_init): +def test_initialize(test_common_init): """Tests initializing retroarcher""" - print(test_pyra_init) - assert test_pyra_init + print(test_common_init) + assert test_common_init @pytest.mark.skip(reason="impossible to test as it has a sys.exit() event and won't actually return") diff --git a/tests/unit/test_locales.py b/tests/unit/test_locales.py index e150018f5..bf76359a1 100644 --- a/tests/unit/test_locales.py +++ b/tests/unit/test_locales.py @@ -2,13 +2,13 @@ .. test_locales.py -Unit tests for pyra.locales.py. +Unit tests for src.common.locales.py. """ # standard imports import inspect # local imports -from pyra import locales +from src.common import locales def test_get_all_locales(): diff --git a/tests/unit/test_logger.py b/tests/unit/test_logger.py index b9834448c..85e06590b 100644 --- a/tests/unit/test_logger.py +++ b/tests/unit/test_logger.py @@ -2,13 +2,13 @@ .. test_logger.py -Unit tests for pyra.logger.py. +Unit tests for src.common.logger.py. """ # standard imports import logging # local imports -from pyra import logger +from src.common import logger def test_blacklist_config(): @@ -33,7 +33,7 @@ def test_init_multiprocessing(): def test_get_logger(): """Test that logger object can be created""" - log = logger.get_logger(name='pyra') + log = logger.get_logger(name='common') assert isinstance(log, logging.Logger) @@ -44,7 +44,7 @@ def test_setup_loggers(): def test_init_logger(): """Test that logger can be initialized""" - log = logger.init_logger(log_name='pyra') + log = logger.init_logger(log_name='common') assert isinstance(log, logging.Logger) diff --git a/tests/unit/test_threads.py b/tests/unit/test_threads.py index 6adf05afa..fb1831d0b 100644 --- a/tests/unit/test_threads.py +++ b/tests/unit/test_threads.py @@ -2,10 +2,10 @@ .. test_threads.py -Unit tests for pyra.threads. +Unit tests for src.common.threads. """ # local imports -from pyra import threads +from src.common import threads def test_run_in_thread(): diff --git a/tests/unit/test_tray_icon.py b/tests/unit/test_tray_icon.py index 22124b671..314cc4224 100644 --- a/tests/unit/test_tray_icon.py +++ b/tests/unit/test_tray_icon.py @@ -2,7 +2,7 @@ .. test_tray_icon.py -Unit tests for pyra.tray_icon. +Unit tests for src.common.tray_icon. """ # standard imports import time @@ -11,8 +11,8 @@ import pytest # local imports -import pyra -from pyra import tray_icon +import src.common +from src.common import tray_icon @pytest.fixture(scope='function') @@ -118,7 +118,7 @@ def test_tray_quit(): """Test tray_quit function""" tray_icon.tray_quit() - signal = pyra.SIGNAL + signal = src.common.SIGNAL assert signal == 'shutdown' @@ -127,7 +127,7 @@ def test_tray_restart(): """Test tray_restart function""" tray_icon.tray_restart() - signal = pyra.SIGNAL + signal = src.common.SIGNAL assert signal == 'restart' diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py index f28952ab2..9e3235ea0 100644 --- a/tests/unit/test_webapp.py +++ b/tests/unit/test_webapp.py @@ -2,14 +2,14 @@ .. test_webapp.py -Unit tests for pyra.webapp. +Unit tests for src.common.webapp. """ # standard imports import sys # local imports -from pyra import threads -from pyra import webapp +from src.common import threads +from src.common import webapp def test_start_webapp():