From ce7a434f2d4cbb6bd6863c97071a97054b0da1cb Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 3 May 2018 18:47:10 +0200 Subject: [PATCH] build: add the prebuild command as a dependency for develop So, 'python setup.py develop' exists. And of course it doesn't have build_py as a dependency, because of course it doesn't. We could use 'data_files' instead of 'package_data and copying', and then use pkg_resources to find the actual file location, and that could work in theory. But pkg_resources API is weird and messy and this whole area of Python packaging theory barely works as it is. Instead we will force the prebuild command to be a dependency of develop as well as build_py, and we do this by monkey-patching instead of the proper way, because at this point it seems cleaner. I wonder if there are more commands that would need this. --- setup.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 17e76015a..bb186dca1 100755 --- a/setup.py +++ b/setup.py @@ -5,6 +5,7 @@ import subprocess from setuptools import setup, Command from setuptools.command.build_py import build_py +from setuptools.command.develop import develop install_requires = [ 'setuptools>=19.0', @@ -61,10 +62,19 @@ class PrebuildCommand(Command): print("Using pre-generated files.") -class CustomBuild(build_py): - def run(self): +def _patch_prebuild(cls): + """Patch a setuptools command to depend on `prebuild`""" + orig_run = cls.run + + def new_run(self): self.run_command('prebuild') - super().run() + orig_run(self) + + cls.run = new_run + + +_patch_prebuild(build_py) +_patch_prebuild(develop) setup( @@ -99,6 +109,5 @@ setup( ], cmdclass={ 'prebuild': PrebuildCommand, - 'build_py': CustomBuild, }, )