Возможно, вы не опытный программист, как я, который все еще боролся после прочтения всех ответов выше. Таким образом, вы могли бы найти другой пример, потенциально полезный ( и адрес комментариев в предыдущих ответах о вводе аргументов командной строки ):
class RunClientCommand(Command):
"""
A command class to runs the client GUI.
"""
description = "runs client gui"
# The format is (long option, short option, description).
user_options = [
('socket=', None, 'The socket of the server to connect (e.g. '127.0.0.1:8000')',
]
def initialize_options(self):
"""
Sets the default value for the server socket.
The method is responsible for setting default values for
all the options that the command supports.
Option dependencies should not be set here.
"""
self.socket = '127.0.0.1:8000'
def finalize_options(self):
"""
Overriding a required abstract method.
The method is responsible for setting and checking the
final values and option dependencies for all the options
just before the method run is executed.
In practice, this is where the values are assigned and verified.
"""
pass
def run(self):
"""
Semantically, runs 'python src/client/view.py SERVER_SOCKET' on the
command line.
"""
print(self.socket)
errno = subprocess.call([sys.executable, 'src/client/view.py ' + self.socket])
if errno != 0:
raise SystemExit("Unable to run client GUI!")
setup(
# Some other omitted details
cmdclass={
'runClient': RunClientCommand,
},
Выше проверено и из некоторого кода, который я написал. Я также включил немного более подробные строки документации, чтобы упростить понимание.
Что касается командной строки: python setup.py runClient --socket=127.0.0.1:7777
. Быстрая двойная проверка с использованием операторов print показывает, что метод run действительно выбирает правильный аргумент.
Другие ресурсы, которые я нашел полезными ( больше и больше примеров):
Пользовательские команды distutils
https://seasonofcode.com/posts/how-to-add-custom-build-steps-and-commands-to-setuppy.html