robotframework-robocop icon indicating copy to clipboard operation
robotframework-robocop copied to clipboard

[Bug] Can't do relative imports in custom rules folder

Open Lakitna opened this issue 4 months ago • 1 comments

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:

robocop_rules/
- keyword_name_checker.py
- keyword_name_parser.py
# keyword_name_checker.py

from .keyword_name_parser import KeywordNameParser
# keyword_name_parser.py

class KeywordNameParser:
  pass

Running Robocop with this code will cause Python to raise the following error:

ImportError: attempted relative import with no known parent package

Changing the import line to the following also does not work:

# keyword_name_checker.py

from robocop_rules.keyword_name_parser import KeywordNameParser
ModuleNotFoundError: No module named 'robocop_rules'

And this is also no dice

# keyword_name_checker.py

from keyword_name_parser import KeywordNameParser
ModuleNotFoundError: No module named 'keyword_name_parser'

What command/code did you try to run?

robocop .

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

Lakitna avatar Oct 15 '24 15:10 Lakitna