Open Lakitna opened 2 weeks ago
I have looked into this a bit and found a potential solution to this issue. However, it does not solve the relative import version.
The solution adds a few things to this function: https://github.com/MarketSquare/robotframework-robocop/blob/master/robocop/checkers/__init__.py#L200-L201
def get_external_modules(self):
+ for ext_rule_path in self.external_rules_paths:
+ sys.path.append(str(Path(ext_rule_path).parent))
+ sys.path.append(ext_rule_path)
+
return self.modules_from_paths([*self.external_rules_paths], recursive=True)
It's a bit of a hacky solution though. With this change, the following imports are supported:
# keyword_name_checker.py
import robocop_rules.sub_folder.keyword_name_parser
import sub_folder.keyword_name_parser
import keyword_name_parser
Where robocop_rules
is my external rules folder.
If you can't think of a nicer solution, I can make a PR to see if this change impacts any tests.
What happened?
I have a bunch of custom rules that only make sense for our organization/situation. But it can be a real pain to structure code written for custom rules.
As an example: I'm working on custom rules related to keyword names. For this, I wrote a keyword name parser to simplify the rule code. I want to use this like so:
Running Robocop with this code will cause Python to raise the following error:
Changing the import line to the following also does not work:
And this is also no dice
What command/code did you try to run?
What is the full error message?
See above
What did you expect to happen instead?
I expect the ability to import python files.
Operating System
Windows
Robocop version
5.4.0