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

Fixed merging. #15

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
4 changes: 0 additions & 4 deletions .gitignore
FerrisWasTaken marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@ Cargo.lock

# Visual Studio Code
*.code-workspace
/.vscode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
.history/
*.vsix
.vscode

# Packaging
/packaging/**/pkg
Expand Down
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"rust-analyzer.showUnlinkedFileNotification": false,
"rust-analyzer.cargo.features": [
"extism_support"
]
}
19 changes: 11 additions & 8 deletions Cargo.toml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the resolver that is no longer the default in newer editions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the newer resolver causes extism to stop being resolved

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you find any documentation on why this has to be done? It seems strange

Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
[workspace]

members = [
"paxy",
"paxy-cli",
"paxy-gui", "paxy-plugin",
"tests"
]
default-members = [
"paxy",
"paxy-cli",
"paxy-gui",

"tests",
"tests"
]

resolver = "2"

resolver = "1"

[workspace.package]

Expand All @@ -20,7 +22,7 @@ homepage = "https://pax-hub.github.io/"
authors = [
"shivanandvp <pvshvp.oss@gmail.com, shivanandvp@rebornos.org>",
"lylythechosenone",
"ferriswastaken",
"Ishaan S <ishaans.code@gmail.com>",
"flyingcakes85",
]
keywords = ["package", "package-manager", "paxy", "packager"]
Expand Down Expand Up @@ -52,7 +54,8 @@ snafu = "0.8"

# Data
lazy_static = "1.4"
serde = { version = "1.0", features = ["derive"] }
semver = {git = "https://github.com/FerrisWasTaken/semver.git", features = ["extism_support"]}
serde = { version = "1.0.200", features = ["derive"] }
serde-aux = "4.5"
serde_yaml = "0.9"
tracing-serde = "0.1"
Expand Down
4 changes: 4 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM archlinux:latest
ENV RUSTC_WRAPPER=sccache
ENV CARGO_INCREMENTAL=0
ENV CARGO_TARGET_DIR=/paxy/podman-target
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.cargo/bin

# Install Rust
RUN pacman -Sy --noconfirm rustup cargo
Expand All @@ -13,3 +14,6 @@ RUN rustup default nightly-2024-03-17
RUN pacman -Sy --noconfirm gdk-pixbuf2 pango gtk4 pkg-config
# Extras
RUN pacman -S --noconfirm sccache
RUN cargo install cargo-make
RUN cargo install cargo-binstall
RUN cargo binstall --no-confirm wasmer-cli
2 changes: 2 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tasks.build]
args = ["build"]
25 changes: 25 additions & 0 deletions paxy-plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cargo-features = ["per-package-target"]
[package]
name = "paxy-plugin"
version.workspace = true
description.workspace = true
repository.workspace = true
homepage.workspace = true
authors.workspace = true
keywords.workspace = true
exclude.workspace = true
categories.workspace = true
documentation.workspace = true
readme.workspace = true
edition.workspace = true
license.workspace = true
default-target = "wasm32-wasi"

[dependencies]
extism-pdk = "1.1.0"
toml = "0.8.12"
semver = { workspace = true, features = ["extism_support"]}
reqwest = { version = "0.11", features = ["blocking", "json"] }

[lib]
crate-type = ["cdylib"]
13 changes: 13 additions & 0 deletions paxy-plugin/examples/paxy.px
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name = "Paxy"
repo = "https://github.com/Pax-Hub/paxy"

[[version]]
ver = "0.1.0"
src = "https://github.com/Pax-hub/paxy/releases/tag/0.1.0"
dependencies = ["rust >= 1.72.0"]
install_inst = "mv pkg/paxy /usr/bin"

[[version]]
ver = "0.1.1"
src = "https://github.com/Pax-hub/paxy/releases/tag/0.1.1"
install_inst = "mv /pkg/paxy /usr/bin"
64 changes: 64 additions & 0 deletions paxy-plugin/src/lib.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the name could be a bit more clear to distinguish from an actual plugin. Just an opinion

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paxy-plugin functions like any user plugin i.e. it is a ln actual plugin

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this plugin for? And why is it within the Paxy repository?

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use std::{fs, process::Command};

use extism_pdk::{plugin_fn, FnResult, Json};
use semver::{Version, VersionReq};
use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct Pkg {
name: String,
repo: String,
version: Vec<Ver>,
}

#[derive(Debug, Deserialize)]
struct Ver {
ver: Version,
dependencies: Vec<VersionReq>,
src: String,
install_inst: String,
}

fn parse_file() -> Pkg {
toml::from_str(
fs::read_to_string("/pkg")
.unwrap()
.as_str(),
)
.expect("invalid file")
}

fn exec_inst(commands: String) {
for stmt in commands.split(';') {
let mut args = stmt
.split(' ')
.collect::<Vec<&str>>();
let mut cmd = Command::new(
args.get(0)
.expect("malformed command"),
);
args.remove(0);
cmd.args(args);
let mut handle = match cmd.spawn() {
Ok(c) => c,
Err(_) => panic!("Illegal expression: {stmt}"),
};
handle
.wait()
.unwrap();
}
}

#[plugin_fn]
pub fn prep(req: Json<Version>) -> FnResult<String> {
let pkg = parse_file();
let ver;
let req = req.0;
for version in pkg.version {
if version.ver == req {
ver = version;
break;
}
}
todo!()
}
3 changes: 3 additions & 0 deletions paxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ url = { version = "2.3", features = ["serde"] }
extism = "1.2.0"
bson = "2.9.0"
git2 = {version = "0.18.3", default-features = false, features = ["https"]}

[dev-dependencies]
serial_test = "3.1.1"
41 changes: 41 additions & 0 deletions paxy/src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,49 @@ pub enum Error {
RepositoryError { source: repository::Error },
}

#[macro_export]
macro_rules! home {
() => {
match home::home_dir() {
Some(path) => path,
None => panic!("Impossible to get your home dir!"),
}
};
}

#[inline]
pub fn ensure_path(path: Option<&PathBuf>) {
if path.is_none() {
let mut file = home!();
file.push(".paxy");
if !file.is_dir() {
::std::fs::create_dir_all(file).expect("Inufficient permissions");
}
} else {
if !path
.unwrap()
.is_dir()
{
::std::fs::create_dir_all(
path.unwrap()
.clone(),
)
.expect("Inufficient permissions");
}
}
}

#[inline]
pub(crate) fn ensure_file<F: Fn(File)>(file: &PathBuf, f: F) {
if !file.is_file() {
f(File::create(file).unwrap())
}
}

// region: IMPORTS

use std::{fs::File, path::{Path, PathBuf}};

use snafu::Snafu;

// endregion: IMPORTS
Expand Down
30 changes: 20 additions & 10 deletions paxy/src/actions/repository/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn add_repo(repo: &str, name: &str) {
file.push("repos.bson");
let mut doc = if !file.is_file() {
warn!("file not found. Creating");
let doc = doc! {"paxy-official": "https://github.com/Pax-Hub/paxy-pkg-repository.git"};
let doc = doc! {"paxy-pkgs": "https://github.com/Pax-Hub/paxy-pkg-repository.git"};
let mut buf = vec![];
doc.to_writer(&mut buf)
.unwrap();
Expand All @@ -25,7 +25,10 @@ fn add_repo(repo: &str, name: &str) {
file.push("repos");
file.push(name);
ensure_path(Some(&file));
Repository::clone(repo, file).unwrap();
if Repository::clone(repo, file.clone()).is_err() {
remove_dir_all(file.clone()).unwrap();
Repository::clone(repo, file);
}
}

#[allow(dead_code)]
Expand All @@ -45,7 +48,7 @@ pub enum Error {
// region: IMPORTS

use std::{
fs::{write, File},
fs::{remove_dir_all, write, File},
path::PathBuf,
};

Expand All @@ -54,26 +57,33 @@ use git2::Repository;
use log::{info, warn};
use snafu::Snafu;

use crate::actions::repository::ensure_path;
use crate::actions::ensure_path;

// endregion: IMPORTS

// region: TESTS

#[cfg(test)]
mod tests {
use std::fs;

use super::*;
use serial_test::serial;

#[test]
fn add_repo_norm_test() {
#[serial]
fn repo_add_norm() {
let mut repo_file = home!();
repo_file.push(".paxy");
repo_file.push("repos.bson");
if repo_file.is_file() {
fs::remove_file(&repo_file).unwrap();
}
add_repo("https://github.com/Pax-Hub/paxy-pkg-repository.git", "paxy");
let mut file = home!();
file.push(".paxy");
file.push("repos.bson");
let doc = Document::from_reader(File::open(file.clone()).unwrap()).unwrap();
let doc = Document::from_reader(File::open(repo_file.clone()).unwrap()).unwrap();
assert_eq!(
doc,
doc! {"paxy-official": "https://github.com/Pax-Hub/paxy-pkg-repository.git", "paxy": "https://github.com/Pax-Hub/paxy-pkg-repository.git"}
doc! {"paxy-pkgs": "https://github.com/Pax-Hub/paxy-pkg-repository.git", "paxy": "https://github.com/Pax-Hub/paxy-pkg-repository.git"}
);
}
}
Expand Down
32 changes: 0 additions & 32 deletions paxy/src/actions/repository/mod.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,3 @@
#[macro_export]
macro_rules! home {
() => {
match home::home_dir() {
Some(path) => path,
None => panic!("Impossible to get your home dir!"),
}
};
}

#[inline]
pub fn ensure_path(path: Option<&PathBuf>) {
if path.is_none() {
let mut file = home!();
file.push(".paxy");
if !file.is_dir() {
::std::fs::create_dir_all(file).expect("Inufficient permissions");
}
} else {
if !path
.unwrap()
.is_dir()
{
::std::fs::create_dir_all(
path.unwrap()
.clone(),
)
.expect("Inufficient permissions");
}
}
}

#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum Error {
Expand Down
Empty file added paxy/src/actions/rm_repo.rs
Empty file.
9 changes: 3 additions & 6 deletions paxy/src/app/config.rs
FerrisWasTaken marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ pub fn init_config(config_filepath: Option<&Path>) -> Result<(Config, Vec<PathBu
// Merge configuration values from global and local filepaths
figment = candidate_config_filepath_stubs
.iter()
.fold(
figment,
move |figment, candidate_config_filepath_stub| {
admerge_from_stub(candidate_config_filepath_stub, figment)
},
);
.fold(figment, move |figment, candidate_config_filepath_stub| {
admerge_from_stub(candidate_config_filepath_stub, figment)
});

// Merge configuration values from environment variables
figment = figment.admerge(Env::prefixed(&format!("{}_", *app::APP_NAME)));
Expand Down
1 change: 1 addition & 0 deletions paxy/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ pub use config::*;
pub use i18n::*;
#[allow(unused_imports)]
pub use logging::*;
mod plugins;

// endregion: RE-EXPORTS
Loading
Loading