Python: move examples, tests and generated inside rips folder so they are packaged in rips pip-package

This commit is contained in:
Gaute Lindkvist
2019-06-12 08:29:41 +02:00
parent fe268cd25f
commit 1d8a417e33
30 changed files with 52 additions and 130 deletions

View File

@@ -2,7 +2,7 @@ import grpc
import os
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

View File

@@ -4,7 +4,7 @@ import sys
from .Grid import Grid
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_grpc

View File

@@ -2,7 +2,7 @@ import grpc
import os
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
import Commands_pb2 as Cmd

View File

@@ -2,7 +2,7 @@ import grpc
import os
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_grpc

View File

@@ -5,7 +5,7 @@ import socket
import logging
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

View File

@@ -5,7 +5,7 @@ import sys
from .Case import Case
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
import Project_pb2

View File

@@ -2,7 +2,7 @@ import grpc
import os
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_grpc

View File

@@ -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)

View File

@@ -1,7 +1,7 @@
import sys
import os
sys.path.insert(1, os.path.join(sys.path[0], '..'))
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips
resInsight = rips.Instance.find()

View File

@@ -1,6 +1,6 @@
import sys
import os
sys.path.insert(1, os.path.join(sys.path[0], '..'))
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips
resInsight = rips.Instance.find()

View File

@@ -1,7 +1,7 @@
import sys
import os
import tempfile
sys.path.insert(1, os.path.join(sys.path[0], '..'))
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips
# Load instance

View File

@@ -1,6 +1,6 @@
import sys
import os
sys.path.insert(1, os.path.join(sys.path[0], '..'))
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips

View File

@@ -1,6 +1,6 @@
import sys
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 time

View File

@@ -1,6 +1,6 @@
import sys
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 time

View File

@@ -1,6 +1,6 @@
import sys
import os
sys.path.insert(1, os.path.join(sys.path[0], '..'))
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips

View File

@@ -1,6 +1,6 @@
import sys
import os
sys.path.insert(1, os.path.join(sys.path[0], '..'))
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips
resInsight = rips.Instance.find()

View File

@@ -1,6 +1,6 @@
import sys
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 itertools
import time

View File

@@ -1,6 +1,6 @@
import sys
import os
sys.path.insert(1, os.path.join(sys.path[0], '..'))
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips
def createResult(soilChunks, porvChunks):

View File

@@ -1,6 +1,6 @@
import sys
import os
sys.path.insert(1, os.path.join(sys.path[0], '..'))
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips
resInsight = rips.Instance.find()

View File

@@ -3,7 +3,7 @@ import sys
import os
import getopt
sys.path.insert(1, os.path.join(sys.path[0], '..'))
sys.path.insert(1, os.path.join(sys.path[0], '../../'))
import rips
_rips_instance = None

View File

@@ -0,0 +1 @@
PATH = "../../../../TestModels"

View File

@@ -2,7 +2,7 @@ import sys
import os
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 dataroot

View File

@@ -3,7 +3,7 @@ import os
import tempfile
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 dataroot

View File

@@ -1,7 +1,7 @@
import sys
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 dataroot

View File

@@ -2,7 +2,7 @@ import sys
import os
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 dataroot

View File

@@ -2,7 +2,7 @@ import sys
import os
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 dataroot

View File

@@ -6,7 +6,7 @@ with open('README.md') as f:
with open('LICENSE') as f:
license = f.read()
RIPS_DIST_VERSION = '2'
RIPS_DIST_VERSION = '3'
setup(
name='rips',
@@ -17,5 +17,5 @@ setup(
author_email='info@ceetronsolutions.com',
url='http://www.resinsight.org',
license=license,
packages=find_packages(exclude=('tests', 'docs', '__pycache', 'examples'))
packages=find_packages(exclude=('docs', '__pycache__'))
)

View File

@@ -1 +0,0 @@
PATH = "../../../TestModels"