"...targets/git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "cd1357effa4fba927059d07233cf6f91535462ea"
Unverified Commit f98ee672 authored by liuzhe-lz's avatar liuzhe-lz Committed by GitHub
Browse files

[v2.0] Refactor code hierarchy (part 1) (#2962)

parent f1105409
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
Example: Example:
from nnicli import Experiment from nni.nnicli import Experiment
exp = Experiment() exp = Experiment()
exp.start_experiment('../../../../examples/trials/mnist-pytorch/config.yml') exp.start_experiment('../../../../examples/trials/mnist-pytorch/config.yml')
......
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
# Licensed under the MIT license. # Licensed under the MIT license.
import os import os
import site from pathlib import Path
import sys import sys
from collections import defaultdict from collections import defaultdict
from pathlib import Path from pathlib import Path
import importlib import importlib
import ruamel.yaml as yaml import ruamel.yaml as yaml
import nni
from .constants import BuiltinAlgorithms from .constants import BuiltinAlgorithms
ALGO_TYPES = ['tuners', 'assessors', 'advisors'] ALGO_TYPES = ['tuners', 'assessors', 'advisors']
...@@ -286,50 +287,9 @@ def create_customized_class_instance(class_params): ...@@ -286,50 +287,9 @@ def create_customized_class_instance(class_params):
return instance return instance
def get_nni_installation_parent_dir():
''' Find nni installation parent directory
'''
if os.getenv('VIRTUAL_ENV'):
# if 'virtualenv' package is used, `site` has not attr getsitepackages, so we will instead use VIRTUAL_ENV
# Note that conda venv will not have VIRTUAL_ENV
python_dir = os.getenv('VIRTUAL_ENV')
else:
python_sitepackage = site.getsitepackages()[0]
# If system-wide python is used, we will give priority to using `local sitepackage`--"usersitepackages()" given
# that nni exists there
if python_sitepackage.startswith('/usr') or python_sitepackage.startswith('/Library'):
python_dir = _try_installation_path_sequentially(site.getusersitepackages(), *site.getsitepackages())
else:
python_dir = _try_installation_path_sequentially(*site.getsitepackages(), site.getusersitepackages())
return python_dir
def _try_installation_path_sequentially(*sitepackages):
'''Try different installation path sequentially util nni is found.
Return None if nothing is found
'''
for sitepackage in sitepackages:
path = Path(sitepackage)
if len(path.parents) > 2 and (path.parents[2] / 'nni' / 'main.js').is_file():
return str(path.parents[2])
if (path / 'nni' / 'main.js').is_file():
return str(path)
return None
def get_nni_installation_path():
''' Find nni installation directory
'''
parent_dir = get_nni_installation_parent_dir()
if parent_dir:
entry_file = os.path.join(parent_dir, 'nni', 'main.js')
if os.path.isfile(entry_file):
return os.path.join(parent_dir, 'nni')
return None
def get_nni_config_dir():
return os.path.join(get_nni_installation_path(), 'config')
def get_package_config_path(): def get_package_config_path():
config_dir = get_nni_config_dir() # FIXME: this might not be the desired location
config_dir = Path(nni.__path__[0]).parent / 'nni_config'
if not os.path.exists(config_dir): if not os.path.exists(config_dir):
os.makedirs(config_dir, exist_ok=True) os.makedirs(config_dir, exist_ok=True)
return os.path.join(config_dir, 'installed_packages.yml') return os.path.join(config_dir, 'installed_packages.yml')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment