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

chore(infra): move get_absolute_path function to infra_utils #2074

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ArniStarkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link

Artifacts upload triggered. View details here

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.

Project coverage is 77.46%. Comparing base (e3165c4) to head (eb4e92e).
Report is 510 commits behind head on main.

Files with missing lines Patch % Lines
crates/infra_utils/src/path.rs 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2074       +/-   ##
===========================================
+ Coverage   40.10%   77.46%   +37.35%     
===========================================
  Files          26      386      +360     
  Lines        1895    40473    +38578     
  Branches     1895    40473    +38578     
===========================================
+ Hits          760    31351    +30591     
- Misses       1100     6815     +5715     
- Partials       35     2307     +2272     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@ArniStarkware ArniStarkware force-pushed the arni/infra_utils/move_get_absolute_path branch from 63ca81d to 5e61b82 Compare November 17, 2024 06:05
Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

Copy link

Benchmark movements:
tree_computation_flow performance improved 😺
tree_computation_flow time: [34.473 ms 34.514 ms 34.558 ms]
change: [-4.7403% -3.1596% -1.7857%] (p = 0.00 < 0.05)
Performance has improved.
Found 2 outliers among 100 measurements (2.00%)
1 (1.00%) high mild
1 (1.00%) high severe

Copy link
Contributor

@Itay-Tsabary-Starkware Itay-Tsabary-Starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 5 files at r1, all commit messages.
Reviewable status: 3 of 5 files reviewed, 1 unresolved discussion (waiting on @ArniStarkware)


crates/infra_utils/src/path.rs line 6 at r1 (raw file):

// 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 {

I think the name and doc should reflect the relative path is from the project directory. Perhaps even state explicitly what is the returned directory.
Also consider (optional) to split into two functions: obtaining the current path, and joining with the relative path.

Code quote:

// 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 {

crates/infra_utils/src/path.rs line 12 at r1 (raw file):

        .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"));

For a different pr:

ChatGPT suggested using env::current_exe(), are you familiar with it?

use std::env;
use std::path::PathBuf;

fn get_project_path() -> PathBuf {
    if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") {
        return PathBuf::from(manifest_dir);
    }

    let exe_path = env::current_exe().expect("Failed to get current executable path");
    let exe_dir = exe_path.parent().expect("Failed to get executable directory");

    if exe_dir.ends_with("debug") || exe_dir.ends_with("release") {
        return exe_dir.parent().unwrap().parent().unwrap().to_path_buf();
    }

    env::current_dir().expect("Failed to get current working directory")
}

fn main() {
    let project_path = get_project_path();
    println!("Project path: {}", project_path.display());
}

Code quote:

    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"));

@ArniStarkware ArniStarkware force-pushed the arni/create_infra_utils_crate branch 2 times, most recently from 33e89ec to 278821c Compare November 19, 2024 12:57
@ArniStarkware ArniStarkware force-pushed the arni/infra_utils/move_get_absolute_path branch from 17634f4 to acaf6a4 Compare November 19, 2024 12:57
Copy link

Artifacts upload triggered. View details here

@ArniStarkware ArniStarkware force-pushed the arni/create_infra_utils_crate branch 2 times, most recently from 18235cb to 0961746 Compare November 19, 2024 15:11
@ArniStarkware ArniStarkware force-pushed the arni/infra_utils/move_get_absolute_path branch from acaf6a4 to b179f10 Compare November 19, 2024 15:11
Copy link

Artifacts upload triggered. View details here

Copy link

Benchmark movements:
tree_computation_flow performance improved 😺
tree_computation_flow time: [34.266 ms 34.298 ms 34.335 ms]
change: [-4.0309% -2.4181% -1.0381%] (p = 0.00 < 0.05)
Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
4 (4.00%) high mild
2 (2.00%) high severe

@ArniStarkware ArniStarkware changed the base branch from arni/create_infra_utils_crate to graphite-base/2074 November 20, 2024 05:19
@ArniStarkware ArniStarkware force-pushed the arni/infra_utils/move_get_absolute_path branch from b179f10 to e9d42d0 Compare November 20, 2024 05:19
@ArniStarkware ArniStarkware changed the base branch from graphite-base/2074 to main November 20, 2024 05:19
@ArniStarkware ArniStarkware force-pushed the arni/infra_utils/move_get_absolute_path branch from e9d42d0 to eb4e92e Compare November 20, 2024 05:19
Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants