jazzband / geojson

Python bindings and utilities for GeoJSON
https://pypi.python.org/pypi/geojson/
BSD 3-Clause "New" or "Revised" License
908 stars 120 forks source link

Circular reference on module import #71

Closed tiktaalik-dev closed 5 years ago

tiktaalik-dev commented 8 years ago

Hello there,

I'm experiencing an endless sequence of Import Errors because there's several circular references between base.py, codec.py, factory.py and mapping.py.

I'm at the end of my tether trying to make them work as they are so I reckon I'll just merge those files into one.

I'd recommend for you to rearrange the classes in a way that prevent this from happening.

Anyway, thanks for making available this library! :-)

Cheers, Rodrigo Gambra

whelks-chance commented 6 years ago

Very old thread, but did you figure this out? Importing geojson is complaining about failing to find codecs, which imports geojson etc etc

There may be another conflict with django-geojson, which I'm also going in circles with.

rayrrr commented 5 years ago

If someone could post a gist/code snippet of exactly how this is happening, along with a note about the Python version being used, that would be helpful.

rayrrr commented 5 years ago

This is going to be fun. geojson-circular-imports

tiktaalik-dev commented 5 years ago

Hey there, Sorry for the very late reply to this thread. It has been in my mind but kept forgetting to reply before. In the end what I did was to merge all the classes in a single file and that solved the problem. I was using Python 2.7 for that project so I didn't check if it worked fine in Python 3.

In case you may want to check my fix you can find it here (though bear in mind that's code from a version you made available 4 years ago): https://github.com/doctortoffu/python-geojson/tree/simplified/simplified_version

Hope it helps, cheers. Rigo.

rayrrr commented 5 years ago

@doctortoffu thanks! I was trying to reproduce this with Python 2.7 and the current version of geojson on PyPi (2.4.1) and was unable to do so. Although some circular refs still exist here, they do not seem to be causing ImportError exceptions any more...perhaps the issue was resolved since the version you experienced it with. I know it was a long time ago, but any chance you can reproduce this? Otherwise I am going to just close out this thread for now and handle circular ref removal during a future code cleanup effort.

tiktaalik-dev commented 5 years ago

Hi @rayrrr, My guess is that you guys probably solved this problem over this last 4 years, as I see that your code has 155 commits ahead since I forked it out :-) I reckon you could close this thread for now. At some point I have to update the code of my project to use Python 3.7, which will require quite a bit of rewriting because of several libraries that were not migrated to Python 3. So when I do, I'll grab again a new version of your library and surely test how it goes. Thanks again for this awesome library!

Cheers, Rigo.

rayrrr commented 5 years ago

Good stuff, Rigo. geojson already supports Python 3.7 so you should be good to go when the time comes. Thanks for letting us know!