Comments (5)
The problem should no longer happen in 1.5.6, I've disabled the problematic feature for now. I'll try to fix it properly later, not really have time at the moment...
from django-codemod.
I came here to report this bug too. Using the latest version:
❯ python --version
Python 3.7.10
❯ django-admin --version
3.0.14
❯ djcodemod run --removed-in=3.1 ./blog/models.py
Running codemods: FixedOffsetTransformer, FloatRangeFormFieldTransformer, FloatRangeModelFieldTransformer, QuerySetPaginatorTransformer
Executing codemod...
Codemodding /Users/jefftriplett/.virtualenvs/trailhawks.com/src/trailhawks.com-git/blog/models.py
Traceback (most recent call last):
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/_parser/base_parser.py", line 152, in _add_token
plan = stack[-1].dfa.transitions[transition]
KeyError: ReservedString(import)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/codemod/_cli.py", line 295, in _execute_transform
output_tree = transformer.transform_module(input_tree)
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/codemod/_command.py", line 88, in transform_module
tree = self._instantiate_and_run(transform, tree)
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/codemod/_command.py", line 58, in _instantiate_and_run
return inst.transform_module(tree)
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/codemod/_codemod.py", line 108, in transform_module
return self.transform_module_impl(tree_with_metadata)
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/codemod/_visitor.py", line 32, in transform_module_impl
return tree.visit(self)
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/_nodes/module.py", line 91, in visit
result = super(Module, self).visit(visitor)
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/_nodes/base.py", line 235, in visit
leave_result = visitor.on_leave(self, with_updated_children)
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/matchers/_visitors.py", line 512, in on_leave
retval = CSTTransformer.on_leave(self, original_node, updated_node)
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/_visitors.py", line 72, in on_leave
updated_node = leave_func(original_node, updated_node)
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/codemod/visitors/_add_imports.py", line 404, in leave_Module
for module, aliases in module_and_alias_mapping.items()
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/codemod/visitors/_add_imports.py", line 405, in <listcomp>
if module != "__future__"
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/_parser/entrypoints.py", line 105, in parse_statement
detect_default_newline=False,
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/_parser/entrypoints.py", line 51, in _parse
result = parser.parse()
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/_parser/base_parser.py", line 111, in parse
self._add_token(token)
File "/Users/jefftriplett/.virtualenvs/trailhawks.com/lib/python3.7/site-packages/libcst/_parser/base_parser.py", line 191, in _add_token
raw_column=token.start_pos[1],
libcst._exceptions.ParserSyntaxError: Syntax Error @ 1:7.
Incomplete input. Encountered 'import', but expected '.', '...', or 'NAME'.
from import datetime
^
Failed to codemod /Users/jefftriplett/.virtualenvs/trailhawks.com/src/trailhawks.com-git/blog/models.py
If it's helpful, I have a public project you can reproduce it on: https://github.com/trailhawks/trailhawks.com
from django-codemod.
Yes I think I've nailed down the problem to this section, it's just wrong (it replaces the import for the parent module, even if the thing being codemodded isn't used in the file):
django-codemod/django_codemod/visitors/base.py
Lines 167 to 175 in 7942036
I'll probably disable this feature and push a new release (hopefully tomorrow) until I can make a fix, this is probably breaking a lot of other things.
from django-codemod.
Hi @luzfcb! Thanks for the report. That's a stange one, I cannot reproduce with the CLI installed in my development environment for the project, however, I'm able to do so if I install django-codemod with pipx, like you do.
I've removed a few options you've used and I tracked down the bug to --deprecated-in 2.2
, and then to the FixedOffsetTransformer
codemodder. You'd get the bug with this:
djcodemod run --codemod FixedOffsetTransformer foobar.py
I'll take a look, but in the meantime you can avoid passing --deprecated-in 2.2
...
from django-codemod.
I think the issue can be avoided by using django-codemod<1.4 since it was most likely introduced in #347
from django-codemod.
Related Issues (20)
- iterable ConnectionHandler HOT 2
- Avoid try: .. except ImportError: blocks HOT 2
- Ability to use a specific codemodder to the CLI
- Merge test, lint and commitlint workflows HOT 3
- Add an option to skip paths (e.g. node_modules) HOT 8
- django.contrib.postgres.fields.jsonb not captured by codemod HOT 3
- Recommended command recurses into my virtualenv HOT 1
- Extra imports added with libCST 0.3.14 and above HOT 2
- Attribute access to `url` incorrectly replaced
- Local variable shadowing import from outer scope HOT 1
- Action Required: Fix Renovate Configuration
- Switch to `version_toml` for semantic release HOT 2
- Simplify import checking with LibCST's FullyQualifiedNameProvider
- Removed compatibility imports in 3.1
- Dependency Dashboard
- Option to show diffs HOT 1
- Django 4 django.dispatch.Signal unexpected keyword argument providing_args HOT 5
- ImportError on an Apple M1 Mac related to libcst HOT 5
- Add tests to sdist HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-codemod.