Mercurial > piecrust2
comparison piecrust/processing/compressors.py @ 1112:a3dec0fbd9ce
bake: Fix bug on Windows where shim scripts of NodeJS tools couldn't run.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 20 Feb 2018 22:15:57 -0800 |
parents | f070a4fc033c |
children |
comparison
equal
deleted
inserted
replaced
1111:98c7dd6ea4ac | 1112:a3dec0fbd9ce |
---|---|
34 args = [self._conf['bin'], '-o', out_path] | 34 args = [self._conf['bin'], '-o', out_path] |
35 args += self._conf['options'] | 35 args += self._conf['options'] |
36 args.append(path) | 36 args.append(path) |
37 logger.debug("Cleaning CSS file: %s" % args) | 37 logger.debug("Cleaning CSS file: %s" % args) |
38 | 38 |
39 # On Windows, we need to run the process in a shell environment | |
40 # otherwise it looks like `PATH` isn't taken into account. | |
41 shell = (platform.system() == 'Windows') | |
42 try: | 39 try: |
43 retcode = subprocess.call(args, shell=shell) | 40 retcode = subprocess.call(args) |
44 except FileNotFoundError as ex: | 41 except FileNotFoundError as ex: |
45 logger.error("Tried running CleanCSS processor with command: %s" % | 42 logger.error("Tried running CleanCSS processor with command: %s" % |
46 args) | 43 args) |
47 raise Exception("Error running CleanCSS processor. " | 44 raise Exception("Error running CleanCSS processor. " |
48 "Did you install it?") from ex | 45 "Did you install it?") from ex |
53 | 50 |
54 def _ensureInitialized(self): | 51 def _ensureInitialized(self): |
55 if self._conf is not None: | 52 if self._conf is not None: |
56 return | 53 return |
57 | 54 |
55 bin_name = 'cleancss' | |
56 if platform.system() == 'Windows': | |
57 bin_name += '.cmd' | |
58 | |
58 self._conf = self.app.config.get('cleancss') or {} | 59 self._conf = self.app.config.get('cleancss') or {} |
59 self._conf.setdefault('bin', 'cleancss') | 60 self._conf.setdefault('bin', bin_name) |
60 self._conf.setdefault('options', ['--skip-rebase']) | 61 self._conf.setdefault('options', ['--skip-rebase']) |
61 self._conf.setdefault('out_ext', '.css') | 62 self._conf.setdefault('out_ext', '.css') |
62 if len(self._conf['out_ext']) > 0 and self._conf['out_ext'][0] != '.': | 63 if len(self._conf['out_ext']) > 0 and self._conf['out_ext'][0] != '.': |
63 self._conf['out_ext'] = '.' + self._conf['out_ext'] | 64 self._conf['out_ext'] = '.' + self._conf['out_ext'] |
64 if not isinstance(self._conf['options'], list): | 65 if not isinstance(self._conf['options'], list): |
81 | 82 |
82 args = [self._conf['bin'], in_path, '-o', out_path] | 83 args = [self._conf['bin'], in_path, '-o', out_path] |
83 args += self._conf['options'] | 84 args += self._conf['options'] |
84 logger.debug("Uglifying JS file: %s" % args) | 85 logger.debug("Uglifying JS file: %s" % args) |
85 | 86 |
86 # On Windows, we need to run the process in a shell environment | |
87 # otherwise it looks like `PATH` isn't taken into account. | |
88 shell = (platform.system() == 'Windows') | |
89 try: | 87 try: |
90 retcode = subprocess.call(args, shell=shell) | 88 retcode = subprocess.call(args) |
91 except FileNotFoundError as ex: | 89 except FileNotFoundError as ex: |
92 logger.error("Tried running UglifyJS processor with command: %s" % | 90 logger.error("Tried running UglifyJS processor with command: %s" % |
93 args) | 91 args) |
94 raise Exception("Error running UglifyJS processor. " | 92 raise Exception("Error running UglifyJS processor. " |
95 "Did you install it?") from ex | 93 "Did you install it?") from ex |
100 | 98 |
101 def _ensureInitialized(self): | 99 def _ensureInitialized(self): |
102 if self._conf is not None: | 100 if self._conf is not None: |
103 return | 101 return |
104 | 102 |
103 bin_name = 'uglifyjs' | |
104 if platform.system() == 'Windows': | |
105 bin_name += '.cmd' | |
106 | |
105 self._conf = self.app.config.get('uglifyjs') or {} | 107 self._conf = self.app.config.get('uglifyjs') or {} |
106 self._conf.setdefault('bin', 'uglifyjs') | 108 self._conf.setdefault('bin', bin_name) |
107 self._conf.setdefault('options', ['--compress']) | 109 self._conf.setdefault('options', ['--compress']) |
108 if not isinstance(self._conf['options'], list): | 110 if not isinstance(self._conf['options'], list): |
109 raise Exception("The `uglify/options` configuration setting " | 111 raise Exception("The `uglify/options` configuration setting " |
110 "must be an array of arguments.") | 112 "must be an array of arguments.") |
111 |