Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: do not include rust files in python package #91

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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