Skip to content

Commit

Permalink
Dciborow/update config (#15)
Browse files Browse the repository at this point in the history
* Trying to figure out where the other PR went wrong....

* Trying to figure out where the other PR went wrong....

* Trying to figure out where the other PR went wrong....
  • Loading branch information
dciborow committed Feb 24, 2020
1 parent 6ece717 commit f2c7862
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
22 changes: 22 additions & 0 deletions 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
Expand Down
7 changes: 4 additions & 3 deletions azure_utils/configuration/notebook_config.py
Expand Up @@ -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):
Expand Down
39 changes: 37 additions & 2 deletions azure_utils/configuration/project_configuration.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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
4 changes: 1 addition & 3 deletions environment.yml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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']
)

0 comments on commit f2c7862

Please sign in to comment.