Skip to content

Commit e5490df

Browse files
committed
Fix target directory resolution
This is a hack which doesn't work for doc-tests but the previous approach didn't work for workspaces. Given that the expectation is that these files will most likely be used in integration tests I'm going with this approach. See: rust-lang/cargo#2841
1 parent 14910bb commit e5490df

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dicom-test-files"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
authors = ["Rob Young <[email protected]>"]
55
edition = "2018"
66
description = "A collection of DICOM files for testing DICOM parsers."

rust/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! To avoid users having to download all the files they are downloaded as they
44
//! are needed and cached in the `/target` directory.
55
//!
6-
//! ```rust
6+
//! ```no_run
77
//! use dicom_test_files;
88
//!
99
//! dicom_test_files::path("pydicom/liver.dcm").unwrap();
@@ -53,7 +53,13 @@ pub fn path(name: &str) -> Result<PathBuf, Error> {
5353
}
5454

5555
pub(crate) fn get_data_path() -> PathBuf {
56-
PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("target").join("dicom_test_files")
56+
let mut target_dir = PathBuf::from(env::current_exe().expect("exe path").parent().expect("exe parent"));
57+
while target_dir.file_name() != Some(std::ffi::OsStr::new("target")) {
58+
if !target_dir.pop() {
59+
panic!("Cannot find target directory");
60+
}
61+
}
62+
target_dir.join("dicom_test_files")
5763
}
5864

5965
const GITHUB_BASE_URL: &str = "https://raw.githubusercontent.com/robyoung/dicom-test-files/master/data/";

0 commit comments

Comments
 (0)