Skip to content
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
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "3"
members = ["crates/pyo-proto", "crates/pyo-api", "crates/pyo-agent", "crates/pyo-builder", "crates/pyo-cli", "crates/pyo-flows", "crates/pyo-resp", "crates/pyo-kv", "crates/pyo-db-controller", "crates/pyo-static", "crates/pyo-envd", "crates/pyo-sandbox"]

[workspace.package]
version = "0.5.0"
version = "0.5.1"
edition = "2024"
license = "Apache-2.0"
publish = false
Expand Down
2 changes: 1 addition & 1 deletion crates/pyo-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish.workspace = true

[dependencies]
anyhow = "1.0.104"
pyo-proto = { version = "0.5.0", path = "../pyo-proto", features = ["command-signing"] }
pyo-proto = { version = "0.5.1", path = "../pyo-proto", features = ["command-signing"] }
futures = "0.3.34"
axum = { version = "0.8.9", default-features = false, features = ["http1", "tokio"] }
http = "1.5.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/pyo-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ axum = { version = "0.8.9", features = ["ws"] }
axum-extra = { version = "0.12.6", features = ["cookie", "typed-header"] }
base64 = "0.23.1"
cookie = "0.18"
pyo-proto = { version = "0.5.0", path = "../pyo-proto", features = ["openapi", "sandbox-token", "command-signing", "agent-ca"] }
pyo-proto = { version = "0.5.1", path = "../pyo-proto", features = ["openapi", "sandbox-token", "command-signing", "agent-ca"] }
hex = "0.4.3"
hmac = "0.13.0"
hyper = { version = "1.12.0", features = ["client", "http1"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/pyo-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ base64 = "0.23.1"
flate2 = "1"
futures = "0.3.34"
hex = "0.4.3"
pyo-proto = { version = "0.5.0", path = "../pyo-proto", features = ["command-signing"] }
pyo-proto = { version = "0.5.1", path = "../pyo-proto", features = ["command-signing"] }
reqwest = { version = "0.13.5", default-features = false, features = ["json", "rustls", "stream"] }
serde = "1.0.229"
serde_json = "1.0.154"
Expand Down
2 changes: 1 addition & 1 deletion crates/pyo-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tar = { version = "0.4.46", default-features = false }
tokio = { version = "1.54.1", features = ["rt-multi-thread", "macros", "net", "io-util", "io-std", "time", "sync", "fs"] }
tokio-tungstenite = { version = "0.29", features = ["rustls-tls-native-roots"] }
toml = "0.9"
pyo-proto = { version = "0.5.0", path = "../pyo-proto" }
pyo-proto = { version = "0.5.1", path = "../pyo-proto" }

[dev-dependencies]
# The JSON Schema of pyo.jsonc, written from the config types by a test.
Expand Down
158 changes: 116 additions & 42 deletions crates/pyo-cli/src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,8 @@ pub fn is_env_file(name: &str) -> bool {
)
}

/// The files of `root` to pack, in order.
pub fn list(root: &Path, with_env: bool) -> Result<Vec<Entry>> {
// The defaults as an ignore file of the lowest precedence, so the
// folder's own files can keep what they leave out.
let defaults = std::env::temp_dir().join(format!("pyo-defaults-{}.ignore", std::process::id()));
std::fs::write(&defaults, DEFAULT_IGNORES)?;
/// A walk over `root` that heeds the folder's own ignore files.
fn walker(root: &Path) -> ignore::WalkBuilder {
let mut walk = ignore::WalkBuilder::new(root);
walk.hidden(false)
.ignore(false)
Expand All @@ -56,50 +52,76 @@ pub fn list(root: &Path, with_env: bool) -> Result<Vec<Entry>> {
.require_git(false)
.parents(true)
.follow_links(false)
.add_custom_ignore_filename(".pyoignore")
.sort_by_file_name(|a, b| a.cmp(b))
.add_custom_ignore_filename(".pyoignore");
walk
}

/// The files of `root` to pack, in order.
pub fn list(root: &Path, with_env: bool) -> Result<Vec<Entry>> {
// The defaults rank below the folder's own ignore files: they leave a
// path out only when those files say nothing about it, so a `!` line
// there keeps it.
let mut defaults = ignore::gitignore::GitignoreBuilder::new(root);
for line in DEFAULT_IGNORES.lines() {
defaults.add_line(None, line)?;
}
let defaults = defaults.build()?;
let own = std::sync::Mutex::new(
walker(root)
.build_matchers()
.pop()
.context("Couldn't read the folder's ignore files")?,
);
let base = root.to_path_buf();
let mut walk = walker(root);
walk.sort_by_file_name(|a, b| a.cmp(b))
.filter_entry(move |e| {
let name = e.file_name().to_string_lossy();
if name == ".git" {
return false;
}
with_env || !(e.file_type().is_some_and(|t| !t.is_dir()) && is_env_file(&name))
});
if let Some(e) = walk.add_ignore(&defaults) {
let _ = std::fs::remove_file(&defaults);
return Err(e.into());
}
let mut out = vec![];
let result = (|| -> Result<()> {
for e in walk.build() {
let e = e?;
let Some(t) = e.file_type() else { continue };
if t.is_dir() {
continue;
if !with_env && e.file_type().is_some_and(|t| !t.is_dir()) && is_env_file(&name) {
return false;
}
let rel = e
.path()
.strip_prefix(root)
.unwrap_or(e.path())
.to_path_buf();
if rel.as_os_str().is_empty() {
continue;
let is_dir = e.file_type().is_some_and(|t| t.is_dir());
if defaults.matched(e.path(), is_dir).is_ignore() {
// The walk got here, so the folder's files don't leave it out.
// Keep it only if they keep it on purpose.
let rel = e.path().strip_prefix(&base).unwrap_or(e.path());
return own
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.matched(rel, is_dir)
.is_whitelist();
}
let size = if t.is_file() {
e.metadata().map(|m| m.len()).unwrap_or(0)
} else {
0
};
out.push(Entry {
rel,
abs: e.path().to_path_buf(),
size,
});
true
});
let mut out = vec![];
for e in walk.build() {
let e = e?;
let Some(t) = e.file_type() else { continue };
if t.is_dir() {
continue;
}
let rel = e
.path()
.strip_prefix(root)
.unwrap_or(e.path())
.to_path_buf();
if rel.as_os_str().is_empty() {
continue;
}
Ok(())
})();
let _ = std::fs::remove_file(&defaults);
result?;
let size = if t.is_file() {
e.metadata().map(|m| m.len()).unwrap_or(0)
} else {
0
};
out.push(Entry {
rel,
abs: e.path().to_path_buf(),
size,
});
}
Ok(out)
}

Expand Down Expand Up @@ -492,6 +514,58 @@ mod tests {
assert!(names(&d.0, false).contains(&"node_modules/a/index.js".to_owned()));
}

#[test]
fn defaults_rank_below_the_folders_ignore_files() {
// A `.gitignore` can keep node_modules too, and the default reaches
// nested ones.
let d = folder(&[
(".gitignore", "!node_modules/\n"),
("node_modules/a.js", "x"),
("web/node_modules/b.js", "x"),
]);
let got = names(&d.0, false);
assert!(got.contains(&"node_modules/a.js".to_owned()), "{got:?}");
assert!(got.contains(&"web/node_modules/b.js".to_owned()), "{got:?}");
let d = folder(&[
("web/node_modules/b.js", "x"),
("web/index.js", "x"),
("node_modules", "a file, not a folder"),
]);
assert_eq!(names(&d.0, false), ["node_modules", "web/index.js"]);
// `.pyoignore` wins over `.gitignore`.
let d = folder(&[
(".gitignore", "!node_modules/\n"),
(".pyoignore", "node_modules/\n"),
("node_modules/a.js", "x"),
]);
assert!(!names(&d.0, false).contains(&"node_modules/a.js".to_owned()));
}

#[test]
fn lists_from_many_threads_at_once() {
let d = folder(&[
(".pyoignore", "secret.txt\n"),
("index.js", "x"),
("secret.txt", "x"),
("node_modules/a/index.js", "x"),
]);
let root = d.0.clone();
std::thread::scope(|s| {
let runs: Vec<_> = (0..8)
.map(|_| {
s.spawn(|| {
for _ in 0..50 {
assert_eq!(names(&root, false), [".pyoignore", "index.js"]);
}
})
})
.collect();
for r in runs {
r.join().unwrap();
}
});
}

#[test]
fn packs_the_same_files_the_same_way() {
let d = folder(&[("a.txt", "hello"), ("b/c.txt", "world")]);
Expand Down
2 changes: 1 addition & 1 deletion crates/pyo-envd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ publish.workspace = true

[dependencies]
libc = "0.2.191"
pyo-proto = { version = "0.5.0", path = "../pyo-proto" }
pyo-proto = { version = "0.5.1", path = "../pyo-proto" }
serde_json.workspace = true
2 changes: 1 addition & 1 deletion crates/pyo-flows/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish.workspace = true
[dependencies]
anyhow = "1.0.104"
libc = "0.2.191"
pyo-proto = { version = "0.5.0", path = "../pyo-proto" }
pyo-proto = { version = "0.5.1", path = "../pyo-proto" }
reqwest = { version = "0.13.5", default-features = false, features = ["json", "rustls"] }
serde_json = "1.0.154"
tokio = { version = "1.54.1", features = ["rt-multi-thread", "macros", "time", "sync"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/pyo-sandbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ http-body-util = "0.1.5"
hyper = { version = "1.12.0", features = ["client", "http1", "server"] }
hyper-util = { version = "0.1.21", features = ["tokio"] }
libc = "0.2.191"
pyo-proto = { version = "0.5.0", path = "../pyo-proto", features = ["sandbox-token"] }
pyo-proto = { version = "0.5.1", path = "../pyo-proto", features = ["sandbox-token"] }
serde.workspace = true
serde_json.workspace = true
tokio.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/pyo-static/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ axum = { version = "0.8.9", default-features = false, features = ["http1", "toki
futures.workspace = true
base64 = "0.23.1"
hex = "0.4.3"
pyo-proto = { version = "0.5.0", path = "../pyo-proto", features = ["command-signing"] }
pyo-proto = { version = "0.5.1", path = "../pyo-proto", features = ["command-signing"] }
reqwest = { version = "0.13.5", default-features = false, features = ["json", "rustls", "stream"] }
serde.workspace = true
serde_json.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion deploy/release-notices.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.5.0",
"version": "0.5.1",
"minFrom": null,
"manualOnly": false,
"beforeYouUpdate": []
Expand Down
Loading