abarker / camel-snake-pep8

Use Rope to help convert names in a Python project to conform with PEP-8.
MIT License
49 stars 4 forks source link

Conflicting information in readme vs py file #3

Closed isaacegglestone closed 4 years ago

isaacegglestone commented 4 years ago

Cool project!

Just having some problems here with running this under python3:

The camel_snake_pep8.py file says: "Currently only runs on Python 2, but can refactor Python 2 and Python 3." https://github.com/abarker/camel-snake-pep8/blob/5d2182738b2bfdfc02221a5ea091207382bb897b/src/camel_snake_pep8/camel_snake_pep8.py#L13

However the document says: The program can be used to refactor either Python 2 or Python 3 code. Run the program with the same version of Python as the code that is being modified. That is, if the code being modified is Python 2 code then run the program with python2, and similarly for Python 3.

Which is confusing because which is it?

When attempting to run with latest python3 docker container and latest rope for python3 I get the following error message:

Hit enter to begin the refactoring...

Analyzing all the modules in the project, may be slow...

============================================================================== ===== Doing post-processing name analysis on all modules. ====================

==============================================================================

Any warnings below are only for potential problems. Most will probably not be problems. No scoping information is taken into account in this analysis.


----- User-rejected change information. --------------------------------------


----- Rope-rejected change information. --------------------------------------


----- Accepted change information. -------------------------------------------

Traceback (most recent call last): File "/common/utils/camel_snake-pep8.py", line 857, in main() File "/common/utils/camel_snake-pep8.py", line 801, in main rope.base.libutils.analyze_modules(project) # Analyze all the modules. File "/usr/local/lib/python3.8/site-packages/rope/base/libutils.py", line 81, in analyze_modules analyze_module(project, resource) File "/usr/local/lib/python3.8/site-packages/rope/base/libutils.py", line 69, in analyze_module project.pycore.analyze_module(resource) File "/usr/local/lib/python3.8/site-packages/rope/base/pycore.py", line 209, in analyze_module rope.base.oi.soa.analyze_module( File "/usr/local/lib/python3.8/site-packages/rope/base/oi/soa.py", line 15, in analyze_module _analyze_node(pycore, pymodule, should_analyze, File "/usr/local/lib/python3.8/site-packages/rope/base/oi/soa.py", line 23, in _analyze_node _analyze_node(pycore, scope.pyobject, should_analyze, File "/usr/local/lib/python3.8/site-packages/rope/base/oi/soa.py", line 38, in _analyze_node rope.base.ast.walk(child, visitor) File "/usr/local/lib/python3.8/site-packages/rope/base/ast.py", line 41, in walk walk(child, walker) File "/usr/local/lib/python3.8/site-packages/rope/base/ast.py", line 41, in walk walk(child, walker) File "/usr/local/lib/python3.8/site-packages/rope/base/ast.py", line 39, in walk return method(node) File "/usr/local/lib/python3.8/site-packages/rope/base/oi/soa.py", line 76, in _Call self._call(pyfunction, args) File "/usr/local/lib/python3.8/site-packages/rope/base/oi/soa.py", line 96, in _call pyfunction.get_returned_object(args) File "/usr/local/lib/python3.8/site-packages/rope/base/builtins.py", line 108, in get_returned_object return self.function(_CallContext(self.argnames, args)) File "/usr/local/lib/python3.8/site-packages/rope/base/builtins.py", line 730, in _open_function return _create_builtin(args, get_file) File "/usr/local/lib/python3.8/site-packages/rope/base/builtins.py", line 722, in _create_builtin holding = _infer_sequence_for_pyname(passed) File "/usr/local/lib/python3.8/site-packages/rope/base/builtins.py", line 704, in _infer_sequence_for_pyname seq = pyname.get_object() File "/usr/local/lib/python3.8/site-packages/rope/base/pynamesdef.py", line 42, in get_object result = self.pyfunction.get_parameter(self.index) File "/usr/local/lib/python3.8/site-packages/rope/base/pyobjectsdef.py", line 69, in get_parameter if index < len(self.parameter_pyobjects.get()): File "/usr/local/lib/python3.8/site-packages/rope/base/utils/init.py", line 29, in newfunc return func(self, *args, kwds) File "/usr/local/lib/python3.8/site-packages/rope/base/pynames.py", line 189, in get self.set(self.get_inferred(*args, *kwds)) File "/usr/local/lib/python3.8/site-packages/rope/base/pyobjectsdef.py", line 40, in _infer_parameters pyobjects = rope.base.oi.soi.infer_parameter_objects(self) File "/usr/local/lib/python3.8/site-packages/rope/base/utils/init.py", line 41, in newfunc return func(args, kwds) File "/usr/local/lib/python3.8/site-packages/rope/base/oi/soi.py", line 47, in infer_parameter_objects result = _parameter_objects(pyfunction) File "/usr/local/lib/python3.8/site-packages/rope/base/oi/soi.py", line 130, in _parameterobjects type = hint_param(pyobject, name) File "/usr/local/lib/python3.8/site-packages/rope/base/oi/type_hinting/providers/inheritance.py", line 21, in call result = self._delegate(superfunc, param_name) File "/usr/local/lib/python3.8/site-packages/rope/base/oi/type_hinting/providers/composite.py", line 19, in call result = delegate(pyfunc, param_name) File "/usr/local/lib/python3.8/site-packages/rope/base/oi/type_hinting/providers/docstrings.py", line 46, in call type_strs = self._parse_docstring(pyfunc.get_doc(), param_name) File "/usr/local/lib/python3.8/site-packages/rope/base/pyobjects.py", line 224, in get_doc isinstance(expr.value, ast.Str): AttributeError: module 'rope.base.ast' has no attribute 'Str'

So is it able to run with python3? If so do I need an older rope version now?

Tried with latest: root@be89a3e42438:/# pip freeze |grep rope rope==0.16.0

And with: root@998bbef81569:/code# pip freeze |grep rope rope==0.14.0

Both return the same error.

FYI I'm just trying to run it on a single python file.

abarker commented 4 years ago

The README page is more recent and is correct. (Rope only fairly recently updated to be runnable with Python 3.) I'll update the comments in the code.

It looks like it's a bug in Rope when running Python 3.8: https://github.com/python-rope/rope/issues/279

From that page, there's a fix in the current Rope development code, but it apparently hasn't made it to the latest release. I get the same error as you when I run the program with 3.8. It works as usual with 3.7 and below. Try running the program with an older version of Python 3 (even if the code targets Python 3.8) to see if that works

isaacegglestone commented 4 years ago

No problem I can easily run 3.7 for the camel-snake-pep8 run Thanks for quick response.

isaacegglestone commented 4 years ago

Yep broke out the camel_snake check to seperate docker container running python 3.7 and that resolved the issue. I’m closing this issue out now.

isaacegglestone commented 4 years ago

I recommend updating the code shabang to just use python instead of python2 as this will default to whatever python the user has set to use rather than needing to call it with a specific version to override this. It’s the general purpose of that env python line rather than calling python directly AFAIK

abarker commented 4 years ago

Thanks, I hadn't noticed that the shebang was still for Python 2. I've just removed the shebang and the corresponding README lines to avoid any possible confusion.