Opened 22 months ago

Closed 11 months ago

Last modified 5 months ago

#29983 closed Cleanup/optimization (fixed)

Replace os.path with pathlib.Path in project template and docs

Reported by: thewhisperinyourears Owned by: Jon Dufresne
Component: Core (Other) Version: 2.0
Severity: Normal Keywords: paths, settings
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Apparently there is an issue hen you are using linux (Ubuntu) and copy and paste your project to Windows. The Paths don't work. I had to change the settings in my STATICFILES_DIRS from os.path.join(BASE_DIR, 'myapp/static') to os.path.join(BASE_DIR, 'myapp', 'static')

Change History (15)

comment:1 Changed 22 months ago by Curtis Maloney

Owner: changed from nobody to Curtis Maloney
Status: newassigned
Triage Stage: UnreviewedAccepted

I was helping this user on IRC, and they were getting confusing errors when running "collectstatic" or "findstatic" about the path not matching.

It turned out to be a conflict with joining Windows-style paths with Unix-style paths, as mentioned above.

I'm going to look at replacing uses of os.path.join and its ilk with pathlib, which does not suffer this problem.

comment:2 Changed 22 months ago by Tim Graham

I'm surprised this hasn't come up before. What does the error look like?

The documentation for STATICFILES_DIRS days, "these paths should use Unix-style forward slashes, even on Windows". I guess the problem is that the way BASE_DIR is generated on Windows using backslashes. It's not clear to me what Django can do about this but we'll see what Curtis comes up with.

comment:3 Changed 22 months ago by Curtis Maloney

Has patch: set
Last edited 22 months ago by Tim Graham (previous) (diff)

comment:4 Changed 22 months ago by Tim Graham

Component: contrib.staticfilesCore (Other)
Patch needs improvement: set
Summary: Paths when using Windows from an Ubuntu projectReplace os.path with pathlib.Path in project template and docs
Type: BugCleanup/optimization

The patch doesn't work because os.path.join(BASE_DIR, 'db.sqlite3') returns a string while BASE_DIR / 'db.sqlite3' returns a PosixPath. The documentation would have to use str(BASE_DIR / 'db.sqlite3') everywhere or Django would have to convert PosixPath to string.

comment:5 Changed 11 months ago by Jon Dufresne

Patch needs improvement: unset

I have resurrected the original patch with a fix for SQLite.

PR

comment:6 Changed 11 months ago by Claude Paroz

I'm not sure if various Django settings requiring a path (template DIRS, STATIC/MEDIA_ROOT, etc.) all support path inputs. Shouldn't we check and add tests for those before changing the project settings template?

comment:7 Changed 11 months ago by Carlton Gibson

Needs tests: set
Owner: changed from Curtis Maloney to Jon Dufresne

Assigning Jon, since he's picked this up; marking as needs tests, since I think Claude is right, we have had regressions from moving to Path.

comment:8 Changed 11 months ago by Carlton Gibson <carlton.gibson@…>

In 92e5abd7:

Refs #29983 -- Added test for FIXTURES_DIRS pathlib support.

comment:9 Changed 11 months ago by Carlton Gibson <carlton.gibson@…>

In 1c4c68d:

Refs #29983 -- Added test for FILE_UPLOAD_TEMP_DIR pathlib support.

comment:10 Changed 11 months ago by Carlton Gibson <carlton.gibson@…>

In fbbff7f:

Refs #29983 -- Added pathlib.Path support to the file email backend.

comment:11 Changed 11 months ago by Carlton Gibson <carlton.gibson@…>

In 74f2a58b:

Refs #29983 -- Added tests for FileBasedCache pathlib support.

comment:12 Changed 11 months ago by Carlton Gibson <carlton.gibson@…>

In 77aa74c:

Refs #29983 -- Added support for using pathlib.Path in all settings.

comment:13 Changed 11 months ago by Carlton Gibson

Triage Stage: AcceptedReady for checkin

comment:14 Changed 11 months ago by Carlton Gibson <carlton.gibson@…>

Resolution: fixed
Status: assignedclosed

In 26554cf5:

Fixed #29983 -- Replaced os.path() with pathlib.Path in project template and docs.

Thanks Curtis Maloney for the original patch.

comment:15 Changed 5 months ago by Carlton Gibson <carlton@…>

In 150c3d13:

Refs #29983 -- Fixed displaying pathlib.Path database name in flush command's inputs.

Note: See TracTickets for help on using tickets.
Back to Top