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

Some fixes to the magic import system #349

Merged
merged 1 commit into from
Nov 25, 2023

Conversation

LasseBlaauwbroek
Copy link
Contributor

@LasseBlaauwbroek LasseBlaauwbroek commented Nov 24, 2023

  • Stop adding the directory of every .capnp file to the import path. If a .capnp file wants to import a file in its own directory, it should use a relative import. Fixes Absolute import causes duplicate ID #278
  • Stop using /usr/include/capnp as an import path. This is incorrect. It should only be /usr/include. People that want to import, for example, rpc.capnp should do import capnp.rpc_capnp instead of import rpc_capnp. This fixes another bug similar to Absolute import causes duplicate ID #278.
  • Stop allowing additional paths to be specified for magic imports. This leads to inconsistencies. More specifically, the way that a nested import like ma.mb.mc_capnp gets imported by python, is to first import ma, then import ma.mb, and finally ma.mb.mc_capnp. Pycapnp's magic importing is only involved in the last step. So any additional paths specified don't work for nested imports. It is very confusing to only have this for non-nested imports. Users with folder layouts that don't follow pythons import paths can still use capnp.load(.., .., imports=[blah]).

Possibly this is also a fix for #279 but I cannot verify that.

- Stop adding the directory of every .capnp file to the import path. If a .capnp
  file wants to import a file in its own directory, it should use a relative
  import. Fixes capnproto#278
- Stop using /usr/include/capnp as an import path. This is incorrect. It should
  only be /usr/include.
- Stop allowing additional paths to be specified for magic imports. This leads
  to inconsistencies. More specifically, the way that a nested import like
  `ma.mb.mc_capnp` gets imported by python, is to first import `ma`, then import
  `ma.mb`, and finally `ma.mb.mc_capnp`. Pycapnp's magic importing is only
  involved in the last step. So any additional paths specified don't work for
  nested imports. It is very confusing to only have this for non-nested imports.
  Users with folder layouts that don't follow pythons import paths can still use
  `capnp.load(.., .., imports=[blah])`.
@haata
Copy link
Collaborator

haata commented Nov 25, 2023

Thanks for fixing this!

@haata haata merged commit 3aade70 into capnproto:master Nov 25, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Absolute import causes duplicate ID
2 participants