Skip to content

Commit

Permalink
feat: do not include rust files in python package
Browse files Browse the repository at this point in the history
  • Loading branch information
cocool97 committed Feb 11, 2025
1 parent 728d960 commit c2588e0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
run: pip install ".[build]"

- 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 }}

Expand Down
5 changes: 5 additions & 0 deletions pyadb_client/src/adb_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
let address = address.parse::<SocketAddrV4>()?;
Ok(ADBServer::new(address).into())
}

/// List available devices
pub fn devices(&mut self) -> Result<Vec<PyDeviceShort>> {
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<PyADBServerDevice> {
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<PyADBServerDevice> {
Ok(self.0.get_device_by_name(&name)?.into())
}
Expand Down
5 changes: 5 additions & 0 deletions pyadb_client/src/adb_server_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,33 @@ 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<String>) -> Result<Vec<u8>> {
let mut output = Vec::new();
let commands: Vec<&str> = commands.iter().map(|x| &**x).collect();
self.0.shell_command(&commands, &mut output)?;
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)?)
Expand Down
4 changes: 4 additions & 0 deletions pyadb_client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![forbid(missing_docs)]
#![doc = include_str!("../README.md")]

mod adb_server;
mod adb_server_device;
mod adb_usb_device;
Expand All @@ -20,6 +23,7 @@ fn pyadb_client(m: &Bound<'_, PyModule>) -> PyResult<()> {
Ok(())
}

/// Get stub informations for this package.
pub fn stub_info() -> anyhow::Result<StubInfo> {
// Need to be run from workspace root directory
StubInfo::from_pyproject_toml("pyproject.toml")
Expand Down
3 changes: 3 additions & 0 deletions pyadb_client/src/models/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ requires-python = ">= 3.7"
build = ["maturin", "patchelf"]

[tool.maturin]
include = [{ path = "adb_client/**/*", format = "sdist" }]
features = ["pyo3/extension-module"]
manifest-path = "pyadb_client/Cargo.toml"

0 comments on commit c2588e0

Please sign in to comment.