Skip to content

REFACTOR: move the banner from the rust source to the standard library#8406

Merged
fdncred merged 18 commits intonushell:mainfrom
amtoine:refactor/move-banner-from-rust-to-standard-library
May 10, 2023
Merged

REFACTOR: move the banner from the rust source to the standard library#8406
fdncred merged 18 commits intonushell:mainfrom
amtoine:refactor/move-banner-from-rust-to-standard-library

Conversation

@amtoine
Copy link
Copy Markdown
Member

@amtoine amtoine commented Mar 11, 2023

Related to:

Description

with the new $nu.startup-time from #8353 and as mentionned in #8311, we are now able to fully move the nushell banner from the rust source base to the standard library.

this PR

  • removes all the rust source code for the banner
  • rewrites a perfect clone of the banner to std.nu, called std banner
  • call std banner from default_config.nu

User-Facing Changes

see the demo: https://asciinema.org/a/566521

  • no config will show the banner (e.g. cargo run --release -- --no-config-file)
  • a custom config without the if $env.config.show_banner block and no call to std banner would never show the banner
  • a custom config with the block and config.show_banner = true will show the banner
  • a custom config with the block and config.show_banner = false will NOT show the banner

Tests + Formatting

a new test line has been added to tests.nu to check the length of the std banner output.

  • 🟢 toolkit fmt
  • 🟢 toolkit clippy
  • 🟢 toolkit test
  • 🟢 toolkit test stdlib

After Submitting

$nothing

@amtoine amtoine marked this pull request as ready for review March 11, 2023 15:52
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Mar 11, 2023

Nice work @amtoine! However, I don't want to remove this until we start distributing the stdlib as default (just like you said above). So, with that in mind, I'm marking this a draft to prevent accidental merging.

@fdncred fdncred marked this pull request as draft March 11, 2023 15:58
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Mar 11, 2023

Nice work @amtoine! However, I don't want to remove this until we start distributing the stdlib as default (just like you said above). So, with that in mind, I'm marking this a draft to prevent accidental merging.

oh yeah you're right!

let's avoid an accidental merge 😌

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 11, 2023

Codecov Report

Merging #8406 (b611da8) into main (a92949b) will increase coverage by 0.07%.
The diff coverage is 16.66%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8406      +/-   ##
==========================================
+ Coverage   68.84%   68.92%   +0.07%     
==========================================
  Files         641      641              
  Lines      102321   102231      -90     
==========================================
+ Hits        70444    70463      +19     
+ Misses      31877    31768     -109     
Impacted Files Coverage Δ
crates/nu-cli/src/repl.rs 3.35% <0.00%> (+0.42%) ⬆️
src/run.rs 73.91% <0.00%> (-0.33%) ⬇️
crates/nu-std/src/lib.rs 80.58% <100.00%> (+0.19%) ⬆️
src/test_bins.rs 96.96% <100.00%> (+0.02%) ⬆️

... and 3 files with indirect coverage changes

@sholderbach sholderbach added the A:std-library Defining and improving the standard library written in Nu label Mar 11, 2023
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Mar 12, 2023

@kubouch
as in #8415, maybe this PR should be marked with the wait-until-after-nushell-release tag as well?

Learn how to remove this at: (ansi green)https://nushell.sh/book/configuration.html#remove-welcome-message(ansi reset)

It's been this long since (ansi green)Nushell(ansi reset)'s first commit:
((date now) - ('2019-05-10 09:59:12-0700' | into datetime))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can use the datetime value here instead of using into datetime

(date now) - 2019-05-10T09:59:12-07:00)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ooh yes indeed!

let me switch to this simpler solution 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

should be simpler in 838ca95, thanks 😌

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Apr 28, 2023

the three commits above should

  • solve the merge conflicts
  • move the implementation of banner and its test to the new nu-std crate
  • make the CI pass again

@amtoine amtoine self-assigned this Apr 28, 2023
amtoine added 2 commits April 28, 2023 10:24
This is to avoid printing something on the same line as the time.

I have a hook that triggers automatically when entering a directory
and running `cargo run --release` gave me
```
...

Startup Time: -1nstoolkit module detected...
activating toolkit module with `use toolkit.nu`
```
before this commit.

now i get
```
...

Startup Time: -1ns
toolkit module detected...
activating toolkit module with `use toolkit.nu`
```
@amtoine amtoine marked this pull request as ready for review April 28, 2023 08:28
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Apr 28, 2023

💡 one thing we could do here is to remove the show_banner option from the config and just call std banner without the if block in default_config.nu.

to disable the banner, a user just have to either

  • remove the std banner call from their local copy of default_config.nu file
  • create a custom config file without std banner

what do you think? 😋

amtoine added 3 commits April 28, 2023 10:50
This should also fix the CI and the `test_config_path::test_alternate_config_path`
test, see https://github.com/nushell/nushell/actions/runs/4828641085/jobs/8602701650?pr=8406
@fdncred found that
1. setting the PWD in the engine state solved the tests
2. not setting it in the stack did not change anything

let's see what the CI thinks of this 😋
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Apr 28, 2023

what do you think? 😋

I'd prefer to implement with a clone with what we have today, 100% same functionality, just working from std lib vs rust code. Then, at a later time, if we want to make the changes you're suggestion, we could do that. I think it's better to just move one step at a time first.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Apr 28, 2023

default_config.nu is not sourced by default?

It gets complicated, so complicated that i cannot remember when defaults are sourced and not. you'll have to do some research i guess.

@amtoine amtoine marked this pull request as draft April 28, 2023 17:12
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Apr 28, 2023

okey, i think i have a fix 😏

how it behaves now

>_ cargo run -- --no-config-file
    Finished dev [unoptimized + debuginfo] target(s) in 0.26s
     Running `target/debug/nu --no-config-file`
     __  ,
 .--()°'.' Welcome to Nushell,
'|, . ,'   based on the nu language,
 !_-(_\    where all data is structured!

Please join our Discord community at https://discord.gg/NtAbbGn
Our GitHub repository is at https://github.com/nushell/nushell
Our Documentation is located at https://nushell.sh
Tweet us at @nu_shell
Learn how to remove this at: https://nushell.sh/book/configuration.html#remove-welcome-message

It's been this long since Nushell's first commit:
3yr 11month 3wk 3day 1hr 40min 36sec 411ms 210µs 441ns

Startup Time: 562ms 481µs 659ns
>                                                                            04/28/2023 08:39:49 PM
>_ cargo run -- --config config.show_banner.nu
    Finished dev [unoptimized + debuginfo] target(s) in 0.26s
     Running `target/debug/nu --config config.show_banner.nu`
     __  ,
 .--()°'.' Welcome to Nushell,
'|, . ,'   based on the nu language,
 !_-(_\    where all data is structured!

Please join our Discord community at https://discord.gg/NtAbbGn
Our GitHub repository is at https://github.com/nushell/nushell
Our Documentation is located at https://nushell.sh
Tweet us at @nu_shell
Learn how to remove this at: https://nushell.sh/book/configuration.html#remove-welcome-message

It's been this long since Nushell's first commit:
3yr 11month 3wk 3day 1hr 40min 42sec 521ms 991µs 924ns

Startup Time: 727ms 981µs 929ns
>                                                                            04/28/2023 08:39:54 PM
>_ cargo run -- --config config.no-show_banner.nu
    Finished dev [unoptimized + debuginfo] target(s) in 0.26s
     Running `target/debug/nu --config config.no-show_banner.nu`
>                                                                            04/28/2023 08:40:01 PM

where

# config.show_banner.nu
let-env config = {
    show_banner: true
}

and

# config.no-show_banner.nu
let-env config = {
    show_banner: false
}

the actual two changes

  • dba796b is here to have a $nu.startup-time not equal to -1 ns when the banner shows up
  • 2b356d6 moves the banner call to the REPL evaluation, before the REPL loop

@amtoine amtoine marked this pull request as ready for review April 29, 2023 07:32
@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Apr 29, 2023

it might be not perfect but that works and the banner has been moved to std 🥳

Copy link
Copy Markdown
Contributor

@fdncred fdncred left a comment

Choose a reason for hiding this comment

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

I've tested this and it looks identical to the original. Good work!

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented Apr 29, 2023

I've tested this and it looks identical to the original. Good work!

glad you like it 🥳

do we want the point of view of another member of the team?

Copy link
Copy Markdown
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

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

You can now not run the default config with --no-std-lib:

As this call is in the rust code and not in the config this should be fixed on the Rust side in my view.

~/nushell> cargo run -- --no-std-lib
    Finished dev [unoptimized + debuginfo] target(s) in 0.16s
     Running `target/debug/nu --no-std-lib`
Error: nu::parser::module_not_found

  × Module not found.
   ╭─[show_banner:1:1]
 1 │ use std banner; banner
   ·     ─┬─
   ·      ╰── module not found
   ╰────
  help: module files and their paths must be available before your script is run as parsing occurs before anything
        is evaluated

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented May 4, 2023

You can now not run the default config with --no-std-lib:

As this call is in the rust code and not in the config this should be fixed on the Rust side in my view.

very good catch! 😮

what should be the behaviour of the banner with --no-std-lib then?
no banner? 🤔

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 4, 2023

At a minimum, I think it's helpful to always have startup time. It's a benchmark metric that need to keep track of like this. It's an easy way to measure some startup performance areas.

  1. nu
  2. nu --no-std-lib
  3. nu -n
  4. nu -n --no-std-lib

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented May 6, 2023

@sholderbach
i think i've found a patch for this, see b99654c 😋

Note
i wanted to add a test for this but could not find a way to simulate running nu --no-std-lib and check whether it fails or not 🤔

@fdncred

At a minimum, I think it's helpful to always have startup time. It's a benchmark metric that need to keep track of like this. It's an easy way to measure some startup performance areas.

we always can run the following to run performance benchmarks!

nu -c "print $nu.startup-time"
nu --no-std-lib -c "print $nu.startup-time"
nu -n -c "print $nu.startup-time"
nu -n --no-std-lib -c "print $nu.startup-time"

or run $nu.startup-time from the history when entering the shell.

i do not think we should require this from the banner 🤔

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 6, 2023

That's fine. I forgot we were storing it in $nu.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 8, 2023

I have another change I'd like to make. I may try to add to this PR if that's ok?

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented May 8, 2023

I have another change I'd like to make.

sure go ahead 😌

I may try to add to this PR if that's ok?

i've ticked the Allow edits and access to secrets by maintainers box above, tell me if that's ok to edit this branch 😋

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 8, 2023

Updated with JT's better date math script + some tweaks.
image

But note, there's a bug somewhere I think because nanoseconds is always zero, which is why it's left out. I think it's something internal to how we're handling dates versus the scripting.

@amtoine Feel free to reorganize/rename or whatever. I just wanted to get the better math in there until Bob can fix our internal rust date math.

@amtoine
Copy link
Copy Markdown
Member Author

amtoine commented May 8, 2023

i'll make this a DRAFT again for now.

just a question, where does this script come from? 😋

@amtoine amtoine marked this pull request as draft May 8, 2023 17:03
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 8, 2023

just a question, where does this script come from? 😋

I said above. JT wrote most of it and I tweaked it.

I'm ready to land it once you give it a look.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 8, 2023

I'm seeing a little bit of cleanup work that needs to be done. There's a comment that I need to remove and we should think about maybe making a function in dt.nu that formats the duration string so we don't end up with this (which i just happened to get in Windows)

3yr 11month 29day 0hr 7min 48sec 641ms 830.8µs
  1. we shouldn't have 0 items
  2. we shouldn't have decimal items (which means nanos are working on windows)

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 8, 2023

ok, cleaned it up a bit and added a pretty-print custom command.
image

@fdncred fdncred marked this pull request as ready for review May 10, 2023 12:02
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 10, 2023

Let's give this a try while we still have a few days before the release.

@fdncred fdncred merged commit 43a3983 into nushell:main May 10, 2023
@amtoine amtoine deleted the refactor/move-banner-from-rust-to-standard-library branch May 10, 2023 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:std-library Defining and improving the standard library written in Nu

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants