diff --git a/setup.py b/setup.py index 1f051063..dd141c54 100644 --- a/setup.py +++ b/setup.py @@ -33,6 +33,9 @@ setup( test_suite='nose.collector', tests_require=['nose'], keywords=['vhdl', 'style', 'beautify', 'guide'], + install_requires[ + 'PyYAML' + ], entry_points={ 'console_scripts': [ 'vsg = vsg.__main__:main' diff --git a/vsg/__main__.py b/vsg/__main__.py index 92f95c0a..703ecece 100644 --- a/vsg/__main__.py +++ b/vsg/__main__.py @@ -7,6 +7,7 @@ import os import json import shutil import glob +import yaml from . import rule_list from . import vhdlFile @@ -38,32 +39,44 @@ def parse_command_line_arguments(): return parser.parse_args() +def open_configuration_file(sFileName, commandLineArguments): + '''Attempts to open a configuration file and read it's contents.''' + try: + with open(sFileName) as json_file: + tempConfiguration = json.load(json_file) + except: + try: + with open(sFileName) as yaml_file: + tempConfiguration = yaml.load(yaml_file) + except: + print('Error in configuration file: ' + sFileName) + write_invalid_configuration_junit_file(sFileName, commandLineArguments) + exit() + return tempConfiguration + + def read_configuration_files(commandLineArguments): if commandLineArguments.configuration: dConfiguration = {} for sFileName in commandLineArguments.configuration: - try: - with open(sFileName) as json_file: - tempConfiguration = json.load(json_file) - for sKey in tempConfiguration.keys(): - if sKey == 'file_list': - try: - dConfiguration['file_list'].extend(tempConfiguration['file_list']) - except: - dConfiguration['file_list'] = tempConfiguration['file_list'] - elif sKey == 'rule': - for sRule in tempConfiguration[sKey]: - try: - dConfiguration[sKey][sRule] = tempConfiguration[sKey][sRule] - except: - dConfiguration[sKey] = {} - dConfiguration[sKey][sRule] = tempConfiguration[sKey][sRule] - else: - dConfiguration[sKey] = tempConfiguration[sKey] - except: - print('Error in JSON file: ' + sFileName) - write_invalid_configuration_junit_file(sFileName, commandLineArguments) - exit() + + tempConfiguration = open_configuration_file(sFileName, commandLineArguments) + + for sKey in tempConfiguration.keys(): + if sKey == 'file_list': + try: + dConfiguration['file_list'].extend(tempConfiguration['file_list']) + except: + dConfiguration['file_list'] = tempConfiguration['file_list'] + elif sKey == 'rule': + for sRule in tempConfiguration[sKey]: + try: + dConfiguration[sKey][sRule] = tempConfiguration[sKey][sRule] + except: + dConfiguration[sKey] = {} + dConfiguration[sKey][sRule] = tempConfiguration[sKey][sRule] + else: + dConfiguration[sKey] = tempConfiguration[sKey] return dConfiguration diff --git a/vsg/tests/vsg/config_1.yaml b/vsg/tests/vsg/config_1.yaml new file mode 100644 index 00000000..5c1a91da --- /dev/null +++ b/vsg/tests/vsg/config_1.yaml @@ -0,0 +1,5 @@ +--- +# Include files to be processed +file_list: + - vsg/tests/vsg/entity1.vhd +... diff --git a/vsg/tests/vsg/config_error.json b/vsg/tests/vsg/config_error.json index cdef6154..de784720 100644 --- a/vsg/tests/vsg/config_error.json +++ b/vsg/tests/vsg/config_error.json @@ -1,5 +1,5 @@ { - "file_list":[ - "vsg/tests/vsg/entity1.vhd", + "file_list":[, + "vsg/tests/vsg/entity1.vhd" ] } diff --git a/vsg/tests/vsg/test_vsg.py b/vsg/tests/vsg/test_vsg.py index c8b8fcd9..d6f25fe9 100644 --- a/vsg/tests/vsg/test_vsg.py +++ b/vsg/tests/vsg/test_vsg.py @@ -56,7 +56,7 @@ class testVsg(unittest.TestCase): def test_invalid_configuration(self): utils.remove_file('vsg/tests/vsg/config_error.actual.xml') lExpected = [] - lExpected.append('Error in JSON file: vsg/tests/vsg/config_error.json') + lExpected.append('Error in configuration file: vsg/tests/vsg/config_error.json') lExpected.append('') lActual = subprocess.check_output(['bin/vsg','--configuration','vsg/tests/vsg/config_error.json','--output_format','syntastic','-f','vsg/tests/vsg/entity1.vhd','--junit','vsg/tests/vsg/config_error.actual.xml']).split('\n') @@ -94,3 +94,19 @@ class testVsg(unittest.TestCase): lActual = subprocess.check_output(['bin/vsg','--configuration','vsg/tests/vsg/config_glob.json','--output_format','syntastic']).split('\n') self.assertEqual(lActual, lExpected) + + def test_single_yaml_configuration_w_filelist(self): + lExpected = [] + lExpected.append('ERROR: vsg/tests/vsg/entity1.vhd(7)port_007 -- Change the number of spaces after the "in" keyword to four spaces.') + lExpected.append('') + + lActual = subprocess.check_output(['bin/vsg','--configuration','vsg/tests/vsg/config_1.yaml','--output_format','syntastic']).split('\n') + self.assertEqual(lActual, lExpected) + + lExpected = [] + lExpected.append('ERROR: vsg/tests/vsg/entity2.vhd(8)port_008 -- Change the number of spaces after the "out" keyword to three spaces.') + lExpected.append('') + + lActual = subprocess.check_output(['bin/vsg','--configuration','vsg/tests/vsg/config_2.json','--output_format','syntastic']).split('\n') + self.assertEqual(lActual, lExpected) +