Skip to content

Commit 8581138

Browse files
ahokinsonAnders Hokinson
andauthored
OS Agnostic Paths (#18)
Co-authored-by: Anders Hokinson <anders@bumbasealpha.lan>
1 parent b740157 commit 8581138

11 files changed

Lines changed: 66 additions & 24 deletions

File tree

.run/Sierra.run.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Sierra" type="PythonConfigurationType" factoryName="Python">
3+
<module name="sierra" />
4+
<option name="ENV_FILES" value="" />
5+
<option name="INTERPRETER_OPTIONS" value="" />
6+
<option name="PARENT_ENVS" value="true" />
7+
<envs>
8+
<env name="PYTHONUNBUFFERED" value="1" />
9+
</envs>
10+
<option name="SDK_HOME" value="" />
11+
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
12+
<option name="IS_MODULE_SDK" value="true" />
13+
<option name="ADD_CONTENT_ROOTS" value="true" />
14+
<option name="ADD_SOURCE_ROOTS" value="true" />
15+
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
16+
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/sierra.py" />
17+
<option name="PARAMETERS" value="" />
18+
<option name="SHOW_COMMAND_LINE" value="false" />
19+
<option name="EMULATE_TERMINAL" value="false" />
20+
<option name="MODULE_MODE" value="false" />
21+
<option name="REDIRECT_INPUT" value="false" />
22+
<option name="INPUT_FILE" value="" />
23+
<method v="2" />
24+
</configuration>
25+
</component>

ai/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from enum import Enum
22
from importlib import import_module
33
from glob import glob
4+
from os import path
45
from os.path import isdir
56

67

@@ -17,9 +18,9 @@ class Role(Enum):
1718

1819

1920
modules = {}
20-
for ai_glob in glob("ai/*"):
21+
for ai_glob in glob(path.join('ai', '*')):
2122
if isdir(ai_glob):
22-
modules[ai_glob.split('/')[-1]] = import_module(ai_glob.replace('/', '.'))
23+
modules[path.split(ai_glob)[-1]] = import_module('.'.join(path.split(ai_glob)))
2324

2425

2526
def load(name, function):

ai/elevenlabs/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from os import path
12
import elevenlabs
23

34
from settings.secrets import Secrets
45
from settings.settings import Settings
56

6-
secrets = Secrets('ai/elevenlabs/secrets.yaml')
7-
settings = Settings('ai/elevenlabs/settings.yaml')
7+
secrets = Secrets(path.join(*__name__.split('.'), 'secrets.yaml'))
8+
settings = Settings(path.join(*__name__.split('.'), 'settings.yaml'))
89
elevenlabs.set_api_key(secrets.get('api_key'))
910

1011

ai/open_ai/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from os import path
12
from time import sleep
23

34
# noinspection PyPackageRequirements
@@ -27,8 +28,8 @@
2728
from settings import sierra_settings
2829
from utils.logging import log
2930

30-
secrets = Secrets('ai/open_ai/secrets.yaml')
31-
settings = Settings('ai/open_ai/settings.yaml')
31+
secrets = Secrets(path.join(*__name__.split('.'), 'secrets.yaml'))
32+
settings = Settings(path.join(*__name__.split('.'), 'settings.yaml'))
3233

3334

3435
class Chat:

ai/play_ht/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from os import path
2+
13
import requests
24

35
from settings.secrets import Secrets
@@ -75,5 +77,5 @@ def __init__(self, message, errors):
7577
self.errors = errors
7678

7779

78-
secrets = Secrets('ai/play_ht/secrets.yaml')
79-
settings = Settings('ai/play_ht/settings.yaml')
80+
secrets = Secrets(path.join(*__name__.split('.'), 'secrets.yaml'))
81+
settings = Settings(path.join(*__name__.split('.'), 'settings.yaml'))

input/keyboard/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
from os import path
23

34
from yaml import safe_load
45

@@ -21,7 +22,7 @@ def collect(self):
2122

2223
class InputSettings:
2324
def __init__(self):
24-
with open('input/keyboard/config.yaml', 'r') as file:
25+
with open(path.join(*__name__.split('.'), 'config.yaml'), 'r') as file:
2526
self._raw = safe_load(file)
2627
self.characters = self._raw.get('characters', [])
2728

input/microphone/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import time
33
import wave
4+
from os import path
45

56
import pyaudio
67
from pynput import keyboard
@@ -79,8 +80,8 @@ def on_release(self, key: keyboard.Key | keyboard.KeyCode):
7980
def collect(self):
8081
while True:
8182
log.info('\ninput.py: Press binds to record.')
82-
self.record('temp/input.wav')
83-
prompt = ai.load(settings.transcribe.module, ai.Function.TRANSCRIBE)().send('temp/input.wav')['text']
83+
self.record(path.join(*['temp', 'input.wav']))
84+
prompt = ai.load(settings.transcribe.module, ai.Function.TRANSCRIBE)().send(path.join(*['temp', 'input.wav']))['text']
8485

8586
chat.submit(prompt, self.recording.character)
8687
log.info(f'Whisper: Transcribed: {prompt}')
@@ -93,7 +94,7 @@ def __init__(self):
9394

9495
class InputSettings:
9596
def __init__(self):
96-
with open('input/microphone/config.yaml', 'r') as file:
97+
with open(path.join(*__name__.split('.'), 'config.yaml'), 'r') as file:
9798
self._raw = safe_load(file)
9899
self.audio = Audio(self._raw.get('audio', {}))
99100
self.binds = {bind.vk: bind for bind in [Bind(bind) for bind in self._raw.get('binds', [])]}

input/twitch/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
from enum import Enum
3+
from os import path
34

45
from yaml import safe_load
56

@@ -36,7 +37,7 @@ async def collect(self):
3637

3738
class InputSettings:
3839
def __init__(self):
39-
with open('input/twitch/secrets.yaml', 'r') as file:
40+
with open(path.join(*[*__name__.split('.'), 'secrets.yaml']), 'r') as file:
4041
yaml = safe_load(file)
4142
self.secrets = {
4243
ClientType.LISTENER: Secrets(yaml.get('listener')),

input/twitch/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
twitchAPI

play/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from glob import glob
2+
from os import path
23

34
from yaml import safe_load
45

@@ -11,9 +12,9 @@ class Play:
1112
@staticmethod
1213
def characters():
1314
characters = {}
14-
for character_glob in glob("play/characters/*"):
15+
for character_glob in glob(path.join('play', 'characters', '*')):
1516
try:
16-
with open(f'{character_glob}/character.yaml', "r") as character_yaml:
17+
with open(path.join(character_glob, 'character.yaml'), 'r') as character_yaml:
1718
c = Character(character_glob, safe_load(character_yaml))
1819
characters[c.name] = c
1920
except FileNotFoundError:
@@ -23,8 +24,8 @@ def characters():
2324
@staticmethod
2425
def tasks():
2526
tasks = {}
26-
for task_glob in glob("play/tasks/*.yaml"):
27-
with open(task_glob, "r") as task_yaml:
27+
for task_glob in glob(path.join('play', 'tasks', '*.yaml')):
28+
with open(task_glob, 'r') as task_yaml:
2829
t = Task(safe_load(task_yaml))
2930
tasks[t.name] = t
3031
return tasks

0 commit comments

Comments
 (0)