From c8fc0bbe317bb41bfe5f28305782a82347b8c776 Mon Sep 17 00:00:00 2001 From: Mostapha Date: Thu, 10 Sep 2020 23:02:24 -0400 Subject: [PATCH] fix(docs): fix import on linux machine --- butterfly/__init__.py | 19 ++++++++++++++----- butterfly/case.py | 2 +- butterfly/gradingutil.py | 4 ++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/butterfly/__init__.py b/butterfly/__init__.py index 8fb8439..b25349f 100644 --- a/butterfly/__init__.py +++ b/butterfly/__init__.py @@ -1,5 +1,7 @@ import re import os +import warnings + def set_config(_ofrunners): """set config for butterfly run manager.""" @@ -7,10 +9,10 @@ def set_config(_ofrunners): 'ESI': r'C:\Program Files (x86)', 'blueCFD': r'C:\Program Files' } - + if not _ofrunners: raise ImportError('Set your installation flavor in confing.yml.') - + # look up for folders for of_runner in _ofrunners: try: @@ -19,6 +21,8 @@ def set_config(_ofrunners): # invalid installation option pass else: + if not os.path.isdir(base_folder): + continue for f in os.listdir(base_folder): of_folder = os.path.join(base_folder, f) if not os.path.isdir(of_folder): @@ -27,12 +31,17 @@ def set_config(_ofrunners): # in case of two installation finds the older one but for now # it is fine. return {'runner': of_runner, 'of_folder': of_folder} - - raise ImportError('Set your installation flavor in confing.yml.') + + warnings.warn( + 'Failed to find the OpenFOAM installation.' + ' Set your installation flavor in confing.yml.' + ) + os.chdir(os.path.dirname(__file__)) with open('config.yml') as inst: _ofrunners = re.findall(r'\s- (.*)', inst.read(),re.MULTILINE ) config = set_config(_ofrunners) -print('OpenFOAM installation: {}'.format(config['runner'])) +if config: + print('OpenFOAM installation: {}'.format(config['runner'])) diff --git a/butterfly/case.py b/butterfly/case.py index 2503890..17d590a 100644 --- a/butterfly/case.py +++ b/butterfly/case.py @@ -50,7 +50,7 @@ import butterfly -if butterfly.config['runner'] == 'blueCFD': +if butterfly.config and butterfly.config['runner'] == 'blueCFD': from .runmanager_bluecfd import RunManagerBlueCFD as RunManager else: from .runmanager import RunManager diff --git a/butterfly/gradingutil.py b/butterfly/gradingutil.py index 54ab55b..17954b6 100644 --- a/butterfly/gradingutil.py +++ b/butterfly/gradingutil.py @@ -1,4 +1,8 @@ from collections import namedtuple +try: + xrange(10) +except: + xrange = range def secant(f, x0, x1, eps, ds, ln, n):