Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #55 from mhearne-usgs/cmdfix
Browse files Browse the repository at this point in the history
Removed dependency on impactutils cmd module, allowing us to have imp…
  • Loading branch information
emthompson-usgs authored Mar 29, 2019
2 parents 4f63a28 + 165cfec commit b825cf6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 22 deletions.
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ channels:
- conda-forge
- defaults
dependencies:
- impactutils
- numpy
- pandas
- scipy
Expand Down
31 changes: 14 additions & 17 deletions makedocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import argparse
import os.path
import sys
import tempfile
import pathlib
from distutils.dir_util import copy_tree

from impactutils.io.cmd import get_command_output
from ps2ff.cmd import get_command_output


def main(args):
Expand All @@ -25,26 +23,24 @@ def main(args):
Nothing. Function will exit upon success or failure.
"""
verbose = args.verbose

#-------------------------------------------------------------
# -------------------------------------------------------------
# Some useful directories
#-------------------------------------------------------------
# -------------------------------------------------------------
REPO_DIR = os.path.dirname(os.path.abspath(__file__))
DOCS_DIR = os.path.join(REPO_DIR, 'docs')
API_DIR = os.path.join(REPO_DIR, 'doc_source')
API_DIR = os.path.join(REPO_DIR, 'doc_source')
PACKAGE_DIR = os.path.join(REPO_DIR, 'ps2ff')

#-------------------------------------------------------------
# -------------------------------------------------------------
# what is the package called and who are the authors
#-------------------------------------------------------------
# -------------------------------------------------------------
PACKAGE = "ps2ff"
AUTHORS = 'Eric Thompson, Bruce Worden'
verstr = '1.1'

#-------------------------------------------------------------
# -------------------------------------------------------------
# run the api doc command; this creates the .rst files
#-------------------------------------------------------------
# -------------------------------------------------------------
sys.stderr.write('Building ps2ff API documentation (REST)...\n')
sphinx_cmd = 'sphinx-apidoc -o %s -f -e -l -M -d 12 -H %s -A "%s"'\
' -V %s %s' % (API_DIR, PACKAGE, AUTHORS, verstr,
Expand All @@ -59,9 +55,9 @@ def main(args):
print(stdout.decode('utf-8'))
print(stderr.decode('utf-8'))

#--------------------------------------------
# --------------------------------------------
# try to clean up some of the excess labeling
#--------------------------------------------
# --------------------------------------------
clean_cmd = "sed -i '' -e 's/ module//g' `find %s/*.rst -type f "\
"-maxdepth 0 -print`" % API_DIR
res, stdout, stderr = get_command_output(clean_cmd)
Expand All @@ -75,11 +71,12 @@ def main(args):
"-maxdepth 0 -print`" % API_DIR
res, stdout, stderr = get_command_output(clean_cmd)

#-------------------------------------------------------------
# -------------------------------------------------------------
# Build the html
#-------------------------------------------------------------
# -------------------------------------------------------------
sys.stderr.write('Building ps2ff pages (HTML)...\n')
res, stdout, stderr = get_command_output('sphinx-build -a -E doc_source docs')
res, stdout, stderr = get_command_output(
'sphinx-build -a -E doc_source docs')
if not res:
raise Exception('Could not build HTML for API documentation. - '
'error "%s"' % stderr.decode())
Expand Down
28 changes: 28 additions & 0 deletions ps2ff/cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python

import subprocess


def get_command_output(cmd):
"""
Method for calling external system command.
Args:
cmd: String command (e.g., 'ls -l', etc.).
Returns:
Three-element tuple containing a boolean indicating success or failure,
the stdout from running the command, and stderr.
"""
proc = subprocess.Popen(cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
stdout, stderr = proc.communicate()
retcode = proc.returncode
if retcode == 0:
retcode = True
else:
retcode = False
return (retcode, stdout, stderr)
2 changes: 1 addition & 1 deletion tests/RjbRrup_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import pandas as pd
import shutil
from impactutils.io.cmd import get_command_output
from ps2ff.cmd import get_command_output


def test_rjb_WC94():
Expand Down
2 changes: 1 addition & 1 deletion tests/fast_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import pandas as pd
import shutil
from impactutils.io.cmd import get_command_output
from ps2ff.cmd import get_command_output


def test_rrup_Sea10_slab():
Expand Down
4 changes: 2 additions & 2 deletions tests/single_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import pandas as pd
import shutil
from impactutils.io.cmd import get_command_output
from ps2ff.cmd import get_command_output


def test_single():
Expand Down Expand Up @@ -120,8 +120,8 @@ def test_single_N1():
# Clean up
shutil.rmtree('DataSingle')


if __name__ == '__main__':
test_single()
test_single_by_theta_false()
test_single_N1()

0 comments on commit b825cf6

Please sign in to comment.