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

Support replacing call to url with simple patterns by path #138

Merged
merged 20 commits into from
Jul 21, 2020

Conversation

browniebroke
Copy link
Owner

Currently we replace url() by re_path() which is a simple rename operation. We could go one step further by looking at the URL pattern and replace the simple ones by the path() function from Django 2.0 which is less error prone.

The most basic would be to check whether the RegEx has any captured groups in it and if not, we can assume the replacement is simple.

We could later consider improving this by trying to convert URLs with only simple captured groups (slug, int, etc...).

@browniebroke browniebroke added the enhancement New feature or request label Jul 8, 2020
@codecov
Copy link

codecov bot commented Jul 8, 2020

Codecov Report

Merging #138 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #138   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        19    +2     
  Lines          455       548   +93     
=========================================
+ Hits           455       548   +93     
Impacted Files Coverage Δ
django_codemod/re.py 100.00% <100.00%> (ø)
django_codemod/visitors/__init__.py 100.00% <100.00%> (ø)
django_codemod/visitors/base.py 100.00% <100.00%> (ø)
django_codemod/visitors/core.py 100.00% <100.00%> (ø)
django_codemod/visitors/decorators.py 100.00% <100.00%> (ø)
django_codemod/visitors/encoding.py 100.00% <100.00%> (ø)
django_codemod/visitors/html.py 100.00% <100.00%> (ø)
django_codemod/visitors/http.py 100.00% <100.00%> (ø)
django_codemod/visitors/lru_cache.py 100.00% <100.00%> (ø)
django_codemod/visitors/os_utils.py 100.00% <100.00%> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 34b6c57...7ff8224. Read the comment docs.

@browniebroke browniebroke added this to the Django 4.0 milestone Jul 10, 2020
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jul 21, 2020

Sourcery Code Quality Report (beta)

Merging this PR leaves code quality unchanged.

Quality metrics Before After Change
Complexity 0.43 0.42 -0.01 🔵
Method Length 25.69 24.96 -0.73 🔵
Quality 9.34 9.34 0.00
Other metrics Before After Change
Lines 530 750 220
Changed files Quality Before Quality After Quality Change
django_codemod/re.py 9.70
django_codemod/visitors/base.py 9.25 9.33 0.08 🔵
django_codemod/visitors/core.py 9.48 9.48 0.00
django_codemod/visitors/decorators.py 9.12 9.12 0.00
django_codemod/visitors/encoding.py 8.73 8.73 0.00
django_codemod/visitors/html.py 9.48 9.48 0.00
django_codemod/visitors/http.py 8.08 8.08 0.00
django_codemod/visitors/lru_cache.py 9.48 9.48 0.00
django_codemod/visitors/os_utils.py 9.48 9.48 0.00
django_codemod/visitors/shortcuts.py 9.60 9.60 0.00
django_codemod/visitors/translations.py 8.08 8.08 0.00
django_codemod/visitors/urls.py 9.48 9.09 -0.39 🔴
tests/visitors/test_base.py 9.50 9.50 0.00
tests/visitors/test_urls.py 9.66 9.57 -0.09 🔴

Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it via email or our Gitter!

@browniebroke browniebroke merged commit c85c280 into master Jul 21, 2020
@browniebroke browniebroke deleted the feature/better-url-transformer branch July 21, 2020 18:36
@browniebroke browniebroke changed the title Support replacing url() with simple patterns by path() Support replacing call to url with simple patterns by path Jul 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant