From 4d163220075a05712553e53c9c51ceeaf187fcd7 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 4 Apr 2015 16:03:46 -0700 Subject: [PATCH] Ignore underscored files when compiling a directory. --- sass.py | 3 ++- sasstests.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/sass.py b/sass.py index cd4619f9..5677240b 100644 --- a/sass.py +++ b/sass.py @@ -149,7 +149,8 @@ def compile_dirname( fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding() for dirpath, _, filenames in os.walk(search_path): filenames = [ - filename for filename in filenames if filename.endswith('.scss') + filename for filename in filenames + if filename.endswith('.scss') and not filename.startswith('_') ] for filename in filenames: input_filename = os.path.join(dirpath, filename) diff --git a/sasstests.py b/sasstests.py index aed141bc..14c362ce 100644 --- a/sasstests.py +++ b/sasstests.py @@ -698,7 +698,6 @@ def test_successful(self): # Make sure we don't compile non-scss files write_file(os.path.join(input_dir, 'baz.txt'), 'Hello der') - # the api for this is weird, why does it need source? sass.compile(dirname=(input_dir, output_dir)) assert os.path.exists(output_dir) assert os.path.exists(os.path.join(output_dir, 'foo')) @@ -711,6 +710,17 @@ def test_successful(self): self.assertEqual(contentsf1, 'a b {\n width: 100%; }\n') self.assertEqual(contentsf2, 'foo {\n width: 100%; }\n') + def test_ignores_underscored_files(self): + with tempdir() as tmpdir: + input_dir = os.path.join(tmpdir, 'input') + output_dir = os.path.join(tmpdir, 'output') + os.mkdir(input_dir) + write_file(os.path.join(input_dir, 'f1.scss'), '@import "f2";') + write_file(os.path.join(input_dir, '_f2.scss'), 'a{color:red}') + + sass.compile(dirname=(input_dir, output_dir)) + assert not os.path.exists(os.path.join(output_dir, '_f2.css')) + def test_error(self): with tempdir() as tmpdir: input_dir = os.path.join(tmpdir, 'input')