Skip to content

Commit

Permalink
chore(infra): move get_absolute_path function to infra_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Nov 17, 2024
1 parent 6875169 commit 5e61b82
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

15 changes: 14 additions & 1 deletion crates/infra_utils/src/path.rs
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
// TODO(Arni): Move the function get_absolute_path to this file.
use std::env;
use std::path::PathBuf;

// TODO(Tsabary/ Arni): consolidate with other get_absolute_path functions.
/// Returns the absolute path from the project root.
pub fn get_absolute_path(relative_path: &str) -> PathBuf {
let base_dir = env::var("CARGO_MANIFEST_DIR")
// Attempt to get the `CARGO_MANIFEST_DIR` environment variable and convert it to `PathBuf`.
// Ascend two directories ("../..") to get to the project root.
.map(|dir| PathBuf::from(dir).join("../.."))
// If `CARGO_MANIFEST_DIR` isn't set, fall back to the current working directory
.unwrap_or_else(|_| env::current_dir().expect("Failed to get current directory"));
base_dir.join(relative_path)
}
1 change: 1 addition & 0 deletions crates/starknet_sequencer_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ anyhow.workspace = true
clap.workspace = true
const_format.workspace = true
futures.workspace = true
infra_utils.workspace = true
papyrus_config.workspace = true
papyrus_proc_macros = { workspace = true, optional = true }
rstest.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet_sequencer_node/src/config/node_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::sync::LazyLock;
use std::vec::Vec;

use clap::Command;
use infra_utils::path::get_absolute_path;
use papyrus_config::dumping::{
append_sub_config_name,
ser_pointer_target_required_param,
Expand All @@ -26,7 +27,6 @@ use starknet_sierra_compile::config::SierraToCasmCompilationConfig;
use validator::Validate;

use crate::config::component_config::ComponentConfig;
use crate::utils::get_absolute_path;
use crate::version::VERSION_FULL;

// The path of the default configuration file, provided as part of the crate.
Expand Down
15 changes: 0 additions & 15 deletions crates/starknet_sequencer_node/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use std::env;
use std::path::PathBuf;

use crate::clients::{create_node_clients, SequencerNodeClients};
use crate::communication::create_node_channels;
use crate::components::create_node_components;
Expand All @@ -17,15 +14,3 @@ pub fn create_node_modules(

(clients, servers)
}

// TODO(Tsabary): consolidate with other get_absolute_path functions.
/// Returns the absolute path from the project root.
pub fn get_absolute_path(relative_path: &str) -> PathBuf {
let base_dir = env::var("CARGO_MANIFEST_DIR")
// Attempt to get the `CARGO_MANIFEST_DIR` environment variable and convert it to `PathBuf`.
// Ascend two directories ("../..") to get to the project root.
.map(|dir| PathBuf::from(dir).join("../.."))
// If `CARGO_MANIFEST_DIR` isn't set, fall back to the current working directory
.unwrap_or_else(|_| env::current_dir().expect("Failed to get current directory"));
base_dir.join(relative_path)
}

0 comments on commit 5e61b82

Please sign in to comment.