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: Support manifest path to project directory #94

Merged
merged 2 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
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ enum Commands {
#[arg(long)] // TODO: Read from environment variable?
auth_file: Option<PathBuf>,

/// The path to 'pixi.toml' or 'pyproject.toml'
/// The path to `pixi.toml`, `pyproject.toml`, or the project directory
#[arg(default_value = cwd().join("pixi.toml").into_os_string())]
manifest_path: PathBuf,

Expand Down
33 changes: 24 additions & 9 deletions src/pack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,36 @@ pub struct PackOptions {
pub create_executable: bool,
}

/// Pack a pixi environment.
pub async fn pack(options: PackOptions) -> Result<()> {
let lockfile_path = options
.manifest_path
.parent()
.ok_or(anyhow!("could not get parent directory"))?
.join("pixi.lock");
fn load_lockfile(manifest_path: &Path) -> Result<LockFile> {
if !manifest_path.exists() {
anyhow::bail!(
"manifest path does not exist at {}",
manifest_path.display()
);
}

let manifest_path = if !manifest_path.is_dir() {
manifest_path
.parent()
.ok_or(anyhow!("could not get parent directory"))?
} else {
manifest_path
};

let lockfile = LockFile::from_path(&lockfile_path).map_err(|e| {
let lockfile_path = manifest_path.join("pixi.lock");

LockFile::from_path(&lockfile_path).map_err(|e| {
anyhow!(
"could not read lockfile at {}: {}",
lockfile_path.display(),
e
)
})?;
})
}

/// Pack a pixi environment.
pub async fn pack(options: PackOptions) -> Result<()> {
let lockfile = load_lockfile(&options.manifest_path)?;

let client = reqwest_client_from_auth_storage(options.auth_file)
.map_err(|e| anyhow!("could not create reqwest client from auth storage: {e}"))?;
Expand Down
12 changes: 12 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,15 @@ async fn test_run_packed_executable(options: Options, required_fs_objects: Vec<&
// Keep the temporary directory alive until the end of the test
drop(temp_dir);
}

#[rstest]
#[tokio::test]
async fn test_manifest_path_dir(#[with(PathBuf::from("examples/simple-python"))] options: Options) {
let pack_options = options.pack_options;
let unpack_options = options.unpack_options;
let pack_file = unpack_options.pack_file.clone();

let pack_result = pixi_pack::pack(pack_options).await;
assert!(pack_result.is_ok(), "{:?}", pack_result);
assert!(pack_file.is_file());
}
Loading