Comments (4)
Ah os.path.sep is incomplete, we need to use altsep too, if not None: https://docs.python.org/3.10/library/os.html#os.altsep
would you like to make a PR changing that instead?
from django-upgrade.
looks_like_migrations_file
is really simple:
django-upgrade/src/django_upgrade/data.py
Lines 68 to 70 in 06bf0b5
Can you try and debug why itβs not returning True
? Seems like it could be a Windows/Powershell issue.
from django-upgrade.
Hi Adam,
it may be indeed a combining PowerShell & git ls-files issue. git ls-files -- '*.py'
outputs the following:
...
projects/migrations/0001_initial.py
projects/migrations/0002_auto_20200512_1030.py
projects/migrations/0238_auto_20200424_1249.py
projects/migrations/0239_auto_20200430_1526.py
projects/migrations/0240_auto_20200505_0954.py
projects/migrations/0241_auto_20200514_1155.py
...
When this is passed to looks_like_migrations_file
, this results in the following:
ipdb> self.filename
'projects/migrations/0238_auto_20200424_1249.py'
ipdb> os.path.sep
'\\'
ipdb> self.filename.split(os.path.sep)
['projects/migrations/0238_auto_20200424_1249.py']
As the separator used by git ls-files (and git bash in general) does not match the os.path.sep
.
replacing the '/' did the trick:
git ls-files -- '*.py' | %{django-upgrade --target-version 4.1 $_.replace('/','\\')}
Is this something to be added in the docs? Or added as an argument?
An example doc change is present here:
I've added this as PR-285 is this seems OK for you.
Otherwise I'd gladly add it as an argument (to be used instead of os.path.sep if one is given).
from django-upgrade.
Not sure if using os.sep and os.altsep is the best way to do this:
Splitting on two delimiters can be done with re.split, the pattern will be something like:
sep_re = rf"[{os.sep}{os.altsep or ''}]"
# or to keep it simple:
sep_re = r"[\\/]"
Not sure if getting the path seperator from os
would have an added value here.
But if we're already going into regex land, maybe simplifying to the general approach in data.py would be a better solution:
migrations_re = re.compile(r"(^|[\\/])migrations([\\/])")
commands_re = re.compile( r"(^|[\\/])management[\\/]commands[\\/]")
...
@cached_property
def looks_like_command_file(self) -> bool:
return commands_re.search(self.filename) is not None
...
@cached_property
def looks_like_migrations_file(self) -> bool:
return migrations_re.search(self.filename) is not None
...
also simplifying the following part as marked above:
django-upgrade/src/django_upgrade/data.py
Lines 55 to 62 in 06bf0b5
Is this ok for you?
from django-upgrade.
Related Issues (20)
- Django 5.1: Fixer for CI*Field - db_collation replacement HOT 1
- does it require internet access? HOT 3
- default_app_config fixer HOT 3
- Rewrite `queryset.filter(pk=obj.pk).exists()` to `queryset.contains(obj)` HOT 3
- Strip skip decorators for old Django versions
- Django 4.1 Deprecated MemcachedCache HOT 1
- Default file storage is unset by django-upgrade HOT 1
- Check for unnecessary r strings in path HOT 3
- Support removal of `django.core.urlresolvers` on Django 2.0 HOT 5
- Cache support HOT 3
- Add `@admin.display` decorators in models file too HOT 5
- Introduce instruction on how to contribute with the project
- Django 6.0: Remove `FORMS_URLFIELD_ASSUME_HTTPS` transitional setting
- `timezone.utc` isn't replaced when `datetime` isn't imported HOT 4
- Rewrite `redirect(reverse(...))` calls to `redirect(...)` HOT 4
- `.choices` dropped for choices not subclassing the `*Choices` class HOT 6
- `request.is_ajax()` method is removed since Django 4.0. HOT 1
- Convert is_authenticated() to is_authenticated HOT 1
- Add fixer for django.db.models.AutoField in Django 3.2 HOT 1
- Template Tag "trans" to "translate" HOT 2
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-upgrade.