Skip to content

Commit

Permalink
refactor: rename user_function_parser
Browse files Browse the repository at this point in the history
  • Loading branch information
rzyu45 committed Nov 21, 2024
1 parent ca90646 commit 9d4c176
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Solverz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from Solverz.utilities.profile import count_time
from Solverz.variable.ssymbol import Var, AliasVar
from Solverz.model.basic import Model
from Solverz.num_api.user_function_parser import save_module_paths, reset_module_paths
from Solverz.num_api.user_function_parser import add_my_module, reset_my_module_paths

from importlib.metadata import version, PackageNotFoundError

Expand Down
4 changes: 2 additions & 2 deletions Solverz/num_api/module_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
warnings.warn(f'Failed to import num api from SolMuseum: {e}')

# parse user defined functions
from .user_function_parser import load_module_paths
from .user_function_parser import load_my_module_paths

user_module_paths = load_module_paths()
user_module_paths = load_my_module_paths()
if user_module_paths:
print('User module detected.')
import os, sys
Expand Down
8 changes: 3 additions & 5 deletions Solverz/num_api/user_function_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
from pathlib import Path
import sys
import importlib.util


def validate_module_paths(paths):
Expand Down Expand Up @@ -32,7 +30,7 @@ def validate_module_paths(paths):
return valid_paths


def save_module_paths(paths, filename='user_modules.txt'):
def add_my_module(paths, filename='user_modules.txt'):
"""
Save user-provided module paths to a specified file, but validate the paths before saving.
If a path already exists in the file, it will not be added again.
Expand Down Expand Up @@ -72,7 +70,7 @@ def save_module_paths(paths, filename='user_modules.txt'):
existing_paths.add(path)


def load_module_paths(filename='user_modules.txt'):
def load_my_module_paths(filename='user_modules.txt'):
"""
Load module paths from a specified file in the .Solverz directory in the user's home directory.
Expand All @@ -94,7 +92,7 @@ def load_module_paths(filename='user_modules.txt'):
return paths


def reset_module_paths(filename='user_modules.txt'):
def reset_my_module_paths(filename='user_modules.txt'):
"""
Reset the user_modules.txt file by clearing its content.
Expand Down

0 comments on commit 9d4c176

Please sign in to comment.