-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from jeremiah-k/plugins-path-fixes
Add get_app_path() function
- Loading branch information
Showing
2 changed files
with
26 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,24 @@ | ||
import yaml | ||
from yaml.loader import SafeLoader | ||
import sys | ||
import os | ||
|
||
def get_app_path(): | ||
""" | ||
Returns the base directory of the application, whether running from source or as an executable. | ||
""" | ||
if getattr(sys, 'frozen', False): | ||
# Running in a bundle (PyInstaller) | ||
return os.path.dirname(sys.executable) | ||
else: | ||
# Running in a normal Python environment | ||
return os.path.dirname(os.path.abspath(__file__)) | ||
|
||
relay_config = {} | ||
with open("config.yaml", "r") as f: | ||
relay_config = yaml.load(f, Loader=SafeLoader) | ||
config_path = os.path.join(get_app_path(), "config.yaml") | ||
|
||
if not os.path.isfile(config_path): | ||
print(f"Configuration file not found: {config_path}") | ||
else: | ||
with open(config_path, "r") as f: | ||
relay_config = yaml.load(f, Loader=SafeLoader) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters