diff --git a/README.md b/README.md index f038091..58ce3f2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,28 @@ # AI Utilities Sample Project This project is a sample showcasing how to create a common repository for utilities that can be used by other AI projects. +# Working with Project +## Build Project + +```bash +python setup.py install +``` + +```bash +pip install -e azure_utils +``` + +## Run Unit Tests with Conda +```bash +conda env create -f environment.yml +conda activate ai-utilities +python -m ipykernal install --prefix=[anaconda-root-dir]\envs\ai-utilities --name ai-utilities +pytest tests +``` + +Example Anaconda Root Dir +C:\Users\dcibo\Anaconda3 + # Contributing This project welcomes contributions and suggestions. Most contributions require you to agree to a diff --git a/azure_utils/configuration/notebook_config.py b/azure_utils/configuration/notebook_config.py index 41b953a..a9785c1 100644 --- a/azure_utils/configuration/notebook_config.py +++ b/azure_utils/configuration/notebook_config.py @@ -13,12 +13,13 @@ tkinter based UI that dynamically loads any appropriate configuration file and displays it to the user to alter the settings. """ -from azure_utils import DIRECTORY + +from tkinter import * + from azure_utils.configuration.configuration_ui import SettingsUpdate from azure_utils.configuration.project_configuration import ProjectConfiguration -from tkinter import * -project_configuration_file = DIRECTORY.replace("azure_utils", "project.yml") +project_configuration_file = "project.yml" def configure_settings(configuration_yaml: str = project_configuration_file): diff --git a/azure_utils/configuration/project_configuration.py b/azure_utils/configuration/project_configuration.py index bf22705..3ebaa47 100644 --- a/azure_utils/configuration/project_configuration.py +++ b/azure_utils/configuration/project_configuration.py @@ -38,10 +38,11 @@ def __init__(self, configuration_file: str): :param configuration_file: File path to configuration file """ - self.configuration_file = configuration_file + found, file_dir = find_file(configuration_file) + self.configuration_file = file_dir + "/" + configuration_file self.configuration = {} - if not os.path.isfile(self.configuration_file): + if not found: self.configuration = {ProjectConfiguration.project_key: "Default Settings", ProjectConfiguration.settings_key: None} self.save_configuration() @@ -171,3 +172,37 @@ def save_configuration(self): """ Save the configuration file """ with open(self.configuration_file, 'w') as ymlfile: yaml.dump(self.configuration, ymlfile) + + +def transverse_up(file: str, search_depth: int = 5): + """ + Check if file is in directory, and if not recursive call up to 5 times + + :param file: Configuration File Name + :param search_depth: Number of directories to search up through + """ + + if search_depth == 0: + return False + if not os.path.isfile(file): + os.chdir("../") + transverse_up(file, search_depth=search_depth - 1) + if os.path.isfile(file): + return True + return False + + +def find_file(file: str): + """ + Transverse up directories to try and find configuration file + + :param file: Configuration File Name + """ + curdir = os.path.abspath(os.curdir) + found = transverse_up(file) + if found: + file_dir = os.path.abspath(os.curdir) + else: + file_dir = curdir + os.chdir(curdir) + return found, file_dir diff --git a/environment.yml b/environment.yml index c6124ae..8972709 100644 --- a/environment.yml +++ b/environment.yml @@ -14,9 +14,7 @@ dependencies: - numpy - pip: - papermill - - azureml-core==1.0.85. - - azure-core - - azure-cli + - azureml-core==1.0.85 - pylint-junit - pytest-nunit - nbconvert diff --git a/setup.py b/setup.py index a2c7496..5029c42 100644 --- a/setup.py +++ b/setup.py @@ -16,5 +16,5 @@ license="MIT", packages=find_packages(), install_requires=['azureml-core', 'python-dotenv', 'nbformat', 'papermill', 'nbconvert', 'junit_xml', 'PyYAML', - 'pytest', 'lightgbm==2.1.2', 'azure-core', 'azure-cli'] + 'pytest', 'lightgbm==2.1.2'] )