Skip to content

Commit

Permalink
feat: do not include rust files in python package (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
cocool97 authored Feb 11, 2025
1 parent 728d960 commit f211023
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/python-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}

Expand Down
2 changes: 1 addition & 1 deletion pyadb_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions pyproject.toml → pyadb_client/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
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
6 changes: 5 additions & 1 deletion 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,7 +23,8 @@ 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")
StubInfo::from_pyproject_toml(format!("{}/pyproject.toml", env!("CARGO_MANIFEST_DIR")))
}
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

0 comments on commit f211023

Please sign in to comment.