Skip to content

Commit b341cc2

Browse files
authored
feat: Support manifest path to project directory (#94)
Signed-off-by: Brandon Maier <[email protected]>
1 parent 41c6b49 commit b341cc2

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ enum Commands {
4646
#[arg(long)] // TODO: Read from environment variable?
4747
auth_file: Option<PathBuf>,
4848

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

src/pack.rs

+24-9
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,36 @@ pub struct PackOptions {
4444
pub create_executable: bool,
4545
}
4646

47-
/// Pack a pixi environment.
48-
pub async fn pack(options: PackOptions) -> Result<()> {
49-
let lockfile_path = options
50-
.manifest_path
51-
.parent()
52-
.ok_or(anyhow!("could not get parent directory"))?
53-
.join("pixi.lock");
47+
fn load_lockfile(manifest_path: &Path) -> Result<LockFile> {
48+
if !manifest_path.exists() {
49+
anyhow::bail!(
50+
"manifest path does not exist at {}",
51+
manifest_path.display()
52+
);
53+
}
54+
55+
let manifest_path = if !manifest_path.is_dir() {
56+
manifest_path
57+
.parent()
58+
.ok_or(anyhow!("could not get parent directory"))?
59+
} else {
60+
manifest_path
61+
};
5462

55-
let lockfile = LockFile::from_path(&lockfile_path).map_err(|e| {
63+
let lockfile_path = manifest_path.join("pixi.lock");
64+
65+
LockFile::from_path(&lockfile_path).map_err(|e| {
5666
anyhow!(
5767
"could not read lockfile at {}: {}",
5868
lockfile_path.display(),
5969
e
6070
)
61-
})?;
71+
})
72+
}
73+
74+
/// Pack a pixi environment.
75+
pub async fn pack(options: PackOptions) -> Result<()> {
76+
let lockfile = load_lockfile(&options.manifest_path)?;
6277

6378
let client = reqwest_client_from_auth_storage(options.auth_file)
6479
.map_err(|e| anyhow!("could not create reqwest client from auth storage: {e}"))?;

tests/integration_test.rs

+12
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,15 @@ async fn test_run_packed_executable(options: Options, required_fs_objects: Vec<&
557557
// Keep the temporary directory alive until the end of the test
558558
drop(temp_dir);
559559
}
560+
561+
#[rstest]
562+
#[tokio::test]
563+
async fn test_manifest_path_dir(#[with(PathBuf::from("examples/simple-python"))] options: Options) {
564+
let pack_options = options.pack_options;
565+
let unpack_options = options.unpack_options;
566+
let pack_file = unpack_options.pack_file.clone();
567+
568+
let pack_result = pixi_pack::pack(pack_options).await;
569+
assert!(pack_result.is_ok(), "{:?}", pack_result);
570+
assert!(pack_file.is_file());
571+
}

0 commit comments

Comments
 (0)