Run command.
(self)
| 200 | """Post-process options.""" |
| 201 | |
| 202 | def run(self): |
| 203 | """Run command.""" |
| 204 | if self.already_run: |
| 205 | return |
| 206 | |
| 207 | if os.path.isdir('build'): |
| 208 | shutil.rmtree('build') |
| 209 | |
| 210 | package = self.distribution.packages[0] |
| 211 | if os.path.exists("package.json"): |
| 212 | shell = bool(os.name == 'nt') |
| 213 | |
| 214 | yarn_program = None |
| 215 | for program in ["yarnpkg", "yarn"]: |
| 216 | try: |
| 217 | yarn_version = check_output([program, "--version"], shell=shell) |
| 218 | if yarn_version != "": |
| 219 | yarn_program = program |
| 220 | break |
| 221 | except subprocess.CalledProcessError: |
| 222 | pass |
| 223 | |
| 224 | assert yarn_program is not None, "need nodejs and yarn installed in current PATH" |
| 225 | |
| 226 | commands = [ |
| 227 | [yarn_program, 'install', '--pure-lockfile'], |
| 228 | [yarn_program, 'run', 'build'], |
| 229 | ] |
| 230 | |
| 231 | for command in commands: |
| 232 | logging.info('Running command: {}'.format(str(" ".join(command)))) |
| 233 | try: |
| 234 | subprocess.check_call(command, shell=shell) |
| 235 | except subprocess.CalledProcessError as e: |
| 236 | raise Exception( |
| 237 | f"Exception = {e} command was called in directory = {os.getcwd()}" |
| 238 | ) from e |
| 239 | |
| 240 | self.copy_tree( |
| 241 | os.path.join(package, 'static'), os.path.join("build", "lib", package, "static") |
| 242 | ) |
| 243 | |
| 244 | assert self.distribution.metadata.version is not None, "version is not set" |
| 245 | with open(os.path.join("build", "lib", package, "VERSION"), "w") as f: |
| 246 | f.write(self.distribution.metadata.version) |
| 247 | |
| 248 | with open(os.path.join(package, "VERSION"), "w") as f: |
| 249 | f.write(self.distribution.metadata.version) |
| 250 | |
| 251 | self.already_run = True |
| 252 | |
| 253 | |
| 254 | class BuildPyCommand(setuptools.command.build_py.build_py): |