How to get native argument values for postinstall hook? #231
Replies: 2 comments 2 replies
-
Hi @mgzenitech, Today this is not possible with the poethepoet poetry plugin. The first problem with this is to determine whether it's possible with the poetry plugin interface. I'd encourage you to poke around in here if you'f like toto help answer that question. The second problem is how to structure an API that poe could expose to facilitate configuring this. Ideally without deviating too much from how poe normally handled arguments. How would you expect it to work? |
Beta Was this translation helpful? Give feedback.
-
and this is what chatgpt spit out. Even if it's incorrect maybe it'll give some ideas on how to implement this... Step 1: Capture Arguments from the Install Command import cleo.application
continue_run = cleo.application.Application._run
def _run(self, io):
tokens = io.input._tokens
task_name_index = _index_of_first_non_option(tokens)
poe_commands = (prefix,) if prefix else task_names
# Check if the command is 'install'
if 0 <= task_name_index < len(tokens) and tokens[task_name_index] == 'install':
# Capture all arguments after 'install'
install_args = tokens[task_name_index+1:]
# Store these args in the application for later use
self.install_args = install_args
elif 0 <= task_name_index < len(tokens) and tokens[task_name_index] in poe_commands:
# Insert '--' to handle other poe commands
tokens.insert(task_name_index, "--")
return continue_run(self, io)
cleo.application.Application._run = _run Step 2: Modify the Event Handler to Forward the Arguments def _get_command_event_handler(
self, hooks: Dict[str, str], application: Application
):
def command_event_handler(
event: ConsoleCommandEvent,
event_name: str,
dispatcher: EventDispatcher,
) -> None:
task = hooks.get(event.command.name)
if not task:
return
import shlex
# Get the stored install arguments
install_args = getattr(application, 'install_args', [])
# Prepare the full command including the install args
full_args = shlex.split(task) + install_args
task_status = PoeCommand.get_poe(application, event.io)(
cli_args=full_args, internal=True
)
if task_status:
event.io.write_line(
"<error>Cancelling command due to failed hook task</error>"
)
raise SystemExit(task_status)
return command_event_handler |
Beta Was this translation helpful? Give feedback.
-
So in my case I'd need to get the value of
--with=
when doingpoetry install
and pass it down to postinstall task. How can I pass the value to my function? For example--with=core,dev
In this case I'd need to pass this argument to both
lib.utils.nodejs.are_packages_valid:are_packages_valid
andlib.utils.nodejs.sync_packages:sync_packages
.Beta Was this translation helpful? Give feedback.
All reactions