annotate rust/chg/src/runcommand.rs @ 52664:f5091286b10c

packaging: modernize (compat PEP 517) with less distutils and setup.py calls - setup.py: less distutils imports and setuptools required distutils is deprecated and one should import commands from setuptools to support modern workflows depending on PEP 517 and 518. Moreover, for Python >=3.12, distutils comes from setuptools. It corresponds to old and unmaintain code that do not support PEP 517. The PEP 517 frontends (pip, build, pipx, PDM, UV, etc.) are responsible for creating a venv just for the build. The build dependencies (currently only setuptools) are specified in the pyproject.toml file. Therefore, there is no reason to support building without setuptools. Calling directly setup.py is deprecated and we have to use a PEP 517 frontend. For this commit we use pip with venv. - run-tests.py: install with pip instead of direct call of setup.py Mercurial is then built in an isolated environment. - Makefile: use venv+pip instead of setup.py
author paugier <pierre.augier@univ-grenoble-alpes.fr>
date Wed, 08 Jan 2025 05:07:00 +0100
parents 426294d06ddc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
1 // Copyright 2018 Yuya Nishihara <yuya@tcha.org>
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
2 //
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
3 // This software may be used and distributed according to the terms of the
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
4 // GNU General Public License version 2 or any later version.
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
5
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
6 //! Functions to run Mercurial command in cHg-aware command server.
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
7
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
8 use bytes::Bytes;
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
9 use std::io;
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
10 use std::os::unix::io::AsRawFd;
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
11 use tokio_hglib::codec::ChannelMessage;
44751
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
12 use tokio_hglib::{Connection, Protocol};
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
13
44751
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
14 use crate::attachio;
44689
6bef9d43cc55 rust-chg: use "crate::" to import local modules
Yuya Nishihara <yuya@tcha.org>
parents: 44685
diff changeset
15 use crate::message::{self, CommandType};
6bef9d43cc55 rust-chg: use "crate::" to import local modules
Yuya Nishihara <yuya@tcha.org>
parents: 44685
diff changeset
16 use crate::uihandler::SystemHandler;
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
17
44751
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
18 /// Runs the given Mercurial command in cHg-aware command server, and
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
19 /// fetches the result code.
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
20 ///
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
21 /// This is a subset of tokio-hglib's `run_command()` with the additional
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
22 /// SystemRequest support.
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
23 pub async fn run_command(
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
24 proto: &mut Protocol<impl Connection + AsRawFd>,
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
25 handler: &mut impl SystemHandler,
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
26 packed_args: impl Into<Bytes>,
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
27 ) -> io::Result<i32> {
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
28 proto
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
29 .send_command_with_args("runcommand", packed_args)
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
30 .await?;
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
31 loop {
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
32 match proto.fetch_response().await? {
44695
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
33 ChannelMessage::Data(b'r', data) => {
44751
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
34 return message::parse_result_code(data);
44695
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
35 }
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
36 ChannelMessage::Data(..) => {
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
37 // just ignores data sent to optional channel
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
38 }
45620
426294d06ddc rust: move rustfmt.toml to repo root so it can be used by `hg fix`
Martin von Zweigbergk <martinvonz@google.com>
parents: 44751
diff changeset
39 ChannelMessage::InputRequest(..)
426294d06ddc rust: move rustfmt.toml to repo root so it can be used by `hg fix`
Martin von Zweigbergk <martinvonz@google.com>
parents: 44751
diff changeset
40 | ChannelMessage::LineRequest(..) => {
44751
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
41 return Err(io::Error::new(
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
42 io::ErrorKind::InvalidData,
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
43 "unsupported request",
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
44 ));
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
45 }
44695
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
46 ChannelMessage::SystemRequest(data) => {
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
47 let (cmd_type, cmd_spec) = message::parse_command_spec(data)?;
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
48 match cmd_type {
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
49 CommandType::Pager => {
44751
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
50 // server spins new command loop while pager request is
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
51 // in progress, which can be terminated by "" command.
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
52 let pin = handler.spawn_pager(&cmd_spec).await?;
45620
426294d06ddc rust: move rustfmt.toml to repo root so it can be used by `hg fix`
Martin von Zweigbergk <martinvonz@google.com>
parents: 44751
diff changeset
53 attachio::attach_io(proto, &io::stdin(), &pin, &pin)
426294d06ddc rust: move rustfmt.toml to repo root so it can be used by `hg fix`
Martin von Zweigbergk <martinvonz@google.com>
parents: 44751
diff changeset
54 .await?;
44751
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
55 proto.send_command("").await?; // terminator
44695
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
56 }
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
57 CommandType::System => {
44751
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
58 let code = handler.run_system(&cmd_spec).await?;
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
59 let data = message::pack_result_code(code);
94cace4b80ea rust-chg: reimplement run_command operation as async function
Yuya Nishihara <yuya@tcha.org>
parents: 44695
diff changeset
60 proto.send_data(data).await?;
44695
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
61 }
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
62 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
63 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
64 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
65 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
66 }