sigma-geosistemas / mommy_spatial_generators

Model mommy spatial fields generators
BSD 3-Clause "New" or "Revised" License
14 stars 4 forks source link

No module named 'generators' #3

Closed fletort closed 8 years ago

fletort commented 8 years ago

Since this commit : https://github.com/sigma-geosistemas/mommy_spatial_generators/commit/a9923549ae65dd8240528a3c3790ce326e8fcd87

When i make from mommy_spatial_generators import MOMMY_SPATIAL_FIELDS

i get this error: File "/usr/django/src/mommy-spatial-generators/mommy_spatial_generators/__init__.py", line 2, in <module> from generators import MOMMY_SPATIAL_FIELDS ImportError: No module named 'generators'

george-silva commented 8 years ago

Hello @fletort . Check the new version. I updated it and then forgot to keep this in __init__.py, but I quickly fixed it.

Can you test this again ?

I just made new virtualenv and did the following:

Created new venv:

(geoadmin) george@winterfell ~/projetos $ mkvirtualenv mommy
Using real prefix '/usr'
New python executable in /home/george/projetos/.virtualenvs/mommy/bin/python2
Also creating executable in /home/george/projetos/.virtualenvs/mommy/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/george/projetos/.virtualenvs/mommy/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/george/projetos/.virtualenvs/mommy/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/george/projetos/.virtualenvs/mommy/bin/preactivate
virtualenvwrapper.user_scripts creating /home/george/projetos/.virtualenvs/mommy/bin/postactivate
virtualenvwrapper.user_scripts creating /home/george/projetos/.virtualenvs/mommy/bin/get_env_details

Installed Django and Model Mommy

(mommy) george@winterfell ~/projetos $ pip install django model_mommy 
Collecting django
  Downloading Django-1.10.2-py2.py3-none-any.whl (6.8MB)
    100% |████████████████████████████████| 6.8MB 146kB/s 
Collecting model_mommy
  Using cached model_mommy-1.3.0.tar.gz
Collecting six (from model_mommy)
  Using cached six-1.10.0-py2.py3-none-any.whl
Building wheels for collected packages: model-mommy
  Running setup.py bdist_wheel for model-mommy ... done
  Stored in directory: /home/george/.cache/pip/wheels/b3/81/ca/387a31885c6bedcbdc2a4efd3a3808db244415388088ecdc48
Successfully built model-mommy
Installing collected packages: django, six, model-mommy
Successfully installed django-1.10.2 model-mommy-1.3.0 six-1.10.0

Installed Mommy Spatial Generators

(mommy) george@winterfell ~/projetos $ pip install -e git+https://github.com/sigma-geosistemas/mommy_spatial_generators.git#egg=mommy_spatial_generators
Obtaining mommy_spatial_generators from git+https://github.com/sigma-geosistemas/mommy_spatial_generators.git#egg=mommy_spatial_generators
  Cloning https://github.com/sigma-geosistemas/mommy_spatial_generators.git to ./.virtualenvs/mommy/src/mommy-spatial-generators
Installing collected packages: mommy-spatial-generators
  Running setup.py develop for mommy-spatial-generators
Successfully installed mommy-spatial-generators

Testing:

(mommy) george@winterfell ~/projetos $ python
Python 2.7.12 (default, Jul  1 2016, 15:12:24) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from mommy_spatial_generators import MOMMY_SPATIAL_FIELDS
>>> MOMMY_SPATIAL_FIELDS
{'django.contrib.gis.db.models.LineStringField': <function gen_linestring at 0x7fea32e659b0>, 'django.contrib.gis.db.models.PolygonField': <function gen_rectangular_polygon at 0x7fea32e65b18>, 'django.contrib.gis.db.models.MultiPointField': <function gen_multipoint at 0x7fea32e65938>, 'django.contrib.gis.db.models.PointField': <function gen_point at 0x7fea32e65848>, 'django.contrib.gis.db.models.MultiLineStringField': <function gen_multilinestring at 0x7fea32e65aa0>, 'django.contrib.gis.db.models.MultiPolygonField': <function gen_rectangular_multipolygon at 0x7fea32e65b90>}
fletort commented 8 years ago

it is not ok for me:

root@adea552c15c0:/usr/django# python
Python 3.5.2 (default, Aug 31 2016, 03:01:41) 
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from mommy_spatial_generators import MOMMY_SPATIAL_FIELDS
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/site-packages/mommy_spatial_generators/__init__.py", line 2, in <module>
    from generators import MOMMY_SPATIAL_FIELDS
ImportError: No module named 'generators'
fletort commented 8 years ago

In fact generators is not a module so it can not be imported. Your import line in your init/py file should be:

from mommy_spatial_generators.generators import MOMMY_SPATIAL_FIELDS

george-silva commented 8 years ago

I was importing it before using relative notation and when I "fixed" I must forgot the dot.

The weird thing is that it's working for me here.

I'll change it and let me know if works for you.

george-silva commented 8 years ago

@fletort added a test case for importing this also. please check and thanks for the bug report.