Skip to content

Commit 32bdf46

Browse files
Develop (#11)
* Updated README.md * Base extractor - Initial cut (#1) * Initial commit of base for extractors * Fixed dockerfile * Added README * Changed extractor to transformer in readme * Updated README * Fleshing out functionality * Updates for file list support * Variable name clarification * Bug fixes * Optimizing Dockerfile * Fixed typo * Merging into Develop (#2) * Initial commit of base for extractors * Fixed dockerfile * Added README * Changed extractor to transformer in readme * Updated README * Fleshing out functionality * Updates for file list support * Variable name clarification * Bug fixes * Optimizing Dockerfile * Fixed typo * Debugging * Removed TERRA REF left-over commented out code * Adding command line parameter storage * Added text abour return codes * Fix up transformer declared types (#4) * Changed list to tuple * type declaration correction and additional commenting * Pylint changes * Test development (#7) * Adding test files * Was missing the 'test_transformer.py' file and made some changes to 'test_transformer_class.py' * adding the initial travis yml * Filled out the yml file * Changed the tests from base unittest to pytest * Changed to pytest over basic unittest * Moved tests to own folder * Removed duplicate files * Moved the yml file out of base-image * modified travis yml to move directories for testing * Added -v to pytest run for more clarity * Ignoring a test for testing purposes * Reverted git ignore changes and temporarily removed a test * Placed test_entrypoint.py back into folder * Pushing from new local * Changed file naming conventions to be more conformative * removing duplicates * Fixed a test * Added pylint installation to travis yml * Added test doc as a link in main readme. * fixed a formatting issue * Initial test folder readme draft * Clarified testing process * added links to helpful documentation * Clarified type of testing being done * Adding pylint file * renamed pylintrc file * changes to pylint file * fixed pylint call * trying to include all files from test folder * moved pylint file * testing pylint * Fixed yml file * fixing yml * I think I figured out the problem * I'll seperate them and make to calls * Made seperate calls * misspelled directory name * made some pylint recommended adjustments * now pulling pylintrc from repo * adding organization repo * Hopefully this works * Updated readme * Added some new lines * Trying again * hopefully this is it * please * done * Minor readme changes * Added pylint protocol link in readmes * Pylint changes * made some pylint recomended changes * Helping pylint along * Directory issues * Resetting python path * adding another line * adding another line * adding another line * added some ignore lines * adding another line * Moved files around * Finding pylint rc * Missed a quotation mark * fixed pylint call * pylint diables * Update base-image/test-files/README.md Co-Authored-By: Chris Schnaufer <schnaufer@email.arizona.edu> * Update base-image/test-files/README.md Co-Authored-By: Chris Schnaufer <schnaufer@email.arizona.edu> * Update base-image/test-files/README.md Co-Authored-By: Chris Schnaufer <schnaufer@email.arizona.edu> * Update base-image/test-files/README.md Co-Authored-By: Chris Schnaufer <schnaufer@email.arizona.edu> * Update base-image/test-files/README.md Co-Authored-By: Chris Schnaufer <schnaufer@email.arizona.edu> * Incorporated Chris' suggestions * Fixed a mistake * Made changes recommended by Chris * missed a change * Loading multiple metadata files & pylint changes (#6) * Update .gitignore, allowing multiple --metadata arguments, spelling & pylint changes * Logging what metadatafiles are loading * Added ability to download files after transformer gives the go-ahead (#8) * Update .gitignore, allowing multiple --metadata arguments, spelling & pylint changes * Logging what metadatafiles are loading * Adding call to download files * Yaml metadata support, optional metadata flag variable, updated to Python3.7 (#10) * Initial support * Updating to Python3.7 * Added link to 'python' command Co-authored-by: Jorge Barrios <jorgebarrios@email.arizona.edu>
1 parent 23045ba commit 32bdf46

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

base-image/Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ RUN chown -R extractor /home/extractor \
1111
RUN apt-get update && \
1212
apt-get upgrade -y && \
1313
apt-get install -y --no-install-recommends \
14-
python3 \
14+
python3.7 \
1515
python3-pip && \
16+
ln -sfn /usr/bin/python3.7 /usr/bin/python && \
17+
ln -sfn /usr/bin/python3.7 /usr/bin/python3 && \
18+
ln -sfn /usr/bin/python3.7m /usr/bin/python3m && \
1619
apt-get autoremove -y && \
1720
apt-get clean && \
1821
rm -rf /var/lib/apt/lists/*

base-image/configuration.py

+4
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66

77
# The transformer description
88
TRANSFORMER_DESCRIPTION = ""
9+
10+
# Override flag for disabling the metadata file requirement.
11+
# Uncomment and set to False to override default behavior
12+
#METADATA_NEEDED = False

base-image/entrypoint.py

+29-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import json
88
import logging
99
from typing import Optional
10+
import yaml
1011

1112
import transformer_class
1213

@@ -55,18 +56,24 @@ def load_metadata(metadata_path: str) -> dict:
5556
won't contain metadata but will contain an error message under an 'error' key.
5657
"""
5758
try:
59+
if os.path.splitext(metadata_path)[1] in ('.yml', '.yaml'):
60+
load_func = yaml.safe_load
61+
else:
62+
load_func = json.load
5863
with open(metadata_path, 'r') as in_file:
59-
md_load = json.load(in_file)
64+
md_load = load_func(in_file)
6065
if md_load is not None:
6166
md_return = {'metadata': md_load}
6267
else:
63-
msg = 'Invalid JSON specified in metadata file "%s"' % metadata_path
68+
msg = 'Invalid JSON/YAML specified in metadata file "%s"' % metadata_path
6469
logging.error(msg)
6570
md_return = {'error': msg}
6671
except Exception as ex:
67-
msg = 'Unable to load metadata file "%s"' % metadata_path
72+
msg = "Unable to load metadata file '%s'" % metadata_path
6873
logging.error(msg)
6974
logging.error('Exception caught: %s', str(ex))
75+
if logging.getLogger().level == logging.DEBUG:
76+
logging.exception(msg)
7077
md_return = {'error': msg}
7178

7279
return md_return
@@ -123,6 +130,24 @@ def check_retrieve_results_error(transformer_retrieve: tuple) -> Optional[dict]:
123130

124131
return None
125132

133+
@staticmethod
134+
def check_metadata_needed() -> bool:
135+
"""Checks if metadata is required
136+
Return:
137+
Returns True if metadata is required (the default is that it's required), or False if not
138+
"""
139+
# Disable the following check since it's not a valid test here (METADATA_NEEDED is an optional variable)
140+
# pylint: disable=no-member
141+
142+
# If we have a variable defined, check the many ways of determining False
143+
if hasattr(configuration, "METADATA_NEEDED"):
144+
if not configuration.METADATA_NEEDED:
145+
return False
146+
if isinstance(configuration.METADATA_NEEDED, str):
147+
if configuration.METADATA_NEEDED.lower().strip() == 'false':
148+
return False
149+
return True
150+
126151
@staticmethod
127152
def load_metadata_files(metadata_files: list) -> dict:
128153
"""Loads the specified metadata files
@@ -358,7 +383,7 @@ def do_work(parser: argparse.ArgumentParser, **kwargs) -> dict:
358383
logging.getLogger().setLevel(args.debug if args.debug == logging.DEBUG else args.info)
359384

360385
# Check that we have mandatory metadata
361-
if not args.metadata:
386+
if not args.metadata and __internal__.check_metadata_needed():
362387
result = __internal__.handle_error(-1, "No metadata paths were specified.")
363388
else:
364389
md_results = __internal__.load_metadata_files(args.metadata)

0 commit comments

Comments
 (0)