Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-pipeline
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-pipeline
Commits
96b356d7
Commit
96b356d7
authored
Jun 07, 2012
by
Timothée Peignier
Committed by
Timothée Peignier
Jun 17, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change compiler interface, to allow compiler to deal with outdated file themselves
parent
05cf8044
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
47 additions
and
49 deletions
+47
-49
docs/compilers.rst
+4
-2
pipeline/compilers/__init__.py
+12
-25
pipeline/compilers/coffee.py
+8
-4
pipeline/compilers/less.py
+6
-7
pipeline/compilers/sass.py
+6
-6
pipeline/compilers/stylus.py
+8
-5
requirements.txt
+3
-0
No files found.
docs/compilers.rst
View file @
96b356d7
...
...
@@ -142,6 +142,8 @@ A custom compiler for an imaginary compiler called jam ::
def match_file(self, filename):
return filename.endswith('.jam')
def compile_file(self, content, path):
return jam.compile(content)
def compile_file(self, infile, outfile, outdated=False, force=False):
if not outdated and not force:
return # No need to recompiled file
return jam.compile(infile, outfile)
pipeline/compilers/__init__.py
View file @
96b356d7
...
...
@@ -6,9 +6,6 @@ try:
except
ImportError
:
from
django.contrib.staticfiles
import
finders
# noqa
from
django.core.files.base
import
ContentFile
from
django.utils.encoding
import
smart_str
from
pipeline.conf
import
settings
from
pipeline.storage
import
default_storage
from
pipeline.utils
import
to_class
...
...
@@ -24,20 +21,19 @@ class Compiler(object):
compilers
=
property
(
compilers
)
def
compile
(
self
,
paths
,
force
=
False
):
for
index
,
path
in
enumerate
(
paths
):
for
index
,
input_
path
in
enumerate
(
paths
):
for
compiler
in
self
.
compilers
:
compiler
=
compiler
(
self
.
verbose
)
if
compiler
.
match_file
(
path
):
new_path
=
self
.
output_path
(
path
,
compiler
.
output_extension
)
paths
[
index
]
=
new_path
if
not
force
and
not
self
.
is_outdated
(
path
,
new_path
):
continue
if
compiler
.
match_file
(
input_path
):
output_path
=
self
.
output_path
(
input_path
,
compiler
.
output_extension
)
paths
[
index
]
=
output_path
try
:
content
=
self
.
read_file
(
path
)
compiled_content
=
compiler
.
compile_file
(
content
,
finders
.
find
(
path
))
self
.
save_file
(
new_path
,
compiled_content
)
infile
=
finders
.
find
(
input_path
)
outfile
=
finders
.
find
(
output_path
)
outdated
=
self
.
is_outdated
(
input_path
,
output_path
)
compiler
.
compile_file
(
infile
,
outfile
,
outdated
=
outdated
,
force
=
force
)
except
CompilerError
:
if
not
self
.
storage
.
exists
(
new
_path
)
or
not
settings
.
PIPELINE
:
if
not
self
.
storage
.
exists
(
output
_path
)
or
not
settings
.
PIPELINE
:
raise
return
paths
...
...
@@ -45,21 +41,12 @@ class Compiler(object):
path
=
os
.
path
.
splitext
(
path
)
return
'.'
.
join
((
path
[
0
],
extension
))
def
read_file
(
self
,
path
):
file
=
self
.
storage
.
open
(
path
,
'rb'
)
content
=
file
.
read
()
file
.
close
()
return
content
def
is_outdated
(
self
,
path
,
new_path
):
def
is_outdated
(
self
,
infile
,
outfile
):
try
:
return
self
.
storage
.
modified_time
(
path
)
>
self
.
storage
.
modified_time
(
new_path
)
return
self
.
storage
.
modified_time
(
infile
)
>
self
.
storage
.
modified_time
(
outfile
)
except
(
OSError
,
NotImplementedError
):
return
True
def
save_file
(
self
,
path
,
content
):
return
self
.
storage
.
save
(
path
,
ContentFile
(
smart_str
(
content
)))
class
CompilerBase
(
object
):
def
__init__
(
self
,
verbose
):
...
...
@@ -68,7 +55,7 @@ class CompilerBase(object):
def
match_file
(
self
,
filename
):
raise
NotImplementedError
def
compile_file
(
self
,
content
,
path
):
def
compile_file
(
self
,
infile
,
outfile
,
outdated
=
False
,
force
=
False
):
raise
NotImplementedError
...
...
pipeline/compilers/coffee.py
View file @
96b356d7
...
...
@@ -8,9 +8,13 @@ class CoffeeScriptCompiler(SubProcessCompiler):
def
match_file
(
self
,
path
):
return
path
.
endswith
(
'.coffee'
)
def
compile_file
(
self
,
content
,
path
):
command
=
"
%
s -sc
%
s"
%
(
def
compile_file
(
self
,
infile
,
outfile
,
outdated
=
False
,
force
=
False
):
if
not
outdated
and
not
force
:
return
# File doesn't need to be recompiled
command
=
"
%
s -c
%
s
%
s >
%
s"
%
(
settings
.
PIPELINE_COFFEE_SCRIPT_BINARY
,
settings
.
PIPELINE_COFFEE_SCRIPT_ARGUMENTS
settings
.
PIPELINE_COFFEE_SCRIPT_ARGUMENTS
,
infile
,
outfile
)
return
self
.
execute_command
(
command
,
content
)
return
self
.
execute_command
(
command
)
pipeline/compilers/less.py
View file @
96b356d7
import
os.path
from
os.path
import
dirname
from
pipeline.conf
import
settings
from
pipeline.compilers
import
SubProcessCompiler
...
...
@@ -10,12 +10,11 @@ class LessCompiler(SubProcessCompiler):
def
match_file
(
self
,
filename
):
return
filename
.
endswith
(
'.less'
)
def
compile_file
(
self
,
content
,
path
):
command
=
'
%
s
%
s
%
s'
%
(
def
compile_file
(
self
,
infile
,
outfile
,
outdated
=
False
,
force
=
False
):
command
=
"
%
s
%
s
%
s
%
s"
%
(
settings
.
PIPELINE_LESS_BINARY
,
settings
.
PIPELINE_LESS_ARGUMENTS
,
path
infile
,
outfile
)
cwd
=
os
.
path
.
dirname
(
path
)
content
=
self
.
execute_command
(
command
,
cwd
=
cwd
)
return
content
return
self
.
execute_command
(
command
,
cwd
=
dirname
(
infile
))
pipeline/compilers/sass.py
View file @
96b356d7
import
os.path
from
os.path
import
dirname
from
pipeline.conf
import
settings
from
pipeline.compilers
import
SubProcessCompiler
...
...
@@ -10,11 +10,11 @@ class SASSCompiler(SubProcessCompiler):
def
match_file
(
self
,
filename
):
return
filename
.
endswith
((
'.scss'
,
'.sass'
))
def
compile_file
(
self
,
content
,
path
):
command
=
"
%
s
--scss
%
s
%
s"
%
(
def
compile_file
(
self
,
infile
,
outfile
,
outdated
=
False
,
force
=
False
):
command
=
"
%
s
%
s --update
%
s:
%
s"
%
(
settings
.
PIPELINE_SASS_BINARY
,
settings
.
PIPELINE_SASS_ARGUMENTS
,
path
infile
,
outfile
)
cwd
=
os
.
path
.
dirname
(
path
)
return
self
.
execute_command
(
command
,
cwd
=
cwd
)
return
self
.
execute_command
(
command
,
cwd
=
dirname
(
infile
))
pipeline/compilers/stylus.py
View file @
96b356d7
import
os.path
from
os.path
import
dirname
from
pipeline.conf
import
settings
from
pipeline.compilers
import
SubProcessCompiler
...
...
@@ -10,10 +10,13 @@ class StylusCompiler(SubProcessCompiler):
def
match_file
(
self
,
filename
):
return
filename
.
endswith
(
'.styl'
)
def
compile_file
(
self
,
content
,
path
):
command
=
"
%
s
%
s"
%
(
def
compile_file
(
self
,
infile
,
outfile
,
outdated
=
False
,
force
=
False
):
if
not
outdated
and
not
force
:
return
# File doesn't need to be recompiled
command
=
"
%
s
%
s <
%
s >
%
s"
%
(
settings
.
PIPELINE_STYLUS_BINARY
,
settings
.
PIPELINE_STYLUS_ARGUMENTS
,
infile
,
outfile
)
cwd
=
os
.
path
.
dirname
(
path
)
return
self
.
execute_command
(
command
,
content
,
cwd
=
cwd
)
return
self
.
execute_command
(
command
,
cwd
=
dirname
(
infile
))
requirements.txt
0 → 100644
View file @
96b356d7
tox
flake8
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment