Scout24 / yamlreader

Read all YAML files in a directory and merge them
Apache License 2.0
45 stars 14 forks source link

Default install of yamlreader from pip causes ImportError ( __main) #9

Closed michael-dev2rights closed 7 years ago

michael-dev2rights commented 7 years ago

If I try installing yamlreader on my Ubuntu system into a virtualenv it fails to work properly with an install. I get the error

Traceback (most recent call last):
  File "/tmp/test-yamlreader/bin/yamlreader", line 7, in <module>
    from yamlreader import __main
ImportError: cannot import name __main

I'd expect a default install to work fine.

NAME="Ubuntu" VERSION="16.04.1 LTS (Xenial Xerus)"

Here's a log from the install.

mikedd@carla /tmp> virtualenv test-yamlreader
Running virtualenv with interpreter /usr/bin/python2
New python executable in /tmp/test-yamlreader/bin/python2
Also creating executable in /tmp/test-yamlreader/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
(test-yamlreader) mikedd@carla /tmp> pip install yamlreader
]Collecting yamlreader
Collecting PyYAML (from yamlreader)
Collecting six (from yamlreader)
  Using cached six-1.10.0-py2.py3-none-any.whl
Installing collected packages: PyYAML, six, yamlreader
Successfully installed PyYAML-3.12 six-1.10.0 yamlreader-3.0.2
(test-yamlreader) mikedd@carla /tmp> yamlreader 
Traceback (most recent call last):
  File "/tmp/test-yamlreader/bin/yamlreader", line 7, in <module>
    from yamlreader import __main
ImportError: cannot import name __main
michael-dev2rights commented 7 years ago

(test-yamlreader) mikedd@carla /tmp> python --version Python 2.7.12

mriehl commented 7 years ago

Your install is not broken. The import stanza is not right, which is your problem.

When you do

from yamlreader import ...

you hit the __init__.py in the yamlreader module (the folder in src/main/python in this git repository). This file doesn't have a __main. It imports data_merge, yaml_load, YamlReaderError from yamlreader.py (using from .yamlreader import ...) though so you could import these symbols.

If you want something from the module (yamlreader.py as opposed to the package, yamlreader with an __init__.py) you need to import from the module, not from the package.

e.G. from yamlreader.yamlreader import __main

Does that make sense? Python's import syntax can be confusing and here it doesn't help that the module has the same name as the package. If the package was named lib you'd do from lib.yamlreader import __main which is clearer I guess.

mriehl commented 7 years ago

I'm closing this since

from yamlreader.yamlreader import __main

solves the issue. If you need more help or this didn't fix your problem, feel free to reopen!

michael-dev2rights commented 7 years ago

This isn't my code. It's the yamlreader command line tool.

michael-dev2rights commented 7 years ago

Unfortunately I can't reopen this issue. You need to be a repository collaborator to do that. @mriehl could you please reopen the ticket.

mriehl commented 7 years ago

Oh, you're right. I totally misread the issue, sorry. I think it's just that the setuptools entry point configuration fails to fully qualify the module, I'll fix it today. Thanks for reporting.

On 17 Jan 2017, at 20:42, Michael De La Rue notifications@github.com wrote:

Unfortunately I can't reopen this issue. You need to be a repository collaborator to do that. @mriehl could you please reopen the ticket.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

mriehl commented 7 years ago

I've fixed it. But I don't have permissions to release on PyPI. @snordhausen could you do a release or setup travis upload?

snordhausen commented 7 years ago

The fixed version is now on Pypi (I bumped the version number, this made our internal build pass).