pakal / django-compat-patcher

A system to improve compatibility between different Django versions, and make upgrading dependencies less painful.
MIT License
13 stars 2 forks source link

Collaborate with django-codemod #12

Closed jayvdb closed 3 years ago

jayvdb commented 4 years ago

https://github.com/browniebroke/django-codemod does code rewriting , and many of their fixers are in the format

class URLTransformer(BaseSimpleFuncRenameTransformer):
    """Resolve deprecation of ``django.conf.urls.url``."""

    deprecated_in = DJANGO_30
    removed_in = DJANGO_40
    rename_from = "django.conf.urls.url"
    rename_to = "django.urls.re_path"

That structure is more re-usable metadata-ish, but they have far fewer fixers, so it would take a big effort to move all of the fixes here to there.

What would be more feasible is if this project used a more metadata-ish format for the 'easy' cases, ideally even a yaml file, and then django-codemod could load those from this project, and do their own thing for the entries which they can correctly parse/handle.

jayvdb commented 4 years ago

Their list of transfomers

    "AbsPathTransformer",
    "AvailableAttrsTransformer",
    "ContextDecoratorTransformer",
    "ForceTextTransformer",
    "HttpUrlQuotePlusTransformer",
    "HttpUrlQuoteTransformer",
    "HttpUrlUnQuotePlusTransformer",
    "HttpUrlUnQuoteTransformer",
    "InlineHasAddPermissionsTransformer",
    "IsSafeUrlTransformer",
    "LRUCacheTransformer",
    "ModelsPermalinkTransformer",
    "RenderToResponseTransformer",
    "SmartTextTransformer",
    "UGetTextLazyTransformer",
    "UGetTextNoopTransformer",
    "UGetTextTransformer",
    "UNGetTextLazyTransformer",
    "UNGetTextTransformer",
    "URLTransformer",
    "UnescapeEntitiesTransformer",
    "UnicodeCompatibleTransformer",
jayvdb commented 4 years ago

A good starting point would be generating a list of ast differences between versions of Django, and store in a usable format.

https://github.com/radix/astdiff/blob/master/astdiff.py is first easy find on doing that.

pakal commented 4 years ago

Thanks for the notice, I hadn't heard about this package ; I'll discuss this on the django-codemod repository.

pakal commented 4 years ago

(Added a readme note about this other project)

pakal commented 3 years ago

This notice will do for now, alas we can't really share code due to how differently projects work (AST rewrite vs MonkeyPatching).