cyberdelia/django-pipeline — Issue #48: Remove usage of os.path.commonprefix in pipeline.compressors.Compressor.compile_templates
Author: mbferg
Created: 2011-12-04 01:21:07+00:00
State: open

Plain and simple, `os.path.commonprefix` is a misleading and broken function that needs to die. Unfortunately, pipeline's `compressor.compressors.Compressor.compile_templates` function uses it to calculate base paths for templates. Here's an example:

Let's say I have a directory, `js/templates/mymodule` and in that directory I have two files, `form` and `field`. In my `settings.py`:

```python
PIPELINE_JS = {
'mymodule': {
'source_filenames': (
'js/templates/mymodule/*.jst',
),
'output_filename': 'js/mymodule-?.js'
}
}
```

Using `os.path.commonprefix` on these files would mean that compressor sets base_path as `js/templates/mymodule/f`, which isn't a path, just a substring. This doesn't break anything until you look at the generated template code, and see `JST['ile']` and `JST['ield']`. This problem isn't exclusive to file names, since `os.path.commonprefix` is actually path-agnostic.

While the easiest way to fix this might be to eliminate dependency on `os.path.commonprefix`, it's probably better to offer an overall better solution for customizing names/prefixes for JavaScript Templates. I'll see what I can come up with and possibly submit an experimental patch this week.

https://github.com/cyberdelia/django-pipeline/blob/master/pipeline/compressors/__init__.py#L83