-
Notifications
You must be signed in to change notification settings - Fork 22
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
base: main
Are you sure you want to change the base?
Conversation
Artifacts upload triggered. View details here |
Codecov ReportAttention: Patch coverage is
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. 🚨 Try these New Features:
|
89fda5f
to
6875169
Compare
63ca81d
to
5e61b82
Compare
Artifacts upload triggered. View details here |
6875169
to
3778061
Compare
5e61b82
to
17634f4
Compare
Artifacts upload triggered. View details here |
Benchmark movements: |
There was a problem hiding this 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"));
33e89ec
to
278821c
Compare
17634f4
to
acaf6a4
Compare
Artifacts upload triggered. View details here |
18235cb
to
0961746
Compare
acaf6a4
to
b179f10
Compare
Artifacts upload triggered. View details here |
Benchmark movements: |
0961746
to
b05cfd6
Compare
b179f10
to
e9d42d0
Compare
e9d42d0
to
eb4e92e
Compare
Artifacts upload triggered. View details here |
Artifacts upload triggered. View details here |
Artifacts upload triggered. View details here |
Artifacts upload triggered. View details here |
Artifacts upload triggered. View details here |
No description provided.