Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

args: ImportError('attempted relative import with no known parent package') #2805

Closed
ssbarnea opened this issue Dec 10, 2022 · 1 comment · Fixed by #2813
Closed

args: ImportError('attempted relative import with no known parent package') #2805

ssbarnea opened this issue Dec 10, 2022 · 1 comment · Fixed by #2813
Assignees
Labels

Comments

@ssbarnea
Copy link
Member

ssbarnea commented Dec 10, 2022

I discovered that our newly args module is something throwing some weird Import Errors, and this time I found the culprit is ansible-core, which for some very weird reasons was using a relative import in the cose, which is a known issue.

https://github.com/ansible/ansible-lint/blob/main/src/ansiblelint/rules/args.py#L88

Replacing the relative import with a full import sorted the issue. Clearly we need to sort this in core and introduce a measure for preventing use of relative imports in the future.

https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/setup.py#L175

One pleasant surprise is that this is the only relative import from lib, there are others inside tests but on code that ships, that is the only one.

@ssbarnea ssbarnea added new Triage required bug labels Dec 10, 2022
ssbarnea added a commit to ssbarnea/ansible that referenced this issue Dec 10, 2022
@ssbarnea ssbarnea removed the new Triage required label Dec 10, 2022
@webknjaz
Copy link
Member

The problem is that the low-level machinery is used and it does not specify ansible as a top-level package so the loader assumes that what you're importing must be top-level already.
Higher-level functions like import_module() or find_spec() have a package argument for specifying what is top-level. If you want to keep using the low-level API, you'll need to find a way to specify where the top-level package is too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants