-
Notifications
You must be signed in to change notification settings - Fork 17
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
feat: Added the ability to use the TEACH-ME mode #221
base: main
Are you sure you want to change the base?
Conversation
@FroVolod Thank you for your contribution! Your pull request is now a part of the Race of Sloths! Current status: waiting for scoringWe're waiting for maintainer to score this pull request with What is the Race of SlothsRace of Sloths is a friendly competition where you can participate in challenges and compete with other open-source contributors within your normal workflow For contributors:
For maintainers:
Feel free to check our website for additional details! Bot commands
|
Screen.Recording.2024-11-10.at.23.06.23.mov |
tracing::info!( | ||
target: "near_teach_me", | ||
parent: &tracing::Span::none(), | ||
"Execution command:\n{}", |
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.
nit-pick, Executing command:
or Execution of command:
or Command execution:
instead of Execution command
.
Execution command
in the context of git
commands in another file is std::process::Command::new
but this detail is irrelevant to user, as user watches commands being executed, not the execution command used to execute git init
for example.
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.
there're many duplicate spots of this same nit-pick, i won't duplicate them to avoid visual clutter
/// TEACH-ME mode | ||
#[interactive_clap(long)] | ||
teach_me: bool, |
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.
i strongly suggest not duplicating the flag here, as
- it will be available in
cargo-near near --teach-me ...
form as well, if anyone prefers to run it ascargo-near
- it won't be present for
cargo --teach-me near ...
form - there's no reason to duplicate
interactive_clap::ResultFromCli::Err(optional_cli_opts, err) => { | ||
if let Some(_cli_opts) = optional_cli_opts { | ||
eprintln!( | ||
"Here is the console command if you ever need to re-run it again:\n{console_command_path} {}\n", | ||
shell_words::join(cli_cmd.to_cli_args()).yellow() |
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.
suggesting applying this diff here
diff --git a/cargo-near/src/main.rs b/cargo-near/src/main.rs
index 78bf58f..a78d0e5 100644
--- a/cargo-near/src/main.rs
+++ b/cargo-near/src/main.rs
@@ -149,6 +149,6 @@ fn main() -> CliResult {
interactive_clap::ResultFromCli::Err(optional_cli_opts, err) => {
- if let Some(_cli_opts) = optional_cli_opts {
+ if let Some(cli_opts) = optional_cli_opts {
eprintln!(
"Here is the console command if you ever need to re-run it again:\n{console_command_path} {}\n",
- shell_words::join(cli_cmd.to_cli_args()).yellow()
+ shell_words::join(cli_opts.to_cli_args()).yellow()
);
tracing::debug!("Setting cargo working dir to '{}'", path); | ||
tracing::info!( | ||
target: "near_teach_me", | ||
parent: &tracing::Span::none(), | ||
"Setting cargo working dir to '{}'", path | ||
); |
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.
this is somewhat redundant, as it's present in cwd
field of Invoking cargo
below
@@ -12,7 +13,9 @@ pub fn extract_abi_entries( | |||
let dylib_path: &Utf8Path = &artifact.path; | |||
let dylib_file_contents = fs::read(dylib_path)?; | |||
let object = symbolic_debuginfo::Object::parse(&dylib_file_contents)?; | |||
tracing::debug!( | |||
tracing::info!( |
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.
these look awesome
|
||
pub use near_cli_rs::CliResult; | ||
|
||
use cargo_near::Cmd; | ||
use cargo_near::{CliOpts, Cmd, Opts}; | ||
|
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.
REQUIRED: the constant in this line https://github.com/near/cargo-near/blob/main/cargo-near-build/src/types/near/docker_build/subprocess/env_vars/mod.rs#L3
has to be changed to "RUST_LOG=info"
, as for new images, which will be built from main
,
after this pr is merged the required export would look like "RUST_LOG=near_teach_me=info"
,
for the older images it's "RUST_LOG=cargo_near=info"
, so the common ground will be "RUST_LOG=info"
.
it's the only required change, as it the only one, which appears to negatively affect existing functionality (tho for yet-to-be docker images) .
diff --git a/cargo-near-build/src/types/near/docker_build/subprocess/env_vars/mod.rs b/cargo-near-build/src/types/near/docker_build/subprocess/env_vars/mod.rs
index 07de532..43f0f9b 100644
--- a/cargo-near-build/src/types/near/docker_build/subprocess/env_vars/mod.rs
+++ b/cargo-near-build/src/types/near/docker_build/subprocess/env_vars/mod.rs
@@ -2,3 +2,3 @@ pub mod nep330_build_info;
-const RUST_LOG_EXPORT: &str = "RUST_LOG=cargo_near=info";
+const RUST_LOG_EXPORT: &str = "RUST_LOG=info";
use nep330_build_info::BuildInfo;
target: "near_teach_me", | ||
parent: &tracing::Span::none(), | ||
"Execution command:\n{}", | ||
pretty_print::indent_payload(&format!("`{:?}`", cmd.cargo_command()).replace("\"", "")) |
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.
suggest reverting to {:#?}
, as the flags are otherwise mangled and hard to notice, which will be harder to figure out to someone, who has never seen the code
if env::var("RUST_LOG").is_ok() { | ||
let environment = if std::env::var(env_keys::nep330::BUILD_ENVIRONMENT).is_ok() { | ||
"container".cyan() | ||
} else { | ||
"host".purple() | ||
}; | ||
let my_formatter = | ||
cargo_near::types::my_formatter::MyFormatter::from_environment(environment); | ||
|
||
let env_filter = EnvFilter::from_default_env(); | ||
let format = format::debug_fn(move |writer, _field, value| write!(writer, "{:?}", value)); | ||
|
||
tracing_subscriber::registry() | ||
.with( | ||
tracing_subscriber::fmt::layer() | ||
.event_format(my_formatter) | ||
.fmt_fields(format) | ||
.with_filter(env_filter), | ||
) | ||
.init(); | ||
tracing_subscriber::registry() | ||
.with( | ||
tracing_subscriber::fmt::layer() | ||
.event_format(my_formatter) | ||
.fmt_fields(format) | ||
.with_filter(EnvFilter::from_default_env()), | ||
) | ||
.init(); | ||
} else if cli_cmd.teach_me || cli_near_args.teach_me { | ||
let env_filter = EnvFilter::from_default_env() | ||
.add_directive(tracing::Level::WARN.into()) | ||
.add_directive("near_teach_me=info".parse()?) | ||
.add_directive("near_cli_rs=info".parse()?) | ||
.add_directive("tracing_instrument=info".parse()?); | ||
tracing_subscriber::registry() | ||
.with( | ||
tracing_subscriber::fmt::layer() | ||
.without_time() | ||
.with_target(false), | ||
) | ||
.with(env_filter) | ||
.init(); | ||
} else { | ||
let indicatif_layer = IndicatifLayer::new() | ||
.with_progress_style( | ||
ProgressStyle::with_template( | ||
"{spinner:.blue}{span_child_prefix} {span_name} {msg} {span_fields}", | ||
) | ||
.unwrap() | ||
.tick_strings(&[ | ||
"▹▹▹▹▹", | ||
"▸▹▹▹▹", | ||
"▹▸▹▹▹", | ||
"▹▹▸▹▹", | ||
"▹▹▹▸▹", | ||
"▹▹▹▹▸", | ||
"▪▪▪▪▪", | ||
]), | ||
) | ||
.with_span_child_prefix_symbol("↳ "); | ||
let env_filter = EnvFilter::from_default_env() | ||
.add_directive(tracing::Level::WARN.into()) | ||
.add_directive("near_cli_rs=info".parse()?) | ||
.add_directive("tracing_instrument=info".parse()?); | ||
tracing_subscriber::registry() | ||
.with( | ||
tracing_subscriber::fmt::layer() | ||
.without_time() | ||
.with_writer(indicatif_layer.get_stderr_writer()), | ||
) | ||
.with(indicatif_layer) | ||
.with(env_filter) | ||
.init(); | ||
}; |
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.
i strongly suggest
- making these blocks a function with following signature
pub fn setup_tracing(rust_log_env_is_set: bool, teach_me_flag_is_set: bool) {
....
}
- putting it and related
tracing-*
imports intocargo-near/src/lib.rs
- then this function https://github.com/near/cargo-near/blob/main/integration-tests/src/lib.rs#L11-L32 can be replaced with
pub fn setup_tracing() {
cargo_near::setup_tracing(true, false);
}
skip_all | ||
)] | ||
fn execute_git_commands(project_dir: &std::path::Path) -> near_cli_rs::CliResult { | ||
tracing::Span::current().pb_set_message("`git` commands ..."); |
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.
this one doesn't get displayed on --teach-me
, but we probably can figure this out in subsequent prs
tracing::info!("{}={}", key, value); | ||
env_map.insert( | ||
key, | ||
value.replace("'", "").replace("\"", "").replace(",", " "), |
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.
rust's debug representation "{:#?}"
should be probably used as is here (and wrap in '...'
single quotes on line 43 removed too)
@race-of-sloths score 13 |
@FroVolod Thank you for your contribution! Your pull request is now a part of the Race of Sloths! Current status: waiting for merge
Your contribution is much appreciated with a final score of 13! @dj8yfo received 25 Sloth Points for reviewing and scoring this pull request. What is the Race of SlothsRace of Sloths is a friendly competition where you can participate in challenges and compete with other open-source contributors within your normal workflow For contributors:
For maintainers:
Feel free to check our website for additional details! Bot commands
|
Screen.Recording.2024-10-04.at.08.16.08.mov