def input_patterns(self, outfile_name, context, triggers, changed): retval = [] for basename in changed: with open(project_root.join(basename)) as f: content = f.read().strip() if content: retval.extend(content.split(',')) return retval
def _file_contents(self, filename): """filename is taken to be relative to project-root.""" abs_filename = project_root.join(filename) self.assertTrue( os.path.exists(abs_filename), '%s not found in %s: %s' % (filename, os.path.dirname(filename), os.listdir(os.path.dirname(abs_filename)))) with open(abs_filename) as f: return f.read()
def _fake_npm_build(self, outfile_infiles_changed_context): """Does a fake 'build' that creates simpler versions of npm scripts.""" node_modules_path = project_root.join('node_modules') if not os.path.exists(node_modules_path): os.symlink(os.path.join('genfiles', 'node_modules'), node_modules_path) for (outfile_name, infile_names, _, _) in outfile_infiles_changed_context: if os.path.basename(outfile_name) == 'handlebars.js': # kake/compile_handlebars.js does require("handlebars"), so we need # to make sure it requires the version in the test sandbox, and not # the global version that you might have installed on your system. with open(project_root.join('genfiles', 'node_modules', 'handlebars', 'index.js'), 'w') as f: print >>f, _FAKE_HANDLEBARS_COMPILER # compile_handlebars.py also has a dep on # handlebars/lib/handlebars.js (though the fake handlebars # compiler never uses it), so create a fake file to make # that dep happy. open(project_root.join('genfiles', 'node_modules', 'handlebars', 'lib', 'handlebars.js'), 'w').close() continue elif 'babel-core' in outfile_name.split(os.sep): index_file = project_root.join('genfiles', 'node_modules', 'babel-core', 'index.js') with open(index_file, 'w') as f: print >>f, _FAKE_BABELJS with open(project_root.join('genfiles', 'node_modules', 'babel-core', 'package.json'), 'w') as f: print >>f, '{}' continue with open(project_root.join(outfile_name), 'w') as f: if os.path.basename(outfile_name) == 'lessc': # format is lessc --flags <infile> <outfile>. We # follow @import's print >>f, _RECURSIVE_PY_CAT if os.path.basename(outfile_name) == 'autoprefixer': # format is autoprefixer -o <outfile> --map <infile>. We # follow @import's print >>f, _FAKE_AUTOPREFIXER elif os.path.basename(outfile_name) in ('cssmin', 'uglifyjs'): # We'll just have the compressors remove newlines and # comments. We have to run perl from a shell script so # we can ignore all the args to cssmin/uglifyjs. # Note that in cssmin, /*! ... */ is a directive, not a # comment, so we leave it alone. print >>f, '#!/bin/sh' print >>f, ('perl -e \'$_ = join("", <>);' ' s,\n,,g;' # newlines ' s,/\*[^!].*?\*/,,g;' # /* comments */ ' s,//.*,,g;' # // comments 'print;\'') else: # Our script just copies from stdin/argv[1] to stdout. # -p does 'cat'. -s ignores flags (all args starting with -). print >>f, '#!/usr/bin/perl -ps' os.chmod(project_root.join(outfile_name), o0755)
def input_patterns(self, outfile_name, context, triggers, changed): with open(project_root.join(triggers[0])) as f: content = f.read().strip() return content.split(',') if content else []
def _get_contents_for_analysis(self, infile): with open(project_root.join(infile)) as f: contents = f.read() return re.sub(NoCommentComputedIncludeInputs.STRIP_COMMENT_RE, '', contents)
def assertFileDoesNotExist(self, filename): """Assert that filename, relative to project-root, does not exist.""" self.assertFalse(os.path.exists(project_root.join(filename)), filename)
def assertFileExists(self, filename): """Assert that filename, relative to project-root, exists.""" self.assertTrue(os.path.exists(project_root.join(filename)), filename)