Reputation: 392
I am migrating the configurations from setup.py
to setup.cfg
but I have a problem with cmdclass
keyword. I looked into setuptools docs and it seems like this keyword is not documented or supported. So I tried options.entry_points
instead. But I keep getting invalid command error.
Here is what I have:
setup.cfg
[options.entry_points]
console_scripts =
install = CustomInstall:run
and
setup.py
from setuptools.command.install import install
from setuptools import setup
class CustomInstall(install):
def run(self):
print('overriden install command')
setup()
The result was just a normal install command. However, I would like to replicate the behaviour that I get when I run:
# setup.py
from setuptools.command.install import install
from setuptools import setup
class CustomInstall(install):
def run(self):
print('overriden install command')
setup(cmdclass= {"install": CustomInstall})
which gives an overriden install command.
Upvotes: 7
Views: 1060
Reputation: 21
The cmdclass
keyword in setup.cfg
has been fixed in v54. It is still not documented though.
Now you can do:
setup.cfg
(only part)
[options]
cmdclass =
install = build.MyInstall
build.py
from setuptools.command.install import install
class MyInstall(install):
def run(self):
print("Custom install start")
super().run()
print("Custom install done")
Both files are located in the root of project.
When you run python setup.py install
, the custom install script gets triggered. This setup is equivalent to the setup(cmdclass=...)
you used.
Upvotes: 2
Reputation: 26845
What [options.entry_points]
and console_scripts
does is create shell commands which run specific functions in your code base. These commands will work once your package has been installed in an environment.
So in your example, a new shell command install
would be created, and it would run the run()
function from a package called CustomInstall
.
Based on looking at source code, I would guess the correct syntax is instead:
[global]
commands =
install = mypackage.CustomInstall
but I haven't been able to make it work either yet.
Upvotes: 0