Code Monkey home page Code Monkey logo

Comments (5)

browniebroke avatar browniebroke commented on June 27, 2024 2

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.

jefftriplett avatar jefftriplett commented on June 27, 2024 1

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.

browniebroke avatar browniebroke commented on June 27, 2024 1

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):

if self.old_parent_module_parts != self.new_parent_module_parts:
# import statement needs updating
AddImportsVisitor.add_needed_import(
context=self.context,
module=".".join(self.new_parent_module_parts),
obj=self.new_parent_name,
asname=import_alias.evaluated_alias,
)
continue

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.

browniebroke avatar browniebroke commented on June 27, 2024

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.

browniebroke avatar browniebroke commented on June 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.