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

feat: Added the ability to use the TEACH-ME mode #221

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open

Conversation

FroVolod
Copy link
Collaborator

@FroVolod FroVolod commented Sep 13, 2024

./cargo-near --teach-me near new test

Screenshot 2024-10-03 at 19 51 28

./cargo-near --teach-me near build --manifest-path /Users/frovolod/Documents/NEAR/neardevhub-contract-1/Cargo.toml

Screenshot 2024-10-04 at 08 08 49

./cargo-near --teach-me near deploy --manifest-path /Users/frovolod/Documents/NEAR/neardevhub-contract-1/Cargo.toml
Screen.Recording.2024-10-04.at.08.16.08.mov

@FroVolod FroVolod marked this pull request as ready for review October 4, 2024 05:23
@FroVolod
Copy link
Collaborator Author

FroVolod commented Oct 4, 2024

@race-of-sloths

@race-of-sloths-bot
Copy link

@FroVolod Thank you for your contribution! Your pull request is now a part of the Race of Sloths!

Shows profile picture for the author of the PR

Current status: waiting for scoring

We're waiting for maintainer to score this pull request with @race-of-sloths score [0,1,2,3,5,8,13] command. Alternatively, autoscoring [1,2] will be applied for this pull request

What is the Race of Sloths

Race 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:

  • Tag @race-of-sloths inside your pull requests
  • Wait for the maintainer to review and score your pull request
  • Check out your position in the Leaderboard
  • Keep weekly and monthly streaks to reach higher positions
  • Boast your contributions with a dynamic picture of your Profile

For maintainers:

  • Score pull requests that participate in the Race of Sloths
  • Engage contributors with fair scoring and fast responses so they keep their streaks
  • Promote the Race to the point where the Race starts promoting you
  • Grow the community of your contributors

Feel free to check our website for additional details!

Bot commands
  • For contributors
    • Include a PR: @race-of-sloths include to enter the Race with your PR
  • For maintainers:
    • Invite contributor @race-of-sloths invite to invite the contributor to participate in a race or include it, if it's already a runner.
    • Assign points: @race-of-sloths score [1/2/3/5/8/13] to award points based on your assessment.
    • Reject this PR: @race-of-sloths exclude to send this PR back to the drawing board.
    • Exclude repo: @race-of-sloths pause to stop bot activity in this repo until @race-of-sloths unpause command is called

@FroVolod FroVolod marked this pull request as draft October 7, 2024 12:49
@FroVolod
Copy link
Collaborator Author

FroVolod commented Oct 7, 2024

Screenshot 2024-10-07 at 15 04 42

@FroVolod
Copy link
Collaborator Author

FroVolod commented Oct 11, 2024

Three alternative commands were tested:

cargo near --teach-me new test
./cargo-near  near --teach-me new test
./cargo-near --teach-me near new test

The execution of the program is the same:
Screenshot 2024-10-11 at 19 29 09

@FroVolod
Copy link
Collaborator Author

Screen.Recording.2024-11-10.at.23.06.23.mov

@FroVolod FroVolod marked this pull request as ready for review November 11, 2024 06:24
tracing::info!(
target: "near_teach_me",
parent: &tracing::Span::none(),
"Execution command:\n{}",
Copy link
Collaborator

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.

Copy link
Collaborator

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

Comment on lines +15 to +17
/// TEACH-ME mode
#[interactive_clap(long)]
teach_me: bool,
Copy link
Collaborator

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

  1. it will be available in cargo-near near --teach-me ... form as well, if anyone prefers to run it as cargo-near
  2. it won't be present for cargo --teach-me near ... form
  3. there's no reason to duplicate

Comment on lines +149 to 153
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()
Copy link
Collaborator

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

image

Comment on lines -124 to +129
tracing::debug!("Setting cargo working dir to '{}'", path);
tracing::info!(
target: "near_teach_me",
parent: &tracing::Span::none(),
"Setting cargo working dir to '{}'", path
);
Copy link
Collaborator

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!(
Copy link
Collaborator

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};

Copy link
Collaborator

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("\"", ""))
Copy link
Collaborator

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

Comment on lines +42 to +106
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();
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

i strongly suggest

  1. making these blocks a function with following signature
pub fn setup_tracing(rust_log_env_is_set: bool, teach_me_flag_is_set: bool) {
	....
}
  1. putting it and related tracing-* imports into cargo-near/src/lib.rs
  2. 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 ...");
Copy link
Collaborator

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(",", " "),
Copy link
Collaborator

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)

@dj8yfo
Copy link
Collaborator

dj8yfo commented Nov 12, 2024

@race-of-sloths score 13

@race-of-sloths
Copy link

@FroVolod Thank you for your contribution! Your pull request is now a part of the Race of Sloths!

Shows inviting banner with latest news.

Shows profile picture for the author of the PR

Current status: waiting for merge
Reviewer Score
@dj8yfo 13

Your contribution is much appreciated with a final score of 13!
You have received 130 Sloth points for this contribution

@dj8yfo received 25 Sloth Points for reviewing and scoring this pull request.

What is the Race of Sloths

Race 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:

  • Tag @race-of-sloths inside your pull requests
  • Wait for the maintainer to review and score your pull request
  • Check out your position in the Leaderboard
  • Keep weekly and monthly streaks to reach higher positions
  • Boast your contributions with a dynamic picture of your Profile

For maintainers:

  • Score pull requests that participate in the Race of Sloths and receive a reward
  • Engage contributors with fair scoring and fast responses so they keep their streaks
  • Promote the Race to the point where the Race starts promoting you
  • Grow the community of your contributors

Feel free to check our website for additional details!

Bot commands
  • For contributors
    • Include a PR: @race-of-sloths include to enter the Race with your PR
  • For maintainers:
    • Invite contributor @race-of-sloths invite to invite the contributor to participate in a race or include it, if it's already a runner.
    • Assign points: @race-of-sloths score [1/2/3/5/8/13] to award points based on your assessment.
    • Reject this PR: @race-of-sloths exclude to send this PR back to the drawing board.
    • Exclude repo: @race-of-sloths pause to stop bot activity in this repo until @race-of-sloths unpause command is called

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.

4 participants