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

Jython: ImportError: No module named pkg_resources #9

Closed
Stewori opened this issue Jul 6, 2017 · 11 comments
Closed

Jython: ImportError: No module named pkg_resources #9

Stewori opened this issue Jul 6, 2017 · 11 comments

Comments

@Stewori
Copy link
Owner

Stewori commented Jul 6, 2017

This is probably a Jython issue, but I'd like to have a fallback, since pytypes used to work with Jython apart from this.
As far as I understand, this is about some functionality of setuptools.
I didn't explicitly run setup.py on Jython, so something might be ill-configured.
However, I also didn't do such a thing on CPython, but there it runs out of the box.

How to fix it?

@Stewori
Copy link
Owner Author

Stewori commented Jul 6, 2017

Note: I tried it with jython-standalone and after using the installer.
With the installer, the error is different, but also biols down to pkg_resources:

'/home/stefan/jython2.7.1/bin/jython' tests/test_typechecker.py
Traceback (most recent call last):
  File "tests/test_typechecker.py", line 28, in <module>
    import pytypes
  File "/data/workspace/linux/pytypes/pytypes/__init__.py", line 560, in <module>
    from .typelogger import dump_cache, log_type, typelogged, typelogged_module, \
  File "/data/workspace/linux/pytypes/pytypes/typechecker.py", line 62, in _pytypes___import__
    res = _python___import__(name, globls, locls, fromlist, level)
  File "/data/workspace/linux/pytypes/pytypes/typelogger.py", line 30, in <module>
    import pkg_resources
  File "/data/workspace/linux/pytypes/pytypes/typechecker.py", line 62, in _pytypes___import__
    res = _python___import__(name, globls, locls, fromlist, level)
  File "/home/stefan/jython2.7.1/Lib/site-packages/pkg_resources/__init__.py", line 74, in <module>
    __import__('pkg_resources.extern.packaging.requirements')
  File "/data/workspace/linux/pytypes/pytypes/typechecker.py", line 62, in _pytypes___import__
    res = _python___import__(name, globls, locls, fromlist, level)
  File "/home/stefan/jython2.7.1/Lib/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 9, in <module>
    from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
  File "/data/workspace/linux/pytypes/pytypes/typechecker.py", line 62, in _pytypes___import__
    res = _python___import__(name, globls, locls, fromlist, level)
  File "/home/stefan/jython2.7.1/Lib/site-packages/pkg_resources/extern/__init__.py", line 43, in load_module
    __import__(extant)
  File "/home/stefan/jython2.7.1/Lib/site-packages/pkg_resources/extern/__init__.py", line 43, in load_module
    __import__(extant)
  File "/data/workspace/linux/pytypes/pytypes/typechecker.py", line 62, in _pytypes___import__
    res = _python___import__(name, globls, locls, fromlist, level)
  File "/home/stefan/jython2.7.1/Lib/site-packages/pkg_resources/_vendor/pyparsing.py", line 4720, in <module>
    _reBracketExpr = Literal("[") + Optional("^").setResultsName("negate") + Group( OneOrMore( _charRange | _singleChar ) ).setResultsName("body") + "]"
  File "/home/stefan/jython2.7.1/Lib/site-packages/pkg_resources/_vendor/pyparsing.py", line 1201, in setResultsName
    newself = self.copy()
  File "/home/stefan/jython2.7.1/Lib/site-packages/pkg_resources/_vendor/pyparsing.py", line 1160, in copy
    cpy = copy.copy( self )
  File "/home/stefan/jython2.7.1/Lib/copy.py", line 88, in copy
    rv = reductor(2)
  File "/data/workspace/linux/pytypes/pytypes/typechecker.py", line 62, in _pytypes___import__
    res = _python___import__(name, globls, locls, fromlist, level)
UnboundLocalError: local variable 'globls' referenced before assignment

If I remove pkg_resources from typelogger.py and set the version to some constant, both variants pass again.

@agronholm
Copy link
Collaborator

Jython does come with setuptools preinstalled, does it not? Installing it normally should make it work. I don't quite understand how the above error relates to pkg_resources.

@agronholm
Copy link
Collaborator

On second look, I see that importing pkg_resources causes the pytypes code to be imported. This is an import order issue. I'll look into it.

agronholm added a commit to agronholm/pytypes that referenced this issue Jul 8, 2017
@Stewori
Copy link
Owner Author

Stewori commented Jul 8, 2017

That fixed the issue in principle, thank you.
However, it does not work with Jython-standalone.jar. I guess only the installer pre-installs setuptools.
I find the version string not important enough to break workability with jython-standalone.jar, so I will add some fallback (i.e. hard-coded version-string), unless we see a better solution.
Also, if we find a better solution over time, we can fix this later.

Do you know if it's possible to include Jython into travis tests?

@Stewori Stewori reopened this Jul 8, 2017
@agronholm
Copy link
Collaborator

From Travis documentation:

Python 2.4 and Jython are not supported and there are no plans to support them in the future.

@agronholm
Copy link
Collaborator

So I'd say it's possible but not without some degree of hacking.

@agronholm
Copy link
Collaborator

There is an alternative to setuptools_scm, named pbr but it adds its own complexity to the build process. The upside is that it doesn't require pkg_resources at runtime.

@Stewori
Copy link
Owner Author

Stewori commented Jul 8, 2017

Okay, let's stick to setuptools_scm now. You'll probably not like the workaround in 872bd33, I also don't like it.
Still I think this hack is an acceptable price for getting it work with jython-standalone; at least at the moment.
If you don't have further concerns, I'd file a release soon (just writing the release notes...)

@agronholm
Copy link
Collaborator

agronholm commented Jul 8, 2017

Re: authors/notices: yeah, looks okay to me.

@agronholm
Copy link
Collaborator

Anyways, the hack is ugly but it doesn't matter if it's just temporary workaround.

@Stewori
Copy link
Owner Author

Stewori commented Jul 8, 2017

Seems like I broke travis with the assert. Removed it as of d07414f
This can be closed for now I'd say.

@Stewori Stewori closed this as completed Jul 8, 2017
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

No branches or pull requests

2 participants