mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Python: move examples, tests and generated inside rips folder so they are packaged in rips pip-package
This commit is contained in:
parent
fe268cd25f
commit
1d8a417e33
@ -110,16 +110,16 @@ foreach(proto_file ${PROTO_FILES})
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
if (PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
||||||
set(rips_proto_python "generated/${proto_file}_pb2.py")
|
set(rips_proto_python "rips/generated/${proto_file}_pb2.py")
|
||||||
set(rips_grpc_python "generated/${proto_file}_pb2_grpc.py")
|
set(rips_grpc_python "rips/generated/${proto_file}_pb2_grpc.py")
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT "${GRPC_PYTHON_SOURCE_PATH}/${rips_proto_python}" "${GRPC_PYTHON_SOURCE_PATH}/${rips_grpc_python}"
|
OUTPUT "${GRPC_PYTHON_SOURCE_PATH}/${rips_proto_python}" "${GRPC_PYTHON_SOURCE_PATH}/${rips_grpc_python}"
|
||||||
COMMAND ${PYTHON_EXECUTABLE}
|
COMMAND ${PYTHON_EXECUTABLE}
|
||||||
ARGS -m grpc_tools.protoc
|
ARGS -m grpc_tools.protoc
|
||||||
-I "${rips_proto_path}"
|
-I "${rips_proto_path}"
|
||||||
--python_out "${GRPC_PYTHON_SOURCE_PATH}/generated"
|
--python_out "${GRPC_PYTHON_SOURCE_PATH}/rips/generated"
|
||||||
--grpc_python_out "${GRPC_PYTHON_SOURCE_PATH}/generated"
|
--grpc_python_out "${GRPC_PYTHON_SOURCE_PATH}/rips/generated"
|
||||||
"${rips_proto}"
|
"${rips_proto}"
|
||||||
DEPENDS "${rips_proto}"
|
DEPENDS "${rips_proto}"
|
||||||
COMMENT "Generating ${rips_proto_python} and ${rips_grpc_python}"
|
COMMENT "Generating ${rips_proto_python} and ${rips_grpc_python}"
|
||||||
@ -147,7 +147,7 @@ endforeach(proto_file)
|
|||||||
if (PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
if (PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
||||||
list(APPEND GRPC_PYTHON_SOURCES
|
list(APPEND GRPC_PYTHON_SOURCES
|
||||||
${GRPC_PYTHON_GENERATED_SOURCES}
|
${GRPC_PYTHON_GENERATED_SOURCES}
|
||||||
"generated/RiaVersionInfo.py"
|
"rips/generated/RiaVersionInfo.py"
|
||||||
"rips/__init__.py"
|
"rips/__init__.py"
|
||||||
"rips/App.py"
|
"rips/App.py"
|
||||||
"rips/Case.py"
|
"rips/Case.py"
|
||||||
@ -156,25 +156,25 @@ if (PYTHON_EXECUTABLE AND EXISTS ${PYTHON_EXECUTABLE})
|
|||||||
"rips/Project.py"
|
"rips/Project.py"
|
||||||
"rips/Properties.py"
|
"rips/Properties.py"
|
||||||
"rips/Instance.py"
|
"rips/Instance.py"
|
||||||
"examples/CommandExample.py"
|
"rips/examples/CommandExample.py"
|
||||||
"examples/CaseInfoStreamingExample.py"
|
"rips/examples/CaseInfoStreamingExample.py"
|
||||||
"examples/SoilPorvAsync.py"
|
"rips/examples/SoilPorvAsync.py"
|
||||||
"examples/SoilPorvSync.py"
|
"rips/examples/SoilPorvSync.py"
|
||||||
"examples/SelectedCases.py"
|
"rips/examples/SelectedCases.py"
|
||||||
"examples/AllCases.py"
|
"rips/examples/AllCases.py"
|
||||||
"examples/SetGridProperties.py"
|
"rips/examples/SetGridProperties.py"
|
||||||
"examples/GridInformation.py"
|
"rips/examples/GridInformation.py"
|
||||||
"examples/InputPropTestSync.py"
|
"rips/examples/InputPropTestSync.py"
|
||||||
"examples/InputPropTestAsync.py"
|
"rips/examples/InputPropTestAsync.py"
|
||||||
"examples/SoilAverage.py"
|
"rips/examples/SoilAverage.py"
|
||||||
"examples/SoilAverageNoComm.py"
|
"rips/examples/SoilAverageNoComm.py"
|
||||||
"tests/test_cases.py"
|
"rips/tests/test_cases.py"
|
||||||
"tests/test_commands.py"
|
"rips/tests/test_commands.py"
|
||||||
"tests/test_grids.py"
|
"rips/tests/test_grids.py"
|
||||||
"tests/test_properties.py"
|
"rips/tests/test_properties.py"
|
||||||
"tests/test_project.py"
|
"rips/tests/test_project.py"
|
||||||
"tests/conftest.py"
|
"rips/tests/conftest.py"
|
||||||
"tests/dataroot.py"
|
"rips/tests/dataroot.py"
|
||||||
"requirements.txt"
|
"requirements.txt"
|
||||||
"setup.py.cmake"
|
"setup.py.cmake"
|
||||||
"README.md"
|
"README.md"
|
||||||
@ -194,7 +194,7 @@ list ( APPEND GRPC_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
|
|||||||
list ( APPEND GRPC_CPP_SOURCES ${SOURCE_GROUP_SOURCE_FILES})
|
list ( APPEND GRPC_CPP_SOURCES ${SOURCE_GROUP_SOURCE_FILES})
|
||||||
|
|
||||||
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RiaVersionInfo.py.cmake
|
CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/ApplicationCode/Adm/RiaVersionInfo.py.cmake
|
||||||
${GRPC_PYTHON_SOURCE_PATH}/generated/RiaVersionInfo.py
|
${GRPC_PYTHON_SOURCE_PATH}/rips/generated/RiaVersionInfo.py
|
||||||
)
|
)
|
||||||
CONFIGURE_FILE( ${GRPC_PYTHON_SOURCE_PATH}/setup.py.cmake
|
CONFIGURE_FILE( ${GRPC_PYTHON_SOURCE_PATH}/setup.py.cmake
|
||||||
${GRPC_PYTHON_SOURCE_PATH}/setup.py
|
${GRPC_PYTHON_SOURCE_PATH}/setup.py
|
||||||
|
@ -2,7 +2,7 @@ import grpc
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../generated'))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated'))
|
||||||
|
|
||||||
from Empty_pb2 import Empty
|
from Empty_pb2 import Empty
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import sys
|
|||||||
from .Grid import Grid
|
from .Grid import Grid
|
||||||
from .Properties import Properties
|
from .Properties import Properties
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../generated'))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated'))
|
||||||
|
|
||||||
import Case_pb2
|
import Case_pb2
|
||||||
import Case_pb2_grpc
|
import Case_pb2_grpc
|
||||||
|
@ -2,7 +2,7 @@ import grpc
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../generated'))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated'))
|
||||||
|
|
||||||
from Empty_pb2 import Empty
|
from Empty_pb2 import Empty
|
||||||
import Commands_pb2 as Cmd
|
import Commands_pb2 as Cmd
|
||||||
|
@ -2,7 +2,7 @@ import grpc
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../generated'))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated'))
|
||||||
|
|
||||||
import Grid_pb2
|
import Grid_pb2
|
||||||
import Grid_pb2_grpc
|
import Grid_pb2_grpc
|
||||||
|
@ -5,7 +5,7 @@ import socket
|
|||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../generated'))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated'))
|
||||||
|
|
||||||
import RiaVersionInfo
|
import RiaVersionInfo
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import sys
|
|||||||
from .Case import Case
|
from .Case import Case
|
||||||
from .Commands import Commands
|
from .Commands import Commands
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../generated'))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated'))
|
||||||
|
|
||||||
from Empty_pb2 import Empty
|
from Empty_pb2 import Empty
|
||||||
import Project_pb2
|
import Project_pb2
|
||||||
|
@ -2,7 +2,7 @@ import grpc
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../generated'))
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated'))
|
||||||
|
|
||||||
import Properties_pb2
|
import Properties_pb2
|
||||||
import Properties_pb2_grpc
|
import Properties_pb2_grpc
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
import grpc
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import socket
|
|
||||||
import logging
|
|
||||||
|
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '../generated'))
|
|
||||||
|
|
||||||
import RiaVersionInfo
|
|
||||||
|
|
||||||
from AppInfo import AppInfo
|
|
||||||
from Commands import Commands
|
|
||||||
from Project import Project
|
|
||||||
|
|
||||||
class Instance:
|
|
||||||
@staticmethod
|
|
||||||
def is_port_in_use(port):
|
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
||||||
s.settimeout(0.2)
|
|
||||||
return s.connect_ex(('localhost', port)) == 0
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def launch():
|
|
||||||
port = 50051
|
|
||||||
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
|
|
||||||
if portEnv:
|
|
||||||
port = int(portEnv)
|
|
||||||
|
|
||||||
resInsightExecutable = os.environ.get('RESINSIGHT_EXECUTABLE')
|
|
||||||
if resInsightExecutable is None:
|
|
||||||
print('Error: Could not launch any ResInsight instances because RESINSIGHT_EXECUTABLE is not set')
|
|
||||||
return None
|
|
||||||
|
|
||||||
while Instance.is_port_in_use(port):
|
|
||||||
port += 1
|
|
||||||
|
|
||||||
print('Port ' + str(port))
|
|
||||||
print('Trying to launch', resInsightExecutable)
|
|
||||||
pid = os.spawnl(os.P_NOWAIT, resInsightExecutable, " --grpcserver " + str(port))
|
|
||||||
print(pid)
|
|
||||||
return Instance(port)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def find(startPort = 50051, endPort = 50071):
|
|
||||||
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
|
|
||||||
if portEnv:
|
|
||||||
startPort = int(portEnv)
|
|
||||||
endPort = startPort + 20
|
|
||||||
|
|
||||||
for tryPort in range(startPort, endPort):
|
|
||||||
if Instance.is_port_in_use(tryPort):
|
|
||||||
return Instance(tryPort)
|
|
||||||
|
|
||||||
print('Error: Could not find any ResInsight instances responding between ports ' + str(startPort) + ' and ' + str(endPort))
|
|
||||||
return None
|
|
||||||
|
|
||||||
def __init__(self, port = 50051):
|
|
||||||
logging.basicConfig()
|
|
||||||
location = "localhost:" + str(port)
|
|
||||||
self.channel = grpc.insecure_channel(location)
|
|
||||||
|
|
||||||
# Main version check package
|
|
||||||
self.appInfo = AppInfo(self.channel)
|
|
||||||
try:
|
|
||||||
majorVersionOk = self.appInfo.majorVersion() == int(RiaVersionInfo.RESINSIGHT_MAJOR_VERSION)
|
|
||||||
minorVersionOk = self.appInfo.minorVersion() == int(RiaVersionInfo.RESINSIGHT_MINOR_VERSION)
|
|
||||||
if not (majorVersionOk and minorVersionOk):
|
|
||||||
raise Exception('Version of ResInsight does not match version of Python API')
|
|
||||||
except grpc.RpcError as e:
|
|
||||||
if e.code() == grpc.StatusCode.UNAVAILABLE:
|
|
||||||
print('Info: Could not find any instances at port ' + str(port))
|
|
||||||
except Exception as e:
|
|
||||||
print('Error:', e)
|
|
||||||
|
|
||||||
# Service packages
|
|
||||||
self.commands = Commands(self.channel)
|
|
||||||
self.project = Project(self.channel)
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
@ -1,6 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
@ -1,7 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
# Load instance
|
# Load instance
|
@ -1,6 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
|
|
||||||
import rips
|
import rips
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
import time
|
import time
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
import time
|
import time
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
|
|
||||||
import rips
|
import rips
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
@ -1,6 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
import itertools
|
import itertools
|
||||||
import time
|
import time
|
@ -1,6 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
def createResult(soilChunks, porvChunks):
|
def createResult(soilChunks, porvChunks):
|
@ -1,6 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
resInsight = rips.Instance.find()
|
resInsight = rips.Instance.find()
|
@ -3,7 +3,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import getopt
|
import getopt
|
||||||
|
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
_rips_instance = None
|
_rips_instance = None
|
@ -0,0 +1 @@
|
|||||||
|
PATH = "../../../../TestModels"
|
@ -2,7 +2,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
import dataroot
|
import dataroot
|
@ -3,7 +3,7 @@ import os
|
|||||||
import tempfile
|
import tempfile
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
import dataroot
|
import dataroot
|
@ -1,7 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
import dataroot
|
import dataroot
|
@ -2,7 +2,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
import dataroot
|
import dataroot
|
@ -2,7 +2,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
sys.path.insert(1, os.path.join(sys.path[0], '..'))
|
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
|
||||||
import rips
|
import rips
|
||||||
|
|
||||||
import dataroot
|
import dataroot
|
@ -6,7 +6,7 @@ with open('README.md') as f:
|
|||||||
with open('LICENSE') as f:
|
with open('LICENSE') as f:
|
||||||
license = f.read()
|
license = f.read()
|
||||||
|
|
||||||
RIPS_DIST_VERSION = '2'
|
RIPS_DIST_VERSION = '3'
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='rips',
|
name='rips',
|
||||||
@ -17,5 +17,5 @@ setup(
|
|||||||
author_email='info@ceetronsolutions.com',
|
author_email='info@ceetronsolutions.com',
|
||||||
url='http://www.resinsight.org',
|
url='http://www.resinsight.org',
|
||||||
license=license,
|
license=license,
|
||||||
packages=find_packages(exclude=('tests', 'docs', '__pycache', 'examples'))
|
packages=find_packages(exclude=('docs', '__pycache__'))
|
||||||
)
|
)
|
@ -1 +0,0 @@
|
|||||||
PATH = "../../../TestModels"
|
|
Loading…
Reference in New Issue
Block a user