Skip to content

Commit

Permalink
Setup changes (#1748)
Browse files Browse the repository at this point in the history
* Converting to ravenframework

* Fix pluginhandler.

* Making pyDOE use relative imports.

* Adding __init__.py so lazy is found.

* pyDOE now really in contrib.

* Make checking libraries optional.

* Updating for raven package.

* Fixing library_report.

* There was both a CodeInterfaces directory and a CodeInterfaces.py This caused problems.

* Support python 2.0 for utils.

* Skip library check if library handler not found.

* Adds ability to generate setup.cfg requirements section.

Usage:
python3 ./scripts/library_handler.py pip --action=setup.cfg > setup.cfg

* Updating things from review.
  • Loading branch information
joshua-cogliati-inl authored May 20, 2022
1 parent da6ee23 commit ab26984
Show file tree
Hide file tree
Showing 78 changed files with 56 additions and 41 deletions.
Empty file.
Empty file.
4 changes: 2 additions & 2 deletions ravenframework/CodeInterfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@author: alfoa
comment: The CodeInterface Module is an Handler.
It inquires all the modules contained in the folder './CodeInterfaces'
It inquires all the modules contained in the folder './CodeInterfaceClasses'
and load them, constructing a '__interFaceDict' on the fly
"""
#for future compatibility with Python 3--------------------------------------------------------------
Expand All @@ -36,7 +36,7 @@
#Internal Modules End--------------------------------------------------------------------------------

__moduleInterfaceList = []
startDir = os.path.join(os.path.dirname(__file__),'CodeInterfaces')
startDir = os.path.join(os.path.dirname(__file__),'CodeInterfaceClasses')
for dirr,_,_ in os.walk(startDir):
__moduleInterfaceList.extend(glob(os.path.join(dirr,"*.py")))
utils.add_path(dirr)
Expand Down
18 changes: 11 additions & 7 deletions ravenframework/CustomDrivers/DriverUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
# ***********************************************
# main utilities
#
def doSetup():
def doSetup(checkLibraries=True):
"""
Fully sets up RAVEN environment and variables.
@ In, None
@ In,checkLibraries, bool, if true check the library versions
@ Out, None
"""
printStatement()
Expand All @@ -34,7 +34,8 @@ def doSetup():
setupFramework()
setupH5py()
setupCpp()
checkVersions()
if checkLibraries:
checkVersions()

def findFramework():
"""
Expand Down Expand Up @@ -102,10 +103,9 @@ def setupCpp():
from ravenframework.utils import utils
utils.find_crow(frameworkDir)

if any(os.path.normcase(sp) == os.path.join(frameworkDir,'contrib') for sp in sys.path):
print(f'WARNING: "{os.path.join(frameworkDir,"contrib")}" already in system path. Skipping CPP setup')
if any(os.path.normcase(sp) == os.path.join(frameworkDir,'contrib', 'pp') for sp in sys.path):
print(f'WARNING: "{os.path.join(frameworkDir,"contrib", "pp")}" already in system path. Skipping CPP setup')
else:
utils.add_path(os.path.join(frameworkDir,'contrib'))
##TODO REMOVE PP3 WHEN RAY IS AVAILABLE FOR WINDOWS
utils.add_path_recursively(os.path.join(frameworkDir,'contrib','pp'))

Expand All @@ -124,7 +124,11 @@ def checkVersions():
sys.path.append(scriptDir)
else:
remove = False
import library_handler as LH
try:
import library_handler as LH
except ModuleNotFoundError:
print("ERROR: Unable to check library versions because library_handler not found")
return
if remove:
sys.path.pop(sys.path.index(scriptDir))
# if libraries are not to be checked, we're done here
Expand Down
2 changes: 1 addition & 1 deletion ravenframework/Driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main(checkLibraries):
@ Out, None
"""
# This is the default driver for the RAVEN framework
dutils.doSetup()
dutils.doSetup(checkLibraries)
from .Simulation import Simulation
from .Application import __QtAvailable
from .Interaction import Interaction
Expand Down
2 changes: 1 addition & 1 deletion ravenframework/Samplers/FactorialDesign.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#Internal Modules------------------------------------------------------------------------------------
from .Grid import Grid
import pyDOE as doe
from ..contrib import pyDOE as doe
from ..utils import InputData, InputTypes
#Internal Modules End--------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion ravenframework/Samplers/ResponseSurfaceDesign.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#Internal Modules------------------------------------------------------------------------------------
from .Grid import Grid
import pyDOE as doe
from ..contrib import pyDOE as doe
from ..utils import InputData, InputTypes
#Internal Modules End--------------------------------------------------------------------------------

Expand Down
5 changes: 4 additions & 1 deletion ravenframework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
@author: maljdp
"""

from .CustomDrivers.PythonRaven import Raven # allows from ravenframework import Raven
import sys
if sys.version_info[0] > 2:
from .CustomDrivers.PythonRaven import Raven # allows from ravenframework import Raven


# This file is necessary so that the sub-modules understand the correct hierarchy
# of things. Once everything is in sub-modules we can possibly do some things
Expand Down
Empty file.
Empty file.
16 changes: 8 additions & 8 deletions ravenframework/contrib/pyDOE/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
__author__ = 'Abraham Lee'
__version__ = '0.3.6'

from pyDOE.doe_box_behnken import *
from pyDOE.doe_composite import *
from pyDOE.doe_factorial import *
from pyDOE.doe_lhs import *
from pyDOE.doe_fold import *
from pyDOE.doe_plackett_burman import *
from pyDOE.var_regression_matrix import *
from .doe_box_behnken import *
from .doe_composite import *
from .doe_factorial import *
from .doe_lhs import *
from .doe_fold import *
from .doe_plackett_burman import *
from .var_regression_matrix import *
4 changes: 2 additions & 2 deletions ravenframework/contrib/pyDOE/doe_box_behnken.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"""

import numpy as np
from pyDOE.doe_factorial import ff2n
from pyDOE.doe_repeat_center import repeat_center
from .doe_factorial import ff2n
from .doe_repeat_center import repeat_center

__all__ = ['bbdesign']

Expand Down
8 changes: 4 additions & 4 deletions ravenframework/contrib/pyDOE/doe_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"""

import numpy as np
from pyDOE.doe_factorial import ff2n
from pyDOE.doe_star import star
from pyDOE.doe_union import union
from pyDOE.doe_repeat_center import repeat_center
from .doe_factorial import ff2n
from .doe_star import star
from .doe_union import union
from .doe_repeat_center import repeat_center

__all__ = ['ccdesign']

Expand Down
12 changes: 5 additions & 7 deletions scripts/TestHarness/testers/UnorderedCSVDiffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@

from Tester import Differ

# get access to math tools from RAVEN
try:
from ravenframework.utils import mathUtils
except ImportError:
new = os.path.realpath(os.path.join(os.path.realpath(__file__), '..', '..',
'..', '..'))
new = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..', '..'))
if new not in sys.path:
sys.path.append(new)
from ravenframework.utils import mathUtils

# get access to math tools from RAVEN
from ravenframework.utils import mathUtils

whoAmI = False # enable to show test dir and out files
debug = False # enable to increase printing
Expand Down
15 changes: 12 additions & 3 deletions scripts/library_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,10 @@ def _readDependencies(initFile):
help='Use subset of installation libraries, divided by source.')

pipParser = subParsers.add_parser('pip', help='use pip as installer')
pipParser.add_argument('--action', dest='action', choices=('install', 'list'), default='install',
pipParser.add_argument('--action', dest='action', choices=('install', 'list', 'setup.cfg'), default='install',
help='Chooses whether to (install) in current environment, or ' +
'(list) installation libraries.')
'(list) installation libraries or ' +
'(setup.cfg) output setup.cfg requirements.')

manualParser = subParsers.add_parser('manual', help='provide LaTeX manual list')

Expand Down Expand Up @@ -574,6 +575,7 @@ def _readDependencies(initFile):
raise IOError('During library installation, the following requested plugin libraries '+
' were not found: {}'.format(', '.join(missing)))

itemSeperator = ' '
### Il Grande Albero Decisionale
# "optional" and "os" are passed through
if args.installer == 'manual':
Expand Down Expand Up @@ -638,9 +640,16 @@ def _readDependencies(initFile):
elif args.action == 'list':
action = 'list'
preamble = ''
if args.action == 'setup.cfg':
action = 'setup.cfg'
preamble = """#setup.cfg from library_handler.py
[options]
install_requires =
"""
itemSeperator = '\n '

preamble = preamble.format(installer=installer, action=action, args=actionArgs)
libTexts = ' '.join(['{lib}{extra}{ver}'
libTexts = itemSeperator.join(['{lib}{extra}{ver}'
.format(lib=lib,
extra=request['pip_extra'] if installer.startswith('pip') and 'pip_extra' in request else '',
ver=('{e}{r}{et}'.format(e=equals, r=request['version'], et=equalsTail) if request['version'] is not None else ''))
Expand Down
2 changes: 1 addition & 1 deletion scripts/library_report
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ except:

sys.path.append(os.path.join(RAVEN_DIR, "scripts"))
import library_handler
from utils import utils
from ravenframework.utils import utils

report_list = library_handler.checkLibraries(buildReport=True)
amsc_report = library_handler.checkSingleLibrary('AMSC', useImportCheck=True)
Expand Down
7 changes: 4 additions & 3 deletions scripts/plugin_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import sys
import time
import argparse
frameworkDir = os.path.join(os.path.dirname(__file__), '..', 'ravenframework')
sys.path.append(frameworkDir)
from utils import xmlUtils
ravenDir = os.path.dirname(os.path.dirname(__file__))
sys.path.append(ravenDir)
frameworkDir = os.path.join(ravenDir, 'ravenframework')
from ravenframework.utils import xmlUtils

# python changed the import error in 3.6
if sys.version_info[0] == 3 and sys.version_info[1] >= 6:
Expand Down

0 comments on commit ab26984

Please sign in to comment.