diff --git a/.github/workflows/python-build.yml b/.github/workflows/python-build.yml index 34e03c9..c236663 100644 --- a/.github/workflows/python-build.yml +++ b/.github/workflows/python-build.yml @@ -22,7 +22,7 @@ jobs: - uses: actions/checkout@v4 - name: Install Python build dependencies - run: pip install ".[build]" + run: pip install maturin==1.8.2 - name: Build Python packages run: maturin build --release -m pyadb_client/Cargo.toml --compatibility manylinux_2_25 --auditwheel=skip @@ -36,10 +36,10 @@ jobs: - uses: actions/checkout@v4 - name: Install Python build dependencies - run: pip install ".[build]" + run: pip install maturin==1.8.2 - name: Publish Python packages - run: maturin publish --non-interactive --compatibility manylinux_2_25 --auditwheel=skip + run: maturin publish -m pyadb_client/Cargo.toml --non-interactive --compatibility manylinux_2_25 --auditwheel=skip env: MATURIN_PYPI_TOKEN: ${{ secrets.MATURIN_PYPI_TOKEN }} diff --git a/pyadb_client/README.md b/pyadb_client/README.md index 964b20e..4e5c98e 100644 --- a/pyadb_client/README.md +++ b/pyadb_client/README.md @@ -42,7 +42,7 @@ python3 -m venv .venv source .venv/bin/activate # Install needed build dependencies -pip install ".[build]" +pip install maturin # Build development package maturin develop diff --git a/pyproject.toml b/pyadb_client/pyproject.toml similarity index 57% rename from pyproject.toml rename to pyadb_client/pyproject.toml index 0c97996..3f06f89 100644 --- a/pyproject.toml +++ b/pyadb_client/pyproject.toml @@ -8,10 +8,5 @@ dynamic = ["authors", "keywords", "version"] name = "pyadb_client" requires-python = ">= 3.7" -[project.optional-dependencies] -build = ["maturin", "patchelf"] - [tool.maturin] -include = [{ path = "adb_client/**/*", format = "sdist" }] -features = ["pyo3/extension-module"] -manifest-path = "pyadb_client/Cargo.toml" +features = ["pyo3/extension-module"] \ No newline at end of file diff --git a/pyadb_client/src/adb_server.rs b/pyadb_client/src/adb_server.rs index 9a15aea..f69dac5 100644 --- a/pyadb_client/src/adb_server.rs +++ b/pyadb_client/src/adb_server.rs @@ -9,25 +9,30 @@ use crate::{PyADBServerDevice, PyDeviceShort}; #[gen_stub_pyclass] #[pyclass] +/// Represent an instance of an ADB Server pub struct PyADBServer(ADBServer); #[gen_stub_pymethods] #[pymethods] impl PyADBServer { #[new] + /// Instantiate a new PyADBServer instance pub fn new(address: String) -> PyResult { let address = address.parse::()?; Ok(ADBServer::new(address).into()) } + /// List available devices pub fn devices(&mut self) -> Result> { Ok(self.0.devices()?.into_iter().map(|v| v.into()).collect()) } + /// Get a device, assuming that only one is currently connected pub fn get_device(&mut self) -> Result { Ok(self.0.get_device()?.into()) } + /// Get a device by its name, as shown in `.devices()` output pub fn get_device_by_name(&mut self, name: String) -> Result { Ok(self.0.get_device_by_name(&name)?.into()) } diff --git a/pyadb_client/src/adb_server_device.rs b/pyadb_client/src/adb_server_device.rs index 397fff3..0bf3c6a 100644 --- a/pyadb_client/src/adb_server_device.rs +++ b/pyadb_client/src/adb_server_device.rs @@ -6,16 +6,19 @@ use std::{fs::File, path::PathBuf}; #[gen_stub_pyclass] #[pyclass] +/// Represent a device connected to the ADB server pub struct PyADBServerDevice(pub ADBServerDevice); #[gen_stub_pymethods] #[pymethods] impl PyADBServerDevice { #[getter] + /// Device identifier pub fn identifier(&self) -> String { self.0.identifier.clone() } + /// Run shell commands on device and return the output (stdout + stderr merged) pub fn shell_command(&mut self, commands: Vec) -> Result> { let mut output = Vec::new(); let commands: Vec<&str> = commands.iter().map(|x| &**x).collect(); @@ -23,11 +26,13 @@ impl PyADBServerDevice { Ok(output) } + /// Push a local file from input to dest pub fn push(&mut self, input: PathBuf, dest: PathBuf) -> Result<()> { let mut reader = File::open(input)?; Ok(self.0.push(&mut reader, dest.to_string_lossy())?) } + /// Pull a file from device located at input, and drop it to dest pub fn pull(&mut self, input: PathBuf, dest: PathBuf) -> Result<()> { let mut writer = File::create(dest)?; Ok(self.0.pull(&input.to_string_lossy(), &mut writer)?) diff --git a/pyadb_client/src/lib.rs b/pyadb_client/src/lib.rs index 42f9666..91b7a24 100644 --- a/pyadb_client/src/lib.rs +++ b/pyadb_client/src/lib.rs @@ -1,3 +1,6 @@ +#![forbid(missing_docs)] +#![doc = include_str!("../README.md")] + mod adb_server; mod adb_server_device; mod adb_usb_device; @@ -20,7 +23,8 @@ fn pyadb_client(m: &Bound<'_, PyModule>) -> PyResult<()> { Ok(()) } +/// Get stub informations for this package. pub fn stub_info() -> anyhow::Result { // Need to be run from workspace root directory - StubInfo::from_pyproject_toml("pyproject.toml") + StubInfo::from_pyproject_toml(format!("{}/pyproject.toml", env!("CARGO_MANIFEST_DIR"))) } diff --git a/pyadb_client/src/models/devices.rs b/pyadb_client/src/models/devices.rs index ef2c15b..3ace3ef 100644 --- a/pyadb_client/src/models/devices.rs +++ b/pyadb_client/src/models/devices.rs @@ -6,17 +6,20 @@ use pyo3_stub_gen_derive::{gen_stub_pyclass, gen_stub_pymethods}; #[gen_stub_pyclass] #[pyclass] +/// Represent a device output as shown when running `adb devices` pub struct PyDeviceShort(DeviceShort); #[gen_stub_pymethods] #[pymethods] impl PyDeviceShort { #[getter] + /// Device identifier pub fn identifier(&self) -> String { self.0.identifier.clone() } #[getter] + /// Device state pub fn state(&self) -> String { self.0.state.to_string() }