feat: do not include rust files in python package (#91)
This commit is contained in:
6
.github/workflows/python-build.yml
vendored
6
.github/workflows/python-build.yml
vendored
@@ -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 }}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"]
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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<String>) -> Result<Vec<u8>> {
|
||||
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)?)
|
||||
|
||||
@@ -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<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")))
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user