#19333 closed Bug (fixed)
Collect static copies a .py file
Reported by: | Camilo Nova | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When you run a collectstatic the file compress.py gets copied to the static directory, and that doesn't seem right.
I have created a pull request because this was generating PEP8 warnings for a project, but looking at the comments i agree this file shouldn't be copied.
https://github.com/django/django/pull/474
Maybe some can tweak the collectstatic command so it ignores .py files.
Change History (16)
comment:1 by , 12 years ago
Component: | contrib.staticfiles → contrib.admin |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Cleanup/optimization → Bug |
comment:4 by , 12 years ago
My personal website offers some Python scripts for download. I'm currently storing them as static files. If .py files were ignored by collectstatic they wouldn't be served anymore.
I may be abusing the static files framework :) but it's possible that other people are doing the same thing. For this reason, "ignore .py files" wasn't my first choice, but I would understand it.
comment:5 by , 12 years ago
Can anyone explain why the compress.py file is actually in the static directory to start with? If the static directory is the directory of stuff you want to share, It seems to me that we could avoid this whole problem by putting compress.py somewhere else (like a utilities directory -- which is what compress.py is anyway)
comment:6 by , 12 years ago
Has patch: | set |
---|
Opinions on proposed fix: https://github.com/ramiro/django/compare/19333-move-compress.py are welcome.
follow-up: 9 comment:8 by , 12 years ago
After your changes the script works only if you pass file names in argument or if you run it from django/contrib/admin/static/admin/js
.
The here
variable should be called admin_js_dir
, because that's what it really is :)
I suggest renaming that variable and pointing it to os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static', 'admin', 'js')
(to be tested, I just wrote it in this comment as an example).
Otherwise, that's the correct fix IMO.
comment:9 by , 12 years ago
Replying to aaugustin:
After your changes the script works only if you pass file names in argument or if you run it from
django/contrib/admin/static/admin/js
.
According to my understanding of the code it's also the current behavior. No changes here.
The
here
variable should be calledadmin_js_dir
, because that's what it really is :)
If I'm right above, the meaning of this var hasn't changed either. It is the CWD from which the script is being executed (not the dir where the script is located).
I suggest renaming that variable and pointing it to
os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static', 'admin', 'js')
(to be tested, I just wrote it in this comment as an example).
Otherwise, that's the correct fix IMO.
The only change this patch introduces is that to ejecute compress.py one needs to specify its full path (e.g. python ../../../bin/compress.py
). Remember the intended potential uses of this script are core devs and people contributing with the admin app by submitting JS patches.
comment:10 by , 12 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
I think the patch looks great. The only thing left to update is the doc: https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/submitting-patches/#compressing-javascript
comment:11 by , 12 years ago
Never mind, I got a little confused. The patch already modifies the doc...
On second thought, I agree with Aymeric in comment:8 to not use getcwd()
, so that the command can be run from anywhere.
comment:12 by , 12 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
Here's the suggested patch: https://github.com/jphalip/django/commit/62ea2101b6012244aeb502b1435e180c7b97bd94
comment:13 by , 12 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:14 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Yes, this file isn't designed to be served, it should be moved outside of the admin's static directory.