Mercurial > piecrust2
comparison piecrust/processing/less.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 | 63be34ce6e65 |
| children | fac4483867a5 |
comparison
equal
deleted
inserted
replaced
| 1111:98c7dd6ea4ac | 1112:a3dec0fbd9ce |
|---|---|
| 75 args += self._conf['options'] | 75 args += self._conf['options'] |
| 76 args.append(in_path) | 76 args.append(in_path) |
| 77 args.append(out_path) | 77 args.append(out_path) |
| 78 logger.debug("Processing LESS file: %s" % args) | 78 logger.debug("Processing LESS file: %s" % args) |
| 79 | 79 |
| 80 # On Windows, we need to run the process in a shell environment | |
| 81 # otherwise it looks like `PATH` isn't taken into account. | |
| 82 shell = (platform.system() == 'Windows') | |
| 83 try: | 80 try: |
| 84 proc = subprocess.Popen( | 81 proc = subprocess.Popen(args, stderr=subprocess.PIPE) |
| 85 args, shell=shell, | |
| 86 stderr=subprocess.PIPE) | |
| 87 stdout_data, stderr_data = proc.communicate() | 82 stdout_data, stderr_data = proc.communicate() |
| 88 except FileNotFoundError as ex: | 83 except FileNotFoundError as ex: |
| 89 logger.error("Tried running LESS processor with command: %s" % | 84 logger.error("Tried running LESS processor with command: %s" % |
| 90 args) | 85 args) |
| 91 raise Exception("Error running LESS processor. " | 86 raise Exception("Error running LESS processor. " |
| 103 | 98 |
| 104 def _ensureInitialized(self): | 99 def _ensureInitialized(self): |
| 105 if self._conf is not None: | 100 if self._conf is not None: |
| 106 return | 101 return |
| 107 | 102 |
| 103 bin_name = 'lessc' | |
| 104 if platform.system() == 'Windows': | |
| 105 bin_name += '.cmd' | |
| 106 | |
| 108 self._conf = self.app.config.get('less') or {} | 107 self._conf = self.app.config.get('less') or {} |
| 109 self._conf.setdefault('bin', 'lessc') | 108 self._conf.setdefault('bin', bin_name) |
| 110 self._conf.setdefault('options', ['--compress']) | 109 self._conf.setdefault('options', ['--compress']) |
| 111 if not isinstance(self._conf['options'], list): | 110 if not isinstance(self._conf['options'], list): |
| 112 raise Exception("The `less/options` configuration setting " | 111 raise Exception("The `less/options` configuration setting " |
| 113 "must be an array of arguments.") | 112 "must be an array of arguments.") |
| 114 | 113 |
