From b2c2228ba12a75d5bfb9b50f4c34e2b326037407 Mon Sep 17 00:00:00 2001 From: Jeremiah C Leary Date: Fri, 28 Feb 2020 07:24:26 -0600 Subject: [PATCH 1/8] Updates for issue #344 Added ability to set rule individual rule configurations. 1) Updated documentation 2) Updated parsing of configuration files to handle individual rule configurations. --- docs/configuring.rst | 65 ++++++++++++++++++++++++++++++++++++++------ vsg/__main__.py | 8 +++++- 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/docs/configuring.rst b/docs/configuring.rst index c370f908..373af516 100644 --- a/docs/configuring.rst +++ b/docs/configuring.rst @@ -1,7 +1,7 @@ Configuring =========== -VSG can use a configuration file to alter it's behavior or include a list of files to analyze. +VSG can use a configuration file to alter it's behavior and/or include a list of files to analyze. This is accomplished by passing JSON and/or YAML file(s) through the **--configuration** command line argument. This is the basic form of a configuration file in JSON: @@ -10,9 +10,12 @@ This is the basic form of a configuration file in JSON: { "file_list":[ "fifo.vhd", - "source/spi.vhd", "$PATH_TO_FILE/spi_master.vhd", - "$OTHER_PATH/src/*.vhd" + "$OTHER_PATH/src/*.vhd", + "source/spi.vhd": { + "rule": { + "ruleId_ruleNumber":"blah" + } ], "local_rules":"$DIRECTORY_PATH", "rule":{ @@ -32,7 +35,10 @@ This is the basic form of a configuration file in YAML: --- file_list:[ - fifo.vhd - - source/spi.vhd + - source/spi.vhd: + rule: + ruleId_ruleNumber: + attributeName: AttributeValue - $PATH_TO_FILE/spi_master.vhd - $OTHER_PATH/src/*.vhd local_rules: $DIRECTORY_PATH @@ -40,13 +46,12 @@ This is the basic form of a configuration file in YAML: global: attributeName: AttributeValue ruleId_ruleNumber: - attributeName: AttributeValue + attributeName: AttributeValue ... It is not required to have **file_list**, **local_rules**, and **rule** defined in the configuration file. -Any combination can be defined. -The order does not matter either. +Any combination can be defined, and the order does not matter. .. NOTE:: All examples of configurations in this documentation use JSON. However, YAML can be used instead. @@ -59,6 +64,8 @@ File globbing is also supported. The Environment variables will be expanded before globbing occurs. This option can be useful when running VSG over multiple files. +Rule configurations can be specified for each file by following the format of the **rule** configuration. + local_rules ----------- @@ -90,8 +97,6 @@ Here are a list of attributes that can be altered for each rule: | fixable | Boolean | If set to False, the violation will not be fixed | +-------------+---------+--------------------------------------------------+ -.. NOTE:: Some rules have additional attributes. These will be noted in the rule description. - Reporting Single Rule Configuration ----------------------------------- @@ -125,6 +130,48 @@ Every rule configuration can be report and saved to a file using the **-oc** opt The output file will be in JSON format and can be modified and passed back to VSG using the *-c* option. +Rule Configuration Priorities +----------------------------- + +There are three ways to configure a rule. +From least to highest priority are: + +* **[rule][global]** +* **[rule][]** +* **[file_list][][rule][]**. + +If the same rule is defined in all three locations as in the example below, then the final setting will be equal to the highest priority. + +.. code-block:: json + + { + "file_list":[ + "entity.vhd":{ + "rule":{ + "length_001":{ + "disable": true + } + } + }, + "architecture.vhd", + "package.vhd" + ], + "rule":{ + "global":{ + "disable": true + }, + "rule": { + "length_001":{ + "disable": false + } + } + } + + +In this example configuration, all rules are disabled by the **global** configuration. +Then rule **length_001** is enabled for the files **architecture.vhd**, **package.vhd** and **entity.vhd** by the **rule** configuration. +Then rule **length_001** is disabled for the file **entity.vhd**. + Example: Disabling a rule -------------------------- diff --git a/vsg/__main__.py b/vsg/__main__.py index 74b1a04b..20ea1a2a 100644 --- a/vsg/__main__.py +++ b/vsg/__main__.py @@ -122,6 +122,8 @@ def update_command_line_arguments(commandLineArguments, configuration): if configuration: if 'file_list' in configuration: for sFilename in configuration['file_list']: + if isinstance(sFilename, dict): + sFilename = list(sFilename.keys())[0] try: commandLineArguments.filename.extend(glob.glob(expand_filename(sFilename))) except: @@ -243,11 +245,15 @@ def main(): display_rule_configuration(commandLineArguments, configuration) - for sFileName in commandLineArguments.filename: + for iIndex, sFileName in enumerate(commandLineArguments.filename): oVhdlFile = vhdlFile.vhdlFile(read_vhdlfile(sFileName)) oVhdlFile.filename = sFileName oRules = rule_list.rule_list(oVhdlFile, commandLineArguments.local_rules) oRules.configure(configuration) + try: + oRules.configure(configuration['file_list'][iIndex][sFileName]) + except TypeError: + pass if commandLineArguments.fix: if commandLineArguments.backup: From 21212d98d58b2d0162c9061de07f7ed4ff7a31f9 Mon Sep 17 00:00:00 2001 From: Jeremiah C Leary Date: Wed, 11 Mar 2020 21:06:06 -0500 Subject: [PATCH 2/8] Updates for issue #344 Fixed issue where file globbing was not working. --- vsg/__main__.py | 22 +++++-- .../vsg/read_configuration_files/arch.vhd | 0 .../vsg/read_configuration_files/arch_2.vhd | 0 .../config_w_file_globbing.json | 5 ++ .../config_w_file_list.json | 7 +++ .../vsg/read_configuration_files/entity.vhd | 0 .../vsg/read_configuration_files/entity_2.vhd | 0 .../vsg/read_configuration_files/package.vhd | 0 .../read_configuration_files/package_2.vhd | 0 .../test_read_configuration_files_function.py | 57 +++++++++++++++++++ 10 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 vsg/tests/vsg/read_configuration_files/arch.vhd create mode 100644 vsg/tests/vsg/read_configuration_files/arch_2.vhd create mode 100644 vsg/tests/vsg/read_configuration_files/config_w_file_globbing.json create mode 100644 vsg/tests/vsg/read_configuration_files/config_w_file_list.json create mode 100644 vsg/tests/vsg/read_configuration_files/entity.vhd create mode 100644 vsg/tests/vsg/read_configuration_files/entity_2.vhd create mode 100644 vsg/tests/vsg/read_configuration_files/package.vhd create mode 100644 vsg/tests/vsg/read_configuration_files/package_2.vhd create mode 100644 vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py diff --git a/vsg/__main__.py b/vsg/__main__.py index 20ea1a2a..28502817 100644 --- a/vsg/__main__.py +++ b/vsg/__main__.py @@ -68,15 +68,24 @@ def read_configuration_files(commandLineArguments): if commandLineArguments.configuration: dConfiguration = {} for sFileName in commandLineArguments.configuration: - +# print(sFileName) 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'] + if not 'file_list' in dConfiguration: + dConfiguration['file_list'] = [] + for iIndex, sFilename in enumerate(tempConfiguration['file_list']): +# print(sFilename) +# print(glob.glob(expand_filename(sFilename))) + for sGlobbedFilename in glob.glob(expand_filename(sFilename)): +# print(sGlobbedFilename) + try: +# print('Extending') + dConfiguration['file_list'].append(sGlobbedFilename) + except: + dConfiguration['file_list'] = [sGlobbedFilename] +# print(dConfiguration) elif sKey == 'rule': for sRule in tempConfiguration[sKey]: try: @@ -246,6 +255,7 @@ def main(): display_rule_configuration(commandLineArguments, configuration) for iIndex, sFileName in enumerate(commandLineArguments.filename): +# print(sFileName) oVhdlFile = vhdlFile.vhdlFile(read_vhdlfile(sFileName)) oVhdlFile.filename = sFileName oRules = rule_list.rule_list(oVhdlFile, commandLineArguments.local_rules) @@ -254,6 +264,8 @@ def main(): oRules.configure(configuration['file_list'][iIndex][sFileName]) except TypeError: pass + except KeyError: + pass if commandLineArguments.fix: if commandLineArguments.backup: diff --git a/vsg/tests/vsg/read_configuration_files/arch.vhd b/vsg/tests/vsg/read_configuration_files/arch.vhd new file mode 100644 index 00000000..e69de29b diff --git a/vsg/tests/vsg/read_configuration_files/arch_2.vhd b/vsg/tests/vsg/read_configuration_files/arch_2.vhd new file mode 100644 index 00000000..e69de29b diff --git a/vsg/tests/vsg/read_configuration_files/config_w_file_globbing.json b/vsg/tests/vsg/read_configuration_files/config_w_file_globbing.json new file mode 100644 index 00000000..429b7acd --- /dev/null +++ b/vsg/tests/vsg/read_configuration_files/config_w_file_globbing.json @@ -0,0 +1,5 @@ +{ + "file_list" : [ + "vsg/tests/vsg/read_configuration_files/*.vhd" + ] +} diff --git a/vsg/tests/vsg/read_configuration_files/config_w_file_list.json b/vsg/tests/vsg/read_configuration_files/config_w_file_list.json new file mode 100644 index 00000000..92564038 --- /dev/null +++ b/vsg/tests/vsg/read_configuration_files/config_w_file_list.json @@ -0,0 +1,7 @@ +{ + "file_list" : [ + "vsg/tests/vsg/read_configuration_files/entity.vhd", + "vsg/tests/vsg/read_configuration_files/arch.vhd", + "vsg/tests/vsg/read_configuration_files/package.vhd" + ] +} diff --git a/vsg/tests/vsg/read_configuration_files/entity.vhd b/vsg/tests/vsg/read_configuration_files/entity.vhd new file mode 100644 index 00000000..e69de29b diff --git a/vsg/tests/vsg/read_configuration_files/entity_2.vhd b/vsg/tests/vsg/read_configuration_files/entity_2.vhd new file mode 100644 index 00000000..e69de29b diff --git a/vsg/tests/vsg/read_configuration_files/package.vhd b/vsg/tests/vsg/read_configuration_files/package.vhd new file mode 100644 index 00000000..e69de29b diff --git a/vsg/tests/vsg/read_configuration_files/package_2.vhd b/vsg/tests/vsg/read_configuration_files/package_2.vhd new file mode 100644 index 00000000..e69de29b diff --git a/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py b/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py new file mode 100644 index 00000000..ab547141 --- /dev/null +++ b/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py @@ -0,0 +1,57 @@ +import unittest +from unittest import mock +import subprocess +import os + +from vsg.tests import utils +from vsg.__main__ import read_configuration_files + + + +class command_line_args(): + ''' This is used as an input into the read_configuration function.''' + def __init__(self, configuration=False): + self.configuration = configuration + + +class test_read_configuration_function(unittest.TestCase): + + def setUp(self): + if os.path.isfile('deleteme.json'): + os.remove('deleteme.json') + + def tearDown(self): + if os.path.isfile('deleteme.json'): + os.remove('deleteme.json') + + def test_file_list(self): + oCommandLineArgs = command_line_args(['vsg/tests/vsg/read_configuration_files/config_w_file_list.json']) + + dExpected = {} + dExpected['file_list'] = [] + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/entity.vhd') + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/arch.vhd') + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/package.vhd') + + dActual = read_configuration_files(oCommandLineArgs) + + self.assertEqual(dActual, dExpected) + + + def test_globbing_files(self): + self.maxDiff = None + oCommandLineArgs = command_line_args(['vsg/tests/vsg/read_configuration_files/config_w_file_globbing.json']) + + dExpected = {} + dExpected['file_list'] = [] + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/package.vhd') + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/entity_2.vhd') + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/arch_2.vhd') + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/package_2.vhd') + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/arch.vhd') + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/entity.vhd') + + dActual = read_configuration_files(oCommandLineArgs) + + self.assertEqual(dActual, dExpected) + From 2ebcb95d720505e132999eceaee1d1e4bb5e3d9d Mon Sep 17 00:00:00 2001 From: Jeremiah C Leary Date: Wed, 11 Mar 2020 22:08:24 -0500 Subject: [PATCH 3/8] Updates for issue #344 Added ability to handle individual rule setting on globbed files. --- vsg/__main__.py | 19 ++++--- .../vsg/read_configuration_files/__init__.py | 0 ...ist_globbing_w_individual_rule_config.json | 19 +++++++ ..._w_file_list_w_individual_rule_config.json | 13 +++++ .../test_read_configuration_files_function.py | 49 ++++++++++++++++++- 5 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 vsg/tests/vsg/read_configuration_files/__init__.py create mode 100644 vsg/tests/vsg/read_configuration_files/config_w_file_list_globbing_w_individual_rule_config.json create mode 100644 vsg/tests/vsg/read_configuration_files/config_w_file_list_w_individual_rule_config.json diff --git a/vsg/__main__.py b/vsg/__main__.py index 28502817..4bcbcee9 100644 --- a/vsg/__main__.py +++ b/vsg/__main__.py @@ -68,7 +68,6 @@ def read_configuration_files(commandLineArguments): if commandLineArguments.configuration: dConfiguration = {} for sFileName in commandLineArguments.configuration: -# print(sFileName) tempConfiguration = open_configuration_file(sFileName, commandLineArguments) for sKey in tempConfiguration.keys(): @@ -76,16 +75,17 @@ def read_configuration_files(commandLineArguments): if not 'file_list' in dConfiguration: dConfiguration['file_list'] = [] for iIndex, sFilename in enumerate(tempConfiguration['file_list']): -# print(sFilename) -# print(glob.glob(expand_filename(sFilename))) - for sGlobbedFilename in glob.glob(expand_filename(sFilename)): -# print(sGlobbedFilename) try: -# print('Extending') + for sGlobbedFilename in glob.glob(expand_filename(sFilename)): dConfiguration['file_list'].append(sGlobbedFilename) - except: - dConfiguration['file_list'] = [sGlobbedFilename] -# print(dConfiguration) + except TypeError: + sKey = list(sFilename.keys())[0] + for sGlobbedFilename in glob.glob(expand_filename(sKey)): + dTemp = {} + dTemp[sGlobbedFilename] = {} + dTemp[sGlobbedFilename].update(tempConfiguration['file_list'][iIndex][sKey]) + dConfiguration['file_list'].append(dTemp) + elif sKey == 'rule': for sRule in tempConfiguration[sKey]: try: @@ -255,7 +255,6 @@ def main(): display_rule_configuration(commandLineArguments, configuration) for iIndex, sFileName in enumerate(commandLineArguments.filename): -# print(sFileName) oVhdlFile = vhdlFile.vhdlFile(read_vhdlfile(sFileName)) oVhdlFile.filename = sFileName oRules = rule_list.rule_list(oVhdlFile, commandLineArguments.local_rules) diff --git a/vsg/tests/vsg/read_configuration_files/__init__.py b/vsg/tests/vsg/read_configuration_files/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/vsg/tests/vsg/read_configuration_files/config_w_file_list_globbing_w_individual_rule_config.json b/vsg/tests/vsg/read_configuration_files/config_w_file_list_globbing_w_individual_rule_config.json new file mode 100644 index 00000000..9cbf741b --- /dev/null +++ b/vsg/tests/vsg/read_configuration_files/config_w_file_list_globbing_w_individual_rule_config.json @@ -0,0 +1,19 @@ +{ + "file_list" : [ + "vsg/tests/vsg/read_configuration_files/entity.vhd", + "vsg/tests/vsg/read_configuration_files/arch*.vhd":{ + "rule":{ + "rule_001":{ + "disable": true + } + } + }, + "vsg/tests/vsg/read_configuration_files/package.vhd":{ + "rule":{ + "rule_002":{ + "disable": false + } + } + } + ] +} diff --git a/vsg/tests/vsg/read_configuration_files/config_w_file_list_w_individual_rule_config.json b/vsg/tests/vsg/read_configuration_files/config_w_file_list_w_individual_rule_config.json new file mode 100644 index 00000000..a8964f0f --- /dev/null +++ b/vsg/tests/vsg/read_configuration_files/config_w_file_list_w_individual_rule_config.json @@ -0,0 +1,13 @@ +{ + "file_list" : [ + "vsg/tests/vsg/read_configuration_files/entity.vhd", + "vsg/tests/vsg/read_configuration_files/arch.vhd":{ + "rule":{ + "rule_001":{ + "disable":True + } + } + }, + "vsg/tests/vsg/read_configuration_files/package.vhd" + ] +} diff --git a/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py b/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py index ab547141..bf0561fa 100644 --- a/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py +++ b/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py @@ -39,7 +39,6 @@ class test_read_configuration_function(unittest.TestCase): def test_globbing_files(self): - self.maxDiff = None oCommandLineArgs = command_line_args(['vsg/tests/vsg/read_configuration_files/config_w_file_globbing.json']) dExpected = {} @@ -55,3 +54,51 @@ class test_read_configuration_function(unittest.TestCase): self.assertEqual(dActual, dExpected) + def test_file_list_with_individual_rule_config(self): + self.maxDiff = None + oCommandLineArgs = command_line_args(['vsg/tests/vsg/read_configuration_files/config_w_file_list_w_individual_rule_config.json']) + + dExpected = {} + dExpected['file_list'] = [] + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/entity.vhd') + dFile = {} + dFile['vsg/tests/vsg/read_configuration_files/arch.vhd'] = {} + dFile['vsg/tests/vsg/read_configuration_files/arch.vhd']['rule'] = {} + dFile['vsg/tests/vsg/read_configuration_files/arch.vhd']['rule']['rule_001'] = {} + dFile['vsg/tests/vsg/read_configuration_files/arch.vhd']['rule']['rule_001']['disable'] = True + dExpected['file_list'].append(dFile) + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/package.vhd') + + dActual = read_configuration_files(oCommandLineArgs) + + self.assertEqual(dActual, dExpected) + + def test_file_list_globbing_with_individual_rule_config(self): + self.maxDiff = None + oCommandLineArgs = command_line_args(['vsg/tests/vsg/read_configuration_files/config_w_file_list_globbing_w_individual_rule_config.json']) + + dExpected = {} + dExpected['file_list'] = [] + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/entity.vhd') + dFile = {} + dFile['vsg/tests/vsg/read_configuration_files/arch_2.vhd'] = {} + dFile['vsg/tests/vsg/read_configuration_files/arch_2.vhd']['rule'] = {} + dFile['vsg/tests/vsg/read_configuration_files/arch_2.vhd']['rule']['rule_001'] = {} + dFile['vsg/tests/vsg/read_configuration_files/arch_2.vhd']['rule']['rule_001']['disable'] = True + dExpected['file_list'].append(dFile) + dFile = {} + dFile['vsg/tests/vsg/read_configuration_files/arch.vhd'] = {} + dFile['vsg/tests/vsg/read_configuration_files/arch.vhd']['rule'] = {} + dFile['vsg/tests/vsg/read_configuration_files/arch.vhd']['rule']['rule_001'] = {} + dFile['vsg/tests/vsg/read_configuration_files/arch.vhd']['rule']['rule_001']['disable'] = True + dExpected['file_list'].append(dFile) + dFile = {} + dFile['vsg/tests/vsg/read_configuration_files/package.vhd'] = {} + dFile['vsg/tests/vsg/read_configuration_files/package.vhd']['rule'] = {} + dFile['vsg/tests/vsg/read_configuration_files/package.vhd']['rule']['rule_002'] = {} + dFile['vsg/tests/vsg/read_configuration_files/package.vhd']['rule']['rule_002']['disable'] = False + dExpected['file_list'].append(dFile) + + dActual = read_configuration_files(oCommandLineArgs) + + self.assertEqual(dActual, dExpected) From e262ee20d9971fb0bd37c1c73adb1fe68dada147 Mon Sep 17 00:00:00 2001 From: Jeremiah C Leary Date: Sat, 21 Mar 2020 09:19:33 -0500 Subject: [PATCH 4/8] Minor updates for codeclimate issues. --- vsg/__main__.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/vsg/__main__.py b/vsg/__main__.py index 4bcbcee9..72e2f562 100644 --- a/vsg/__main__.py +++ b/vsg/__main__.py @@ -72,19 +72,19 @@ def read_configuration_files(commandLineArguments): for sKey in tempConfiguration.keys(): if sKey == 'file_list': - if not 'file_list' in dConfiguration: + if 'file_list' not in dConfiguration: dConfiguration['file_list'] = [] for iIndex, sFilename in enumerate(tempConfiguration['file_list']): try: - for sGlobbedFilename in glob.glob(expand_filename(sFilename)): - dConfiguration['file_list'].append(sGlobbedFilename) + for sGlobbedFilename in glob.glob(expand_filename(sFilename)): + dConfiguration['file_list'].append(sGlobbedFilename) except TypeError: - sKey = list(sFilename.keys())[0] - for sGlobbedFilename in glob.glob(expand_filename(sKey)): - dTemp = {} - dTemp[sGlobbedFilename] = {} - dTemp[sGlobbedFilename].update(tempConfiguration['file_list'][iIndex][sKey]) - dConfiguration['file_list'].append(dTemp) + sKey = list(sFilename.keys())[0] + for sGlobbedFilename in glob.glob(expand_filename(sKey)): + dTemp = {} + dTemp[sGlobbedFilename] = {} + dTemp[sGlobbedFilename].update(tempConfiguration['file_list'][iIndex][sKey]) + dConfiguration['file_list'].append(dTemp) elif sKey == 'rule': for sRule in tempConfiguration[sKey]: From f7902a59d911f3cd0f8125f6113ecc79bd416ec0 Mon Sep 17 00:00:00 2001 From: Jeremiah C Leary Date: Sat, 21 Mar 2020 09:24:35 -0500 Subject: [PATCH 5/8] Attempting to reduce complexity in function update_command_line_arguments. --- vsg/__main__.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/vsg/__main__.py b/vsg/__main__.py index 72e2f562..e769b417 100644 --- a/vsg/__main__.py +++ b/vsg/__main__.py @@ -128,17 +128,19 @@ def write_junit_xml_file(oJunitFile): def update_command_line_arguments(commandLineArguments, configuration): - if configuration: - if 'file_list' in configuration: - for sFilename in configuration['file_list']: - if isinstance(sFilename, dict): - sFilename = list(sFilename.keys())[0] - try: - commandLineArguments.filename.extend(glob.glob(expand_filename(sFilename))) - except: - commandLineArguments.filename = glob.glob(expand_filename(sFilename)) - if 'local_rules' in configuration: - commandLineArguments.local_rules = expand_filename(configuration['local_rules']) + if not configuration: + return + + if 'file_list' in configuration: + for sFilename in configuration['file_list']: + if isinstance(sFilename, dict): + sFilename = list(sFilename.keys())[0] + try: + commandLineArguments.filename.extend(glob.glob(expand_filename(sFilename))) + except: + commandLineArguments.filename = glob.glob(expand_filename(sFilename)) + if 'local_rules' in configuration: + commandLineArguments.local_rules = expand_filename(configuration['local_rules']) def expand_filename(sFileName): From 6180366a017ccff993075a8b53f26c31f2543f6d Mon Sep 17 00:00:00 2001 From: Jeremiah C Leary Date: Sat, 21 Mar 2020 09:43:42 -0500 Subject: [PATCH 6/8] Attempting to fix Travis CI issue when comparing dictionaries. --- .../test_read_configuration_files_function.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py b/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py index bf0561fa..c2c90be3 100644 --- a/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py +++ b/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py @@ -35,7 +35,7 @@ class test_read_configuration_function(unittest.TestCase): dActual = read_configuration_files(oCommandLineArgs) - self.assertEqual(dActual, dExpected) + self.assertDictEqual(dActual, dExpected) def test_globbing_files(self): @@ -52,7 +52,7 @@ class test_read_configuration_function(unittest.TestCase): dActual = read_configuration_files(oCommandLineArgs) - self.assertEqual(dActual, dExpected) + self.assertDictEqual(dActual, dExpected) def test_file_list_with_individual_rule_config(self): self.maxDiff = None @@ -71,7 +71,7 @@ class test_read_configuration_function(unittest.TestCase): dActual = read_configuration_files(oCommandLineArgs) - self.assertEqual(dActual, dExpected) + self.assertDictEqual(dActual, dExpected) def test_file_list_globbing_with_individual_rule_config(self): self.maxDiff = None @@ -101,4 +101,4 @@ class test_read_configuration_function(unittest.TestCase): dActual = read_configuration_files(oCommandLineArgs) - self.assertEqual(dActual, dExpected) + self.assertDictEqual(dActual, dExpected) From 3939e7c9488eac2bc82c077abe3ca962bbe44175 Mon Sep 17 00:00:00 2001 From: Jeremiah C Leary Date: Sat, 21 Mar 2020 09:56:59 -0500 Subject: [PATCH 7/8] Attempting to fix Travis CI issues. --- .../test_read_configuration_files_function.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py b/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py index c2c90be3..41ad20d2 100644 --- a/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py +++ b/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py @@ -29,12 +29,15 @@ class test_read_configuration_function(unittest.TestCase): dExpected = {} dExpected['file_list'] = [] - dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/entity.vhd') dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/arch.vhd') + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/entity.vhd') dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/package.vhd') dActual = read_configuration_files(oCommandLineArgs) + dExpected['file_list'].sort() + dActual['file_list'].sort() + self.assertDictEqual(dActual, dExpected) @@ -46,12 +49,15 @@ class test_read_configuration_function(unittest.TestCase): dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/package.vhd') dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/entity_2.vhd') dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/arch_2.vhd') - dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/package_2.vhd') dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/arch.vhd') + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/package_2.vhd') dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/entity.vhd') dActual = read_configuration_files(oCommandLineArgs) + dExpected['file_list'].sort() + dActual['file_list'].sort() + self.assertDictEqual(dActual, dExpected) def test_file_list_with_individual_rule_config(self): From 3d391ff6d2b1b0164473a2b6e3de2f76cf875db6 Mon Sep 17 00:00:00 2001 From: Jeremiah C Leary Date: Sat, 21 Mar 2020 11:03:37 -0500 Subject: [PATCH 8/8] Attempting to fix Travis CI issue: 1) rewrote unittest so it doesn't care about order in a list. --- .../test_read_configuration_files_function.py | 55 ++++++++++++++++++- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py b/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py index 41ad20d2..34908c9c 100644 --- a/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py +++ b/vsg/tests/vsg/read_configuration_files/test_read_configuration_files_function.py @@ -6,6 +6,13 @@ import os from vsg.tests import utils from vsg.__main__ import read_configuration_files +def get_index_of_dictionary_in_list(lList, sKey): + for iIndex, item in enumerate(lList): + if isinstance(item, dict): + sMyKey = list(item.keys())[0] + if sMyKey == sKey: + return iIndex + return None class command_line_args(): @@ -77,7 +84,26 @@ class test_read_configuration_function(unittest.TestCase): dActual = read_configuration_files(oCommandLineArgs) - self.assertDictEqual(dActual, dExpected) + lExpected = [] + for item in dExpected['file_list']: + if not isinstance(item, dict): + lExpected.append(item) + lExpected.sort() + + lActual = [] + for item in dActual['file_list']: + if not isinstance(item, dict): + lActual.append(item) + lActual.sort() + + self.assertEqual(lActual, lExpected) + + for iIndex, item in enumerate(dExpected['file_list']): + if isinstance(item, dict): + sKey = list(item.keys())[0] + iActualIndex = get_index_of_dictionary_in_list(dActual['file_list'], sKey) + self.assertEqual(dActual['file_list'][iActualIndex], dExpected['file_list'][iIndex]) + def test_file_list_globbing_with_individual_rule_config(self): self.maxDiff = None @@ -85,19 +111,21 @@ class test_read_configuration_function(unittest.TestCase): dExpected = {} dExpected['file_list'] = [] - dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/entity.vhd') + dFile = {} dFile['vsg/tests/vsg/read_configuration_files/arch_2.vhd'] = {} dFile['vsg/tests/vsg/read_configuration_files/arch_2.vhd']['rule'] = {} dFile['vsg/tests/vsg/read_configuration_files/arch_2.vhd']['rule']['rule_001'] = {} dFile['vsg/tests/vsg/read_configuration_files/arch_2.vhd']['rule']['rule_001']['disable'] = True dExpected['file_list'].append(dFile) + dFile = {} dFile['vsg/tests/vsg/read_configuration_files/arch.vhd'] = {} dFile['vsg/tests/vsg/read_configuration_files/arch.vhd']['rule'] = {} dFile['vsg/tests/vsg/read_configuration_files/arch.vhd']['rule']['rule_001'] = {} dFile['vsg/tests/vsg/read_configuration_files/arch.vhd']['rule']['rule_001']['disable'] = True dExpected['file_list'].append(dFile) + dFile = {} dFile['vsg/tests/vsg/read_configuration_files/package.vhd'] = {} dFile['vsg/tests/vsg/read_configuration_files/package.vhd']['rule'] = {} @@ -105,6 +133,27 @@ class test_read_configuration_function(unittest.TestCase): dFile['vsg/tests/vsg/read_configuration_files/package.vhd']['rule']['rule_002']['disable'] = False dExpected['file_list'].append(dFile) + dExpected['file_list'].append('vsg/tests/vsg/read_configuration_files/entity.vhd') + dActual = read_configuration_files(oCommandLineArgs) - self.assertDictEqual(dActual, dExpected) + lExpected = [] + for item in dExpected['file_list']: + if not isinstance(item, dict): + lExpected.append(item) + lExpected.sort() + + lActual = [] + for item in dActual['file_list']: + if not isinstance(item, dict): + lActual.append(item) + lActual.sort() + + self.assertEqual(lActual, lExpected) + + for iIndex, item in enumerate(dExpected['file_list']): + if isinstance(item, dict): + sKey = list(item.keys())[0] + iActualIndex = get_index_of_dictionary_in_list(dActual['file_list'], sKey) + self.assertEqual(dActual['file_list'][iActualIndex], dExpected['file_list'][iIndex]) +