Skip to content

Conversation

@DerekFurstPitt
Copy link
Contributor

Added shell script and python script that will take as input a template yaml file (which is in a new directory). This script will look through the yaml file for certain tags. When a tag is reached, it will replace the tag with information at a given url or file path.

DerekFurstPitt and others added 15 commits June 21, 2021 11:53
Added file entity-api-spec-TEMPLATE.yaml
Added python file schema-template-transformer.py
~Derek Furst 6/21/2021
Added file entity-api-spec-TEMPLATE.yaml
Added python file schema-template-transformer.py
~Derek Furst 6/21/2021

added pycharm to gitignore and updated requirements with nested lookup. Added template yaml file for general schema information. Added test package and a test python script. divided up most of schema template transformer into functions.
~Derek Furst 6/28/21
Added file entity-api-spec-TEMPLATE.yaml
Added python file schema-template-transformer.py
~Derek Furst 6/21/2021

added pycharm to gitignore and updated requirements with nested lookup. Added template yaml file for general schema information. Added test package and a test python script. divided up most of schema template transformer into functions.
~Derek Furst 6/28/21
…l api schema template with all

reused information. Placed all templates into template folder called yaml-templates
~Derek Furst 6/29/2021
…from the command line. Added

line to accept argv.
…can now take in as a

command line argument the path to another file. It will look for tags starting with
"X-replace" and, depending on the tag, replace sections of the given file with sections of other
files at given urls which are provided along with the x-replace tag. It acts recursively, and
if it encounters a file that also has x-replace tags, it will perform those replacements as well.

I added in my yaml-templates folder a "base-schema" template that includes some schemas I've
used for testing. Its unlikely all of these schemas would be used, but it was useful for
testing.
…general_schema_template_transformer.py and passes it that

argument. At this time, the shell script outputs nothing, as the python script itself handles the output. May change to allow
the shell script itself to handle the final output. Changed some formatting with the python script just to put comments above
the functions instead of next to them.
…pec.yaml is treated as a temporary file. the shell script does

'cat' on this file and pipes stdout to a new file my-spec.yaml. Also, all file paths now calculate the current file path first rather
than relying on relative pathing.
…by itself, it outputs to stdout. The build-schema.sh takes that

output and pipes it into a new file my-schema.yaml

I added a try block around my call to input from file. Rather than simply checking if argument length is greater than one, it will
an exception either if no argument is passed or if the argument is to a file that doesn't exist.
…build-schema.sh rather than the python script

general_schema_template_transformer.py. This way, we can avoid running the script at all if errors are found. If errors
still are encountered at input and output, exception handling exists in the python script. I removed a ton of previously
commented out lines to get this ready for final review, and changed variable names to be less redundant and more descriptive.
I had an integer count loops through a recursive variable and that has now been replaced. Lastly, I removed a potential source of
a future bug. Since adding a third return type for my recursive function, I had forgotten to change an earlier comparator that was
either "equal" to a value or "not equal". Now that there's a third possible output, there was a case where something incorrect
could be appended to a dictionary. This has been corrected.
…plate-files

reorganized schema template work undir its own directory
@DerekFurstPitt DerekFurstPitt requested a review from yuanzhou July 20, 2021 18:11
Copy link
Member

@yuanzhou yuanzhou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DerekFurstPitt I pulled all the recent new changes from test-release into your branch and appended that commit to your branch too. The unit test failed:

test.test_schema_template_transformer (nose2.loader.ModuleImportFailure) ... ERROR

======================================================================
ERROR: test.test_schema_template_transformer (nose2.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: test.test_schema_template_transformer
Traceback (most recent call last):
  File "/home/zhy19/HuBMAP/entity-api/venv/lib64/python3.7/site-packages/nose2/plugins/loader/discovery.py", line 201, in _find_tests_in_file
    module = util.module_from_name(module_name)
  File "/home/zhy19/HuBMAP/entity-api/venv/lib64/python3.7/site-packages/nose2/util.py", line 77, in module_from_name
    __import__(name)
  File "/home/zhy19/HuBMAP/entity-api/test/test_schema_template_transformer.py", line 2, in <module>
    import schema_template_transformer
ModuleNotFoundError: No module named 'schema_template_transformer'


----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)

Can you fix it?

@yuanzhou
Copy link
Member

yuanzhou commented Jul 22, 2021

@DerekFurstPitt tweaks I made:

  • renamed package schema-templating to schema_templating and placed it under the src directory, underscore is preferred to be used in package name, hyphen would cause import issue.
  • when running the general_schema_template_transformer.py as a python script, use the if __name__ == "__main__": block.
  • deleted the deprecated code and test since they'll just confuse us and github is the tool of record keeping
  • added a sample unit test to load the yaml file using mocking, and use nose2 as the test runner
  • formatted your README.md due to markdown syntax errors with titles

@yuanzhou yuanzhou merged commit b97849f into test-release Jul 22, 2021
@yuanzhou yuanzhou deleted the entity-api-schema-template branch August 2, 2021 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants