Problem Description
Currently any rule file used in an NsiqCppStyle session (e.g., RULE_3_1_A_do_not_start_filename_with_underbar) must reside in the nsiqcppstyle\rules package folder. You can see this in nsiqcppstyle_runmanager.py:
def LoadRules(self, checkingRuleNames):
...
for ruleName in checkingRuleNames:
ruleModule = __import__("rules." + ruleName)
self.loadedRule.append(ruleModule)
...
I have written many proprietary rules that I do not want to return to the NsiqCppStyle repository. To include them in my NsiqCppStyle checking runs, I must copy my rules to the rules folder. Should I upgrade NsiqCppStyle to a newer version I may need to copy all of my proprietary rules again. Should I push changes through a GitHub pull request, I have to be careful not to add my proprietary rules to the commit. In general, I want to keep my proprietary rules totally separate from the NsiqCppStyle package.
Proposed Solution
The proposal is to support a new command-line option for specifying one or more additional paths that should be searched for rules. These paths can be anywhere in the file system. For all rule names in the filefilter.txt file, NsiqCppStyle should search first the rules folder, followed by any additional folders. If found, the engine should import the rule file. The following Stack Overflow post provides Python code that can be used to import the rule file from anywhere. Here is a test script I wrote:
d:\junk\import-from-anywhere\main.py
import importlib.util
import sys
spec = importlib.util.spec_from_file_location("test.py", "d:\\junk\\test.py")
foo = importlib.util.module_from_spec(spec)
sys.modules["test.py"] = foo
spec.loader.exec_module(foo)
print("foobar=%d" % (foo.foobar))
d:\junk\test.py
Running main.py shows the import in action:
D:\Junk\NsiqCppStyle\Import-From-Anywhere>python main.py
foobar=5
Problem Description
Currently any rule file used in an NsiqCppStyle session (e.g.,
RULE_3_1_A_do_not_start_filename_with_underbar) must reside in thensiqcppstyle\rulespackage folder. You can see this in nsiqcppstyle_runmanager.py:I have written many proprietary rules that I do not want to return to the NsiqCppStyle repository. To include them in my NsiqCppStyle checking runs, I must copy my rules to the
rulesfolder. Should I upgrade NsiqCppStyle to a newer version I may need to copy all of my proprietary rules again. Should I push changes through a GitHub pull request, I have to be careful not to add my proprietary rules to the commit. In general, I want to keep my proprietary rules totally separate from the NsiqCppStyle package.Proposed Solution
The proposal is to support a new command-line option for specifying one or more additional paths that should be searched for rules. These paths can be anywhere in the file system. For all rule names in the
filefilter.txtfile, NsiqCppStyle should search first therulesfolder, followed by any additional folders. If found, the engine should import the rule file. The following Stack Overflow post provides Python code that can be used to import the rule file from anywhere. Here is a test script I wrote:d:\junk\import-from-anywhere\main.py
d:\junk\test.py
Running main.py shows the import in action: