-
-
Notifications
You must be signed in to change notification settings - Fork 6
It's easier to manage vars through dotenv #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,6 +32,8 @@ | |||||||||
| import ast | ||||||||||
| import argparse | ||||||||||
| import hashlib | ||||||||||
|
|
||||||||||
| from dotenv import load_dotenv | ||||||||||
| from prettytable import PrettyTable | ||||||||||
| from tqdm import tqdm as tqdm | ||||||||||
| from typing import List, Tuple | ||||||||||
|
|
@@ -390,6 +392,8 @@ def convert_bytes(size): | |||||||||
| if not overwrite: | ||||||||||
| # Remove the existing files from the list of files to copy | ||||||||||
| files_to_copy = [f for f in files_to_copy if f not in existing_files] | ||||||||||
| else: | ||||||||||
| overwrite = False | ||||||||||
|
|
||||||||||
| if not files_to_copy: | ||||||||||
| print("No files to copy. Exiting copy operation.") | ||||||||||
|
|
@@ -746,11 +750,14 @@ def main() -> None: | |||||||||
| "external caches, respectively.]]") | ||||||||||
| # define the default source directories (no training delimiter) | ||||||||||
| # points to path of internal "modules" directory | ||||||||||
| load_dotenv() | ||||||||||
| global ollama_int_dir | ||||||||||
| ollama_int_dir = os.getenv("OLLAMAUTIL_INTERNAL_DIR") | ||||||||||
| # points to path of external "modules" directory | ||||||||||
| global ollama_ext_dir | ||||||||||
| ollama_ext_dir = os.getenv("OLLAMAUTIL_EXTERNAL_DIR") | ||||||||||
| if ollama_int_dir is None or ollama_ext_dir is None: | ||||||||||
| raise Exception("Ollamautil internal and external directories not set.") | ||||||||||
|
Comment on lines
+759
to
+760
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check is a good addition, but it can be improved. The check Furthermore, the same logic for loading and checking environment variables is duplicated in I'd suggest replacing this check with the one below, and removing the redundant one at lines 773-779.
Suggested change
|
||||||||||
| global valid_caches | ||||||||||
| valid_caches = [ | ||||||||||
| ('internal', ollama_int_dir), | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| python-dotenv | ||
| argparse==1.4.0 | ||
| ollama==0.1.8 | ||
| prettytable==3.10.0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| from .ollamautil import build_ext_int_comb_filelist, display_models_table, migrate_cache_user, toggle_int_ext_cache, remove_from_cache, pull_models, push_models | ||
| import os | ||
| import ast | ||
| from dotenv import load_dotenv | ||
|
|
||
| def main_menu(): | ||
| print("\n\033[1mMain Menu\033[0m") | ||
|
|
@@ -39,12 +40,15 @@ def process_choice(choice: str, combined, models_table: PrettyTable|None = None) | |
| print("Invalid choice, please try again.") | ||
|
|
||
| def main() -> None: | ||
| ''' | ||
| """ | ||
| Display main menu and basic high-level handling. | ||
| ''' | ||
| """ | ||
| # Set up environment variables | ||
| load_dotenv() | ||
| ollama_int_dir = os.getenv("OLLAMAUTIL_INTERNAL_DIR") | ||
| ollama_ext_dir = os.getenv("OLLAMAUTIL_EXTERNAL_DIR") | ||
| if ollama_int_dir is None or ollama_ext_dir is None: | ||
| raise Exception("Ollamautil internal and external directories not set.") | ||
|
Comment on lines
+50
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new check is redundant with the existing check on lines 58-62. The existing check is more robust as it also handles empty strings and provides a more informative error message before exiting with This logic is also duplicated in I recommend removing this new |
||
| try: | ||
| ollama_file_ignore = ast.literal_eval(os.getenv("OLLAMAUTIL_FILE_IGNORE", "['.DS_Store']")) | ||
| except: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
elseblock correctly fixes a potentialUnboundLocalErrorfor theoverwritevariable. A more common and arguably cleaner pattern is to initialize variables with a default value. Consider initializingoverwrite = Falsebefore theif existing_files:block on line 388 and removing thiselseblock. This makes the default value explicit and improves readability.