Skip to content

Commit

Permalink
Merge 592201f into c105f94
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jul 3, 2019
2 parents c105f94 + 592201f commit 4c41f17
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
17 changes: 8 additions & 9 deletions sami2py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,21 @@
specified by the user.
---------------------------------------------------------------------------
"""
from __future__ import print_function
import logging
import sys
import os

__version__ = str('0.1.2')

# get home directory
env_dir = sys.prefix
env_dir = os.path.expanduser('~')
# set sami2py directory path in home directory
sami2py_dir = os.path.join(env_dir, '.sami2py')
# make sure a sami2py directory for model output exists
if not os.path.isdir(sami2py_dir):
# create directory
os.mkdir(sami2py_dir)
print(''.join(('Created .sami2py directory in ' + env_dir + ' to',
'store settings.')))
print('Created {} directory to store settings.'.format(sami2py_dir))


archive_path = os.path.join(sami2py_dir, 'archive_path.txt')
Expand All @@ -60,8 +59,8 @@
with open(archive_path, 'w+') as f:
f.write('')
archive_dir = ''
print(''.join(('Run sami2py.utils.set_archive_dir to set the path to',
' top-level directory for model outputs.')))
print('Run sami2py.utils.set_archive_dir to set the path to'
' top-level directory for model outputs.')

# load fortran directory
with open(os.path.join(sami2py_dir, 'fortran_path.txt'), 'r') as f:
Expand All @@ -73,8 +72,8 @@

# import main functions
try:
from sami2py import _core, _core_class, utils
from sami2py._core import run_model
from sami2py._core_class import Model
from sami2py import _core, _core_class, utils # noqa: F401
from sami2py._core import run_model # noqa: F401
from sami2py._core_class import Model # noqa: F401
except ImportError as errstr:
logging.exception('problem importing sami2py: ' + str(errstr))
5 changes: 1 addition & 4 deletions sami2py/tests/test_core_class.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Unit tests for model.py
"""
import os
import sys
import sami2py
from nose.tools import raises

Expand All @@ -22,9 +21,7 @@ def teardown(self):
if os.path.isdir(self.tmp_archive_dir):
sami2py.utils.set_archive_dir(path=self.tmp_archive_dir)
else:
env_dir = sys.prefix
sami2py_dir = os.path.join(env_dir, '.sami2py')
archive_path = os.path.join(sami2py_dir, 'archive_path.txt')
archive_path = os.path.join(sami2py.sami2py_dir, 'archive_path.txt')
with open(archive_path, 'w') as archive_file:
archive_file.write('')
sami2py.archive_dir = ''
Expand Down
4 changes: 1 addition & 3 deletions sami2py/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,11 @@ def set_archive_dir(path=None, store=True):
if True, store data directory for future runs
"""
import os
import sys
import sami2py

if os.path.isdir(path):
if store:
with open(os.path.join(sys.prefix,
'.sami2py', 'archive_path.txt'),
with open(os.path.join(sami2py.sami2py_dir, 'archive_path.txt'),
'w') as archive_file:
archive_file.write(path)
sami2py.archive_dir = path
Expand Down
28 changes: 14 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@
# Full license can be found in License.md
# -----------------------------------------------------------------------------

import sys
from os import path, mkdir
import os
from setuptools import setup, find_packages

HOME = os.path.expanduser('~')


# Define a read function for using README for long_description
def read(fname):
return open(path.join(path.dirname(__file__), fname)).read()
return open(os.path.join(os.path.dirname(__file__), fname)).read()


# generate path for fortran model files
here = path.abspath(path.dirname(__file__))
fortran_path = path.join(here, 'sami2py', 'fortran')
test_data_path = path.join(here, 'sami2py', 'tests', 'test_data')
file_path = path.join(sys.prefix, '.sami2py')
here = os.path.abspath(os.path.dirname(__file__))
fortran_path = os.path.join(here, 'sami2py', 'fortran')
test_data_path = os.path.join(here, 'sami2py', 'tests', 'test_data')
file_path = os.path.join(HOME, '.sami2py')

if not path.isfile(fortran_path + '/sami2py.x'):
if not os.path.isfile(fortran_path + '/sami2py.x'):
print('\n'.join(['\nYou will need to compile the fortran files. Try',
'$ make -C sami2py/fortran compile\n']))

if not path.isdir(file_path):
mkdir(file_path)
print(''.join(('Created .sami2py directory in ' + sys.prefix + ' to',
'store settings.')))
if not os.path.isdir(file_path):
os.mkdir(file_path)
print('Created {} directory to store settings.'.format(file_path))

with open(path.join(file_path, 'fortran_path.txt'), 'w+') as f:
with open(os.path.join(file_path, 'fortran_path.txt'), 'w+') as f:
f.write(fortran_path)
with open(path.join(file_path, 'test_data_path.txt'), 'w+') as f:
with open(os.path.join(file_path, 'test_data_path.txt'), 'w+') as f:
f.write(test_data_path)

# Define a test suite
Expand Down

0 comments on commit 4c41f17

Please sign in to comment.