Skip to content

Instantly share code, notes, and snippets.

@drmalex07
Last active December 6, 2022 22:00
Show Gist options
  • Save drmalex07/866df4bb235ddd5ecf6f to your computer and use it in GitHub Desktop.
Save drmalex07/866df4bb235ddd5ecf6f to your computer and use it in GitHub Desktop.
Provide a custom setuptools command. #setuptools #distutils #setup.py
from setuptools import setup, find_packages
from distutils.cmd import Command
class Foo(Command):
description = "Run foo command"
user_options = [
('baz=', None, 'Baz Option'),
('dry-run', None, 'Dry run'),
]
def initialize_options(self):
self.baz = -1
self.dry_run = False
def finalize_options(self):
self.baz = int(self.baz)
self.dry_run = bool(self.dry_run)
def run(self):
print 'Running foo with baz=%d, dry=%r' % (self.baz, self.dry_run)
setup(
name='helloworld',
...
cmdclass = {
'foo': Foo
},
...
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment