python-betterproto icon indicating copy to clipboard operation
python-betterproto copied to clipboard

Issue importing structures between files in subpackages

Open danni opened this issue 5 years ago • 3 comments

Given a file like...

import "badger/mushroom";

package badger.snake;

message Snake {
  badger.mushroom.Mushroom mushroom = ...;
}

This results in compiling a badger/snake.py which includes the line from .badger import mushroom instead of from . import mushroom.

danni avatar Oct 08 '20 04:10 danni

I am seeing this as well in v1.2.5. Given:

  • proj/pkg1/pkg1.proto
    import "proj/pkg2/pkg2.proto";
    
    package proj.pkg1;
    
    message Test1 {
      proj.pkg2.Test2 test = 1;
    }
    
  • proj/pkg2/pkg2.proto
    package proj.pkg2;
    
    message Test2 {
      string test = 1;
    }
    

The generated proj/pkg1/pkg1.py has:

# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: proj/pkg1/mapping.proto
# plugin: python-betterproto
from dataclasses import dataclass
from typing import Dict, List

import betterproto

from .proj import pkg2

When it should either be from .. import pkg2 or from proj import pkg2

shaunco avatar Dec 02 '20 10:12 shaunco

Is this still an issue on V2.0.0b2?

Gobot1234 avatar Dec 02 '20 12:12 Gobot1234

Is this still an issue on V2.0.0b2?

v2.0.0b2 packs everything for each package in to the __init__.py file and seems to have solved the parent/cousin import issues.

shaunco avatar Dec 03 '20 09:12 shaunco