Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
refactor: restructure source code
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher committed Aug 9, 2024
1 parent 01d4d90 commit 121ebe7
Show file tree
Hide file tree
Showing 49 changed files with 228 additions and 217 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
--tb=native \
--verbose \
--color=yes \
--cov=pyra \
--cov=src \
tests
- name: Upload coverage
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ cython_debug/
node_modules/
*package-lock.json

# RetroArcher directories
# project files and directories
logs/

# RetroArcher files
*config.ini
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 -----------------------------------------------------
Expand Down
5 changes: 2 additions & 3 deletions docs/source/contributing/localization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 0 additions & 7 deletions docs/source/pyra_docs/config.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/source/pyra_docs/hardware.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/source/pyra_docs/helpers.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/source/pyra_docs/locales.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/source/pyra_docs/logger.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/source/pyra_docs/threads.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/source/pyra_docs/webapp.rst

This file was deleted.

7 changes: 7 additions & 0 deletions docs/source/src/common/common.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. include:: ../global.rst

:modname:`common.__init__`
--------------------------
.. automodule:: common
:members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. include:: ../global.rst

:modname:`pyra.__init__`
:modname:`common.config`
------------------------
.. automodule:: pyra
.. automodule:: common.config
:members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/src/common/definitions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. include:: ../global.rst

:modname:`common.definitions`
-----------------------------
.. automodule:: common.definitions
:members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/src/common/hardware.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. include:: ../global.rst

:modname:`common.hardware`
--------------------------
.. automodule:: common.hardware
:members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. include:: ../global.rst

:modname:`pyra.tray_icon`
:modname:`common.helpers`
-------------------------
.. automodule:: pyra.tray_icon
.. automodule:: common.helpers
:members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/src/common/locales.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. include:: ../global.rst

:modname:`common.locales`
-------------------------
.. automodule:: common.locales
:members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/src/common/logger.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. include:: ../global.rst

:modname:`common.logger`
------------------------
.. automodule:: common.logger
:members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/src/common/threads.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. include:: ../global.rst

:modname:`common.threads`
-------------------------
.. automodule:: common.threads
:members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. include:: ../global.rst

:modname:`pyra.definitions`
:modname:`common.tray_icon`
---------------------------
.. automodule:: pyra.definitions
.. automodule:: common.tray_icon
:members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/src/common/webapp.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.. include:: ../global.rst

:modname:`common.webapp`
------------------------
.. automodule:: common.webapp
:members:
:show-inheritance:
File renamed without changes.
22 changes: 11 additions & 11 deletions docs/source/toc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=./',
Expand Down
Empty file added src/__init__.py
Empty file.
10 changes: 5 additions & 5 deletions pyra/__init__.py → src/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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

Check warning on line 124 in src/common/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/common/__init__.py#L124

Added line #L124 was not covered by tests
try:
tray_end()
except AttributeError:
Expand Down
10 changes: 5 additions & 5 deletions pyra/config.py → src/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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()


Expand Down
13 changes: 8 additions & 5 deletions pyra/definitions.py → src/common/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'))

Expand Down
10 changes: 5 additions & 5 deletions pyra/hardware.py → src/common/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
--------
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions pyra/locales.py → src/common/locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading

0 comments on commit 121ebe7

Please sign in to comment.