mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Restrict python library to 3.7abi (so compatible with 3.7 and everything after that)
This commit is contained in:
@@ -15,5 +15,10 @@ name = "velopack_python"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
velopack.workspace = true
|
||||
pyo3.workspace = true
|
||||
pyo3-log.workspace = true
|
||||
|
||||
[build-dependencies]
|
||||
pyo3-build-config.workspace = true
|
||||
|
||||
@@ -3,6 +3,8 @@ use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
fn main() {
|
||||
pyo3_build_config::add_extension_module_link_args();
|
||||
|
||||
// Get the workspace version
|
||||
let version = get_workspace_version().unwrap_or_else(|| env::var("CARGO_PKG_VERSION").unwrap_or_else(|_| "0.1.0".to_string()));
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyFunction;
|
||||
use pyo3::types::PyCFunction;
|
||||
|
||||
use velopack::VelopackApp as VelopackAppRust;
|
||||
|
||||
@@ -7,12 +7,12 @@ use velopack::VelopackApp as VelopackAppRust;
|
||||
#[pyclass(name = "App")]
|
||||
pub struct VelopackAppWrapper {
|
||||
// We'll store the callbacks as Python objects
|
||||
install_hook: Option<Py<PyFunction>>,
|
||||
update_hook: Option<Py<PyFunction>>,
|
||||
obsolete_hook: Option<Py<PyFunction>>,
|
||||
uninstall_hook: Option<Py<PyFunction>>,
|
||||
firstrun_hook: Option<Py<PyFunction>>,
|
||||
restarted_hook: Option<Py<PyFunction>>,
|
||||
install_hook: Option<Py<PyCFunction>>,
|
||||
update_hook: Option<Py<PyCFunction>>,
|
||||
obsolete_hook: Option<Py<PyCFunction>>,
|
||||
uninstall_hook: Option<Py<PyCFunction>>,
|
||||
firstrun_hook: Option<Py<PyCFunction>>,
|
||||
restarted_hook: Option<Py<PyCFunction>>,
|
||||
auto_apply: bool,
|
||||
args: Option<Vec<String>>,
|
||||
}
|
||||
@@ -47,37 +47,37 @@ impl VelopackAppWrapper {
|
||||
}
|
||||
|
||||
/// This hook is triggered when the application is started for the first time after installation
|
||||
pub fn on_first_run(mut slf: PyRefMut<Self>, callback: Py<PyFunction>) -> PyRefMut<Self> {
|
||||
pub fn on_first_run(mut slf: PyRefMut<Self>, callback: Py<PyCFunction>) -> PyRefMut<Self> {
|
||||
slf.firstrun_hook = Some(callback);
|
||||
slf
|
||||
}
|
||||
|
||||
/// This hook is triggered when the application is restarted by Velopack after installing updates
|
||||
pub fn on_restarted(mut slf: PyRefMut<Self>, callback: Py<PyFunction>) -> PyRefMut<Self> {
|
||||
pub fn on_restarted(mut slf: PyRefMut<Self>, callback: Py<PyCFunction>) -> PyRefMut<Self> {
|
||||
slf.restarted_hook = Some(callback);
|
||||
slf
|
||||
}
|
||||
|
||||
/// Fast callback hook for after installation (Windows only)
|
||||
pub fn on_after_install_fast_callback(mut slf: PyRefMut<Self>, callback: Py<PyFunction>) -> PyRefMut<Self> {
|
||||
pub fn on_after_install_fast_callback(mut slf: PyRefMut<Self>, callback: Py<PyCFunction>) -> PyRefMut<Self> {
|
||||
slf.install_hook = Some(callback);
|
||||
slf
|
||||
}
|
||||
|
||||
/// Fast callback hook for after update (Windows only)
|
||||
pub fn on_after_update_fast_callback(mut slf: PyRefMut<Self>, callback: Py<PyFunction>) -> PyRefMut<Self> {
|
||||
pub fn on_after_update_fast_callback(mut slf: PyRefMut<Self>, callback: Py<PyCFunction>) -> PyRefMut<Self> {
|
||||
slf.update_hook = Some(callback);
|
||||
slf
|
||||
}
|
||||
|
||||
/// Fast callback hook for before update (Windows only)
|
||||
pub fn on_before_update_fast_callback(mut slf: PyRefMut<Self>, callback: Py<PyFunction>) -> PyRefMut<Self> {
|
||||
pub fn on_before_update_fast_callback(mut slf: PyRefMut<Self>, callback: Py<PyCFunction>) -> PyRefMut<Self> {
|
||||
slf.obsolete_hook = Some(callback);
|
||||
slf
|
||||
}
|
||||
|
||||
/// Fast callback hook for before uninstall (Windows only)
|
||||
pub fn on_before_uninstall_fast_callback(mut slf: PyRefMut<Self>, callback: Py<PyFunction>) -> PyRefMut<Self> {
|
||||
pub fn on_before_uninstall_fast_callback(mut slf: PyRefMut<Self>, callback: Py<PyCFunction>) -> PyRefMut<Self> {
|
||||
slf.uninstall_hook = Some(callback);
|
||||
slf
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
use pyo3::exceptions::PyException;
|
||||
use pyo3::prelude::*;
|
||||
|
||||
#[pyclass(name="VelopackError", extends=PyException, module="velopack.exceptions")]
|
||||
#[derive(Debug)]
|
||||
pub struct VelopackError {
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl VelopackError {
|
||||
#[new]
|
||||
fn new(message: String) -> Self {
|
||||
VelopackError { message }
|
||||
}
|
||||
|
||||
fn __str__(&self) -> String {
|
||||
self.message.clone()
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,6 @@ use pyo3::types::PyModule;
|
||||
mod types;
|
||||
use types::*;
|
||||
|
||||
mod exceptions;
|
||||
use exceptions::VelopackError;
|
||||
|
||||
mod app;
|
||||
use app::VelopackAppWrapper;
|
||||
|
||||
@@ -15,8 +12,8 @@ use manager::UpdateManagerWrapper;
|
||||
|
||||
#[pymodule]
|
||||
fn velopack(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||
m.add_class::<VelopackError>()?;
|
||||
|
||||
pyo3_log::init();
|
||||
|
||||
// auto-generated DTO's
|
||||
m.add_class::<PyVelopackAsset>()?;
|
||||
m.add_class::<PyUpdateInfo>()?;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use anyhow::Result;
|
||||
use pyo3::prelude::*;
|
||||
use std::sync::mpsc;
|
||||
use std::thread;
|
||||
@@ -5,7 +6,6 @@ use std::thread;
|
||||
use velopack::sources::AutoSource;
|
||||
use velopack::{UpdateCheck, UpdateInfo, UpdateManager as VelopackUpdateManagerRust};
|
||||
|
||||
use crate::exceptions::VelopackError;
|
||||
use crate::types::*;
|
||||
|
||||
#[pyclass(name = "UpdateManager")]
|
||||
@@ -15,23 +15,17 @@ pub struct UpdateManagerWrapper {
|
||||
|
||||
#[pymethods]
|
||||
impl UpdateManagerWrapper {
|
||||
// for new, just take in a string, which is the source
|
||||
#[new]
|
||||
#[pyo3(signature = (source, options = None, locator = None))]
|
||||
pub fn new(source: String, options: Option<PyUpdateOptions>, locator: Option<PyVelopackLocatorConfig>) -> PyResult<Self> {
|
||||
pub fn new(source: String, options: Option<PyUpdateOptions>, locator: Option<PyVelopackLocatorConfig>) -> Result<Self> {
|
||||
let source = AutoSource::new(&source);
|
||||
// set myinner to a new VelopackUpdateManager with the source
|
||||
let inner = VelopackUpdateManagerRust::new(source, options.map(Into::into), locator.map(Into::into))
|
||||
.map_err(|e| PyErr::new::<VelopackError, _>(format!("Failed to create UpdateManager: {}", e)))?;
|
||||
let inner = VelopackUpdateManagerRust::new(source, options.map(Into::into), locator.map(Into::into))?;
|
||||
Ok(UpdateManagerWrapper { inner })
|
||||
}
|
||||
|
||||
// check_for_updates return update info indicating if updates are available
|
||||
/// This method checks for updates and returns update info if updates are available, None otherwise.
|
||||
pub fn check_for_updates(&mut self) -> PyResult<Option<PyUpdateInfo>> {
|
||||
let update_check =
|
||||
self.inner.check_for_updates().map_err(|e| PyErr::new::<VelopackError, _>(format!("Failed to check for updates: {}", e)))?;
|
||||
|
||||
pub fn check_for_updates(&mut self) -> Result<Option<PyUpdateInfo>> {
|
||||
let update_check = self.inner.check_for_updates()?;
|
||||
match update_check {
|
||||
UpdateCheck::UpdateAvailable(updates) => {
|
||||
let py_updates = PyUpdateInfo::from(updates);
|
||||
@@ -43,7 +37,7 @@ impl UpdateManagerWrapper {
|
||||
}
|
||||
|
||||
#[pyo3(signature = (update_info, progress_callback = None))]
|
||||
pub fn download_updates(&mut self, update_info: &PyUpdateInfo, progress_callback: Option<PyObject>) -> PyResult<()> {
|
||||
pub fn download_updates(&mut self, update_info: &PyUpdateInfo, progress_callback: Option<PyObject>) -> Result<()> {
|
||||
// Convert PyUpdateInfo back to rust UpdateInfo
|
||||
let rust_update_info: UpdateInfo = update_info.clone().into();
|
||||
|
||||
@@ -65,31 +59,22 @@ impl UpdateManagerWrapper {
|
||||
});
|
||||
|
||||
// Call download with the sender
|
||||
let result = self
|
||||
.inner
|
||||
.download_updates(&rust_update_info, Some(sender))
|
||||
.map_err(|e| PyErr::new::<VelopackError, _>(format!("Failed to download updates: {}", e)));
|
||||
let result = self.inner.download_updates(&rust_update_info, Some(sender))?;
|
||||
|
||||
// Wait for the progress thread to finish
|
||||
let _ = progress_thread.join();
|
||||
|
||||
result.map(|_| ())
|
||||
Ok(result)
|
||||
} else {
|
||||
// No progress callback provided
|
||||
self.inner
|
||||
.download_updates(&rust_update_info, None)
|
||||
.map_err(|e| PyErr::new::<VelopackError, _>(format!("Failed to download updates: {}", e)))
|
||||
.map(|_| ())
|
||||
self.inner.download_updates(&rust_update_info, None)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_updates_and_restart(&mut self, update_info: &PyUpdateInfo) -> PyResult<()> {
|
||||
pub fn apply_updates_and_restart(&mut self, update_info: &PyUpdateInfo) -> Result<()> {
|
||||
// Convert PyUpdateInfo back to rust UpdateInfo
|
||||
let rust_update_info: UpdateInfo = update_info.clone().into();
|
||||
|
||||
self.inner
|
||||
.apply_updates_and_restart(&rust_update_info)
|
||||
.map_err(|e| PyErr::new::<VelopackError, _>(format!("Failed to apply updates and restart: {}", e)))
|
||||
.map(|_| ())
|
||||
self.inner.apply_updates_and_restart(&rust_update_info)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user