I would like, when I install my python package with pip install .
, that the command pre-commit install
be run as well as everything else in the setup file.
Here is my setup.py file where I try to execute this:
from distutils.core import setup
from distutils.command.build import build as _build
from setuptools import find_packages, Command
import subprocess
class InstallPreCommit(Command):
def run(self):
subprocess.run(['pre-commit', 'install'])
# This class handles the pip install mechanism.
class build(_build):
sub_commands = _build.sub_commands
setup(
name="my-pkg",
version="0.0.1",
packages=find_packages(),
install_requires=['pre-commit'],
py_modules=["pkg"],
cmdclass={
'build': build,
'install-pre-commit': InstallPreCommit
}
)
However, when I run this, pre-commit install
does not get run. I'm mostly taking inspiration from this SO post and this setup.py file in Apache Beam.
Does anyone have a sense of how to make sure I am invoking the setup of my package as well as calling my custom command, which runs the pre-commit install
command?