nautilus_core/
paths.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Posei Systems Pty Ltd. All rights reserved.
3//  https://poseitrader.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Utility functions for resolving project and workspace directory paths.
17
18use std::path::PathBuf;
19
20/// Returns the workspace root directory path.
21///
22/// # Panics
23///
24/// Panics if the `CARGO_MANIFEST_DIR` environment variable is not set or its parent directory cannot be determined.
25#[must_use]
26pub fn get_workspace_root_path() -> PathBuf {
27    PathBuf::from(env!("CARGO_MANIFEST_DIR"))
28        .parent()
29        .expect("Failed to get project root")
30        .to_path_buf()
31}
32
33/// Returns the project root directory path.
34///
35/// # Panics
36///
37/// Panics if the workspace root path cannot be determined or its parent directory is missing.
38#[must_use]
39pub fn get_project_root_path() -> PathBuf {
40    get_workspace_root_path()
41        .parent()
42        .expect("Failed to get workspace root")
43        .to_path_buf()
44}
45
46/// Returns the tests root directory path.
47#[must_use]
48pub fn get_tests_root_path() -> PathBuf {
49    get_project_root_path().join("tests")
50}
51
52/// Returns the test data directory path.
53#[must_use]
54pub fn get_test_data_path() -> PathBuf {
55    if let Ok(test_data_root_path) = std::env::var("TEST_DATA_ROOT_PATH") {
56        get_project_root_path()
57            .join(test_data_root_path)
58            .join("test_data")
59    } else {
60        get_project_root_path().join("tests").join("test_data")
61    }
62}