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

stdlib: refactor into a multi-module library #8815

Merged

Conversation

amtoine
Copy link
Member

@amtoine amtoine commented Apr 8, 2023

Description

this PR

  • moves the tests to their own tests/ directory
  • splits the old std.nu module into multiple submodules and a main mod.nu one in lib/
  • fixes the mentions to the old structure
  • i moved the log example to crates/nu-std/examples.nu, to be used as use crates/nu-std/examples.nu; examples log (cc/ @presidento)

🗝️ old structure

crates/nu-std/
├── Cargo.toml
├── LICENSE
├── README.md
├── src
│   └── lib.rs
├── std.nu
├── test_asserts.nu
├── test_dirs.nu
├── test_logger.nu
├── tests.nu
├── test_std.nu
└── test_xml.nu

2 directories, 11 files

🔑 new structure

crates/nu-std/
├── Cargo.toml
├── examples.nu
├── lib
│   ├── assert.nu
│   ├── dirs.nu
│   ├── help.nu
│   ├── log.nu
│   ├── mod.nu
│   └── xml.nu
├── LICENSE
├── README.md
├── src
│   └── lib.rs
└── tests
    ├── run.nu
    ├── test_asserts.nu
    ├── test_dirs.nu
    ├── test_logger.nu
    ├── test_std.nu
    └── test_xml.nu

4 directories, 17 files

⚠️ main limitations

  • from crates/nu-std/lib/mod.nu, modules NEED to be exported with export use <mod> *

Note

  • the * is important
  • only use the name of the module, not the path or the filename (it's imported automatically since c3df973)
  • with c3df973, the developer needs to modify the list of submodules in the crates/nu-std/src/lib.rs file => i think this is not so much of a limitation because, as the library is to be embedded in the nu binary, we need to abstract away from the actual files in nu-std
  • commands need to be defined as "module command" in their modules such that we do not end up with std module module command when using the library
  • to export environment, the following structure is to be used from inside mod.nu
export-env {
    use crates/nu-std/lib/<mod>.nu *
}
  • view source std only shows the main mod.nu module
  • we cannot import a whole submodule, e.g. use std help won't import all the help commands but rather only the help command

User-Facing Changes

$nothing

Tests + Formatting

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

After Submitting

$nothing

Commands used:
```bash
mkdir crates/nu-std/tests
mv crates/nu-std/test_*.nu crates/nu-std/tests/
mv crates/nu-std/tests.nu crates/nu-std/tests/run.nu
```
Commands used:
```bash
mkdir crates/nu-std/lib/
mv crates/nu-std/std.nu crates/nu-std/lib/mod.nu
[assert dirs log xml help] | each {|mod|
    touch ({
        parent: "crates/nu-std/lib"
        stem: $mod
        extension: "nu"
    } | path join)
}
```
This mitigates the following errors when `use`ing the library:
```bash
Error: nu::parser::named_as_module

  × Can't export command named same as the module.
    ╭─[assert.nu:30:1]
 30 │ # ```
 31 │ export def assert [
    ·            ───┬──
    ·               ╰── can't export from module assert
 32 │     condition: bool, # Condition, which should be true
    ╰────
  help: Module assert can't export command named the same as the module. Either change the module name, or export `main`
        custom command.
```

and

```bash
Error: nu::parser::named_as_module

  × Can't export command named same as the module.
     ╭─[help.nu:676:1]
 676 │ #   > help --find char
 677 │ export def help [
     ·            ──┬─
     ·              ╰── can't export from module help
 678 │     ...item: string  # the name of the help item to get help on
     ╰────
  help: Module help can't export command named the same as the module. Either change the module name, or export `main`
        custom command.
```
@amtoine

This comment was marked as outdated.

This mitigates the following errors when using things like
```bash
cargo run
````

```
MODULE NOT FOUND
MODULE NOT FOUND
MODULE NOT FOUND
MODULE NOT FOUND
Error: nu::parser::module_not_found

  × Module not found.
   ╭─[std:3:1]
 3 │ export use assert.nu
 4 │ export use dirs.nu
   ·            ───┬───
   ·               ╰── module not found
 5 │ export use help.nu
   ╰────
  help: module files and their paths must be available before your script is run as parsing occurs before anything is
        evaluated`
```
We have a namespace issue here BUT it can be worked around by
looking for `help help ...` instead of `help ...` in the library.

This commit mitigates the following error when using `cargo run`

```bash
Error:
  × Unable to load the prelude of the standard library.
  help: this is a bug: please file an issue in the [issue tracker](https://github.com/nushell/nushell/issues/new/choose)

Error:
  × could not load `help commands` from `std`.

Error:
  × could not load `help aliases` from `std`.

Error:
  × could not load `help modules` from `std`.

Error:
  × could not load `help externs` from `std`.

Error:
  × could not load `help operators` from `std`.
```
This has the benefit of simplifying back the prelude search names.
All the command now have the exact same name as defined in their
respective submodules.
@amtoine

This comment was marked as outdated.

i forgot the `sd` in the hidden files as well 😮

Command used:
```bash
[.github/**/* **/*.rs **/*.nu]
| each {|target|
    sd 'crates/nu-std/tests.nu' 'crates/nu-std/tests/run.nu' $target
}
```
Otherwise,
```bash
use std 'dirs show'
dirs show
```
will give
```bash
Error: nu::shell::column_not_found

  × Cannot find column
    ╭─[crates/nu-std/lib/dirs.nu:59:1]
 59 │     mut out = []
 60 │     for $p in ($env.DIRS_LIST | enumerate) {
    ·                ──┬─ ────┬────
    ·                  │      ╰── cannot find column 'DIRS_LIST'
    ·                  ╰── value originates here
 61 │         $out = ($out | append [
    ╰────
```
This commit merges the fixes to the `nu-std` tests which now uses
the embedded `std` module instead of the old `std.nu` module file.
@amtoine amtoine marked this pull request as ready for review April 8, 2023 15:06
@amtoine amtoine mentioned this pull request Apr 8, 2023
7 tasks
@amtoine amtoine marked this pull request as draft April 8, 2023 15:30
@bobhy
Copy link
Contributor

bobhy commented Apr 8, 2023

Sorry, I don't know the best place to put this comment, but have you considered this alternative file structure? The structure you have is kind of familiar from the Rust project convention, but the one below might be easier for outside contributors to work with and maintain, since it puts all the files related to a custom command in one folder.

crates/nu-std/
├── Cargo.toml
├── lib
│   ├── assert
│   ├──── assert.nu
│   ├──── tests_assert.nu
│   ├── help
│   ├──── help.nu
│   ├──── tests_help.nu
. . .
├── LICENSE
├── README.md
├── src
│   └── lib.rs

There might be a concern that putting source and test files in the same folder might make it harder to build a pure production build distribution of the library, you'd have to strip out the test files from multiple folders. But we've already got the convention that test files are distinguished from (library) source files with the test_*, and you would still have the explicit use command to control what gets imported at runtime. And I do think this folder structure is easier to explain in CONTRIBUTING, fwiw.

@amtoine
Copy link
Member Author

amtoine commented Apr 8, 2023

@bobhy

i'll come back to you shortly 😌

i would like to have a modular base which works => this is not the case right as you can see with the ❌ in the CI 😱

once we have a modular library fully working we'll be able to change the exact locations of the files as we please, almost a detail at that point 😉
but a detail that matters 💯 to write things like a clear CONTRIBUTING.md 😏

count on me not to forget about you 👍

This commit should fix the CI tests of `std`.
@presidento
Copy link
Contributor

I strongly suggest moving the unit testing framework (aka run.nu) to stdlib. We already have asserts, but they are not so useful without the test runner. (Let it be distributed with the assert commands.)

@amtoine
Copy link
Member Author

amtoine commented Apr 8, 2023

Let it be distributed with the assert commands.

was tests.nu, now renamed tests/run.nu, meant to be a part of the library?
because it's been a script until now not a module and always only used to run the tests of the lib itself 🤔

i only moved it from tests.nu to tests.nu here, i think we can make it a true std module after this PR, not to accumulate too many changes 😌

@presidento
Copy link
Contributor

presidento commented Apr 8, 2023

was tests.nu, now renamed tests/run.nu, meant to be a part of the library?

For me, sooner or later, absolutely yes. Previously it contained only the tests, but now it is an almost complete unit testing framework. (The remaining part of supporting setup / teardown commands are in #8776). Some parts of this framework are already on standard library (the asserts), but they are not so useful without the runner.

I already created a PR to enhance Python plugin, and added tests for plugins. (Unfortunately I was not able to register a plugin in the CI, so I just closed that.)

I think in Nushell we can consider these as the recommended or the existing way of testing any code in Nushell.

If you wish, it can be done later, as well.

@amtoine
Copy link
Member Author

amtoine commented Apr 8, 2023

For me, sooner or later, absolutely yes. Previously it contained only the tests, but now it is an almost complete unit testing framework. ... I think in Nushell we can consider these as the recommended or the existing way of testing any code in Nushell.

i agree with that

If you wish, it can be done later, as well.

yes, i prefer leaving the library untouched in this PR, only moving its parts 😌

@kubouch
Copy link
Contributor

kubouch commented Apr 8, 2023

@amtoine You don't need to keep naming the commands with the module name. E.g., inside assert.nu you can define just def error instead of def "assert error". Then, you just call use assert.nu without the *. It's cleaner to do it that way since currently you're duplicating the assert namespace: You're creating a command named "assert error" inside the assert module.

bobhy added a commit to bobhy/nushell that referenced this pull request Apr 9, 2023
@amtoine
Copy link
Member Author

amtoine commented Apr 9, 2023

@kubouch

you are absolutely right, thanks for pointing this out to me 😮

i thought this would change the behaviour of the imports, i.e. exposing only equal for instance instead of assert equal, but it does not 👌

@amtoine
Copy link
Member Author

amtoine commented Apr 9, 2023

@kubouch

mm an annoying thing is that we have some built-in command shadowing 🤔
e.g.
assert length, assert str contains, possibly xml update, xml insert, also dirs drop, ...

fixing the namespace right now would require changing some of the API 😕
i'm not sure it's the right PR to do so 😬

even though it's not perfect, at least the behaviour is the same right now as previously, wihout changing any command names 😌

@amtoine amtoine marked this pull request as ready for review April 9, 2023 08:55
@kubouch
Copy link
Contributor

kubouch commented Apr 9, 2023

When you call use assert.nu, the commands will be named assert length etc., there won't be name shadowing.

But that can be done in another PR, that's OK. I'm also working in module changes which we can take advantage of in stdlib so there might be more changes in the future anyway.

@amtoine
Copy link
Member Author

amtoine commented Apr 9, 2023

When you call use assert.nu, the commands will be named assert length etc., there won't be name shadowing.

not in the user space yes 👍
but i meant in the submodules themselves 😕

e.g. in the assert.nu submodule, assert length uses the builtin length command and assert str contains uses the builtin str contains command.
with use assert * all is fine.

but if we use use assert and rename the commands to length and str contains, that will break the whole library 🤔

But that can be done in another PR, that's OK. I'm also working in module changes which we can take advantage of in stdlib so there might be more changes in the future anyway.

oooh yeah definitely things we'll use in nu-std 💪

@fdncred fdncred added the std-library Defining and improving the standard library written in nu and the core Rust ccommands label Apr 9, 2023
@kubouch
Copy link
Contributor

kubouch commented Apr 9, 2023

I see, then you'll need to use a command with a different name internally inside the module. This is an interesting problem. A long-term solution I see is to have built-in commands in modules (imported by default). That would allow higher naming flexibility if you run into this situation, e.g., you could do use core and refer to the original length as core length inside the module.

@amtoine
Copy link
Member Author

amtoine commented Apr 9, 2023

I see, then you'll need to use a command with a different name internally inside the module. This is an interesting problem. A long-term solution I see is to have built-in commands in modules (imported by default). That would allow higher naming flexibility if you run into this situation, e.g., you could do use core and refer to the original length as core length inside the module.

a core "module" to avoid built-in shadowing would be AMAZING 🤩

@kubouch kubouch merged commit 4a955d7 into nushell:main Apr 9, 2023
15 checks passed
@amtoine amtoine deleted the wip/refactor/stdlib/multi-module-library branch April 9, 2023 17:03
bobhy added a commit to bobhy/nushell that referenced this pull request Apr 9, 2023
sophiajt pushed a commit that referenced this pull request Apr 9, 2023
> **Note**
> waiting for
> - #8770
> - #8815

# Description
this PR adds a very basic completion support to the `help`
implementations of the `std`.

# User-Facing Changes
completion on all the `std help ...` commands, based on the names in
`$nu.scope.`

# Tests + Formatting
- ⚫ `toolkit fmt`
- ⚫ `toolkit clippy`
- ⚫ `toolkit test`
- ⚫ `toolkit test stdlib`

# After Submitting
```
$nothing
```
bobhy added a commit to bobhy/nushell that referenced this pull request Apr 10, 2023
MariaSolOs added a commit to MariaSolOs/nushell that referenced this pull request Apr 12, 2023
commit 8ee52b6
Author: JT <547158+jntrnr@users.noreply.github.com>
Date:   Wed Apr 12 05:21:52 2023 +1200

    Relax the closure syntax, highlight differently (nushell#8846)

    This relaxes the closure syntax so that `||` is no longer required. This
    allows for `ls | each { $in.name }` for example.

    I've gone ahead and changed the syntax highlighting so that blocks and
    closures are distinct for now.

    Removes `||` requirement for closures.

    Don't forget to add tests that cover your changes.

    Make sure you've run and fixed any issues with these commands:

    - `cargo fmt --all -- --check` to check standard code formatting (`cargo
    fmt --all` applies these changes)
    - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
    clippy::needless_collect` to check that you're using the standard code
    style
    - `cargo test --workspace` to check that all tests pass
    - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
    standard library

    > **Note**
    > from `nushell` you can also use the `toolkit` as follows
    > ```bash
    > use toolkit.nu # or use an `env_change` hook to activate it
    automatically
    > toolkit check pr
    > ```

    If your PR had any user-facing changes, update [the
    documentation](https://github.com/nushell/nushell.github.io) after the
    PR is merged, if necessary. This will help us keep the docs up to date.

commit 46dba88
Author: JT <547158+jntrnr@users.noreply.github.com>
Date:   Wed Apr 12 05:21:31 2023 +1200

    Revert numberlike parsing restriction (nushell#8845)

    This effectively reverts nushell#8635. We shipped this change with 0.78 and
    received many comments/issues related to this restriction feeling like a
    step backward.

    fixes: nushell#8844
    (and probably other issues)

    Returns numbers and number-like values to being allowed to be bare
    words. Examples: `3*`, `1fb43`, `4,5`, and related.

    Don't forget to add tests that cover your changes.

    Make sure you've run and fixed any issues with these commands:

    - `cargo fmt --all -- --check` to check standard code formatting (`cargo
    fmt --all` applies these changes)
    - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
    clippy::needless_collect` to check that you're using the standard code
    style
    - `cargo test --workspace` to check that all tests pass
    - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
    standard library

    > **Note**
    > from `nushell` you can also use the `toolkit` as follows
    > ```bash
    > use toolkit.nu # or use an `env_change` hook to activate it
    automatically
    > toolkit check pr
    > ```

    If your PR had any user-facing changes, update [the
    documentation](https://github.com/nushell/nushell.github.io) after the
    PR is merged, if necessary. This will help us keep the docs up to date.

commit eb4d19f
Author: federico viscomi <federicoviscomi@gmail.com>
Date:   Mon Apr 10 22:52:51 2023 +0100

    Parser panic for signature with multibyte char for short flag nushell#8821 (nushell#8849)

    Hey I'm a developer and I'm still new to nushell and rust but I would
    like to learn more about both. This is my first PR for this project.

    The intent of my change is to allow to use multibyte utf-8 characters in
    commands short flags.

commit c367876
Author: Máté FARKAS <fm@farkas-mate.hu>
Date:   Mon Apr 10 22:42:11 2023 +0200

    stdlib test runner: implement `setup` and `teardown` commands to unit tests (nushell#8776)

    As in other testing frameworks, the `setup` runs before every test case,
    and the `teardown` after that. A context can be created in `setup`,
    which will be in the `$in` variable in the test cases, and in the
    `teardown`. The `teardown` is called regardless of the test is passed,
    skipped, or failed.

    For example:

    ```nushell
    use std.nu *

    export def setup [] {
        log debug "Setup is running"
        {msg: "This is the context"}
    }

    export def teardown [] {
        log debug $"Teardown is running. Context: ($in)"
    }

    export def test_assert_pass [] {
        log debug $"Assert is running. Context: ($in)"
    }

    export def test_assert_skip [] {
        log debug $"Assert is running. Context: ($in)"
        assert skip
    }

    export def test_assert_fail_skipped_by_default [] {
        log debug $"Assert is running. Context: ($in)"
        assert false
    }
    ```

    ![image](https://user-images.githubusercontent.com/282320/230466359-9908cc72-edbd-4150-9aff-d15fe42c0cc7.png)

    I'll update the documentation.

    ---------

    Co-authored-by: Mate Farkas <Mate.Farkas@oneidentity.com>

commit 9bb2c8f
Author: Justin Ma <hustcer@outlook.com>
Date:   Tue Apr 11 04:10:41 2023 +0800

    Upgrade to nu v0.78 for binaries release workflow (nushell#8840)

    Upgrade to nu v0.78 for binary packages release workflow

    Test Release: https://github.com/hustcer/nu-release/releases/tag/v0.78.2
    Release workflow running output:
    https://github.com/hustcer/nu-release/actions/runs/4656319252/jobs/8239828202

    _(List of all changes that impact the user experience here. This helps
    us keep track of breaking changes.)_

    Don't forget to add tests that cover your changes.

    Make sure you've run and fixed any issues with these commands:

    - `cargo fmt --all -- --check` to check standard code formatting (`cargo
    fmt --all` applies these changes)
    - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
    clippy::needless_collect` to check that you're using the standard code
    style
    - `cargo test --workspace` to check that all tests pass
    - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
    standard library

    > **Note**
    > from `nushell` you can also use the `toolkit` as follows
    > ```bash
    > use toolkit.nu # or use an `env_change` hook to activate it
    automatically
    > toolkit check pr
    > ```

    If your PR had any user-facing changes, update [the
    documentation](https://github.com/nushell/nushell.github.io) after the
    PR is merged, if necessary. This will help us keep the docs up to date.

commit 74dcac3
Author: nibon7 <nibon7@163.com>
Date:   Tue Apr 11 02:52:42 2023 +0800

    Fix process_range on 32-bit platforms (nushell#8842)

    This PR fixes
    `commands::str_::substrings_the_input_and_treats_end_index_as_length_if_blank_end_index_given`
    testcase on 32-bit platform.

    ```
    failures:
    ---- commands::str_::substrings_the_input_and_treats_end_index_as_length_if_blank_end_index_given stdout ----
    === stderr
    thread 'commands::str_::substrings_the_input_and_treats_end_index_as_length_if_blank_end_index_given' panicked at 'assertion failed: `(left == right)`
      left: `"arepa"`,
     right: `"arepas"`', crates/nu-command/tests/commands/str_/mod.rs:363:9
    failures:
        commands::str_::substrings_the_input_and_treats_end_index_as_length_if_blank_end_index_given
    test result: FAILED. 1072 passed; 1 failed; 23 ignored; 0 measured; 0 filtered out; finished in 2.98s
    error: test failed, to rerun pass `-p nu-command --test main`
    ```

    https://gitlab.alpinelinux.org/nibon7/aports/-/jobs/1005935#L3864
    https://gitlab.alpinelinux.org/nibon7/aports/-/jobs/1005931#L3867

    N/A

    Don't forget to add tests that cover your changes.

    Make sure you've run and fixed any issues with these commands:

    - `cargo fmt --all -- --check` to check standard code formatting (`cargo
    fmt --all` applies these changes)
    - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
    clippy::needless_collect` to check that you're using the standard code
    style
    - `cargo test --workspace` to check that all tests pass
    - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
    standard library

    > **Note**
    > from `nushell` you can also use the `toolkit` as follows
    > ```bash
    > use toolkit.nu # or use an `env_change` hook to activate it
    automatically
    > toolkit check pr
    > ```

    If your PR had any user-facing changes, update [the
    documentation](https://github.com/nushell/nushell.github.io) after the
    PR is merged, if necessary. This will help us keep the docs up to date.

commit 6d51e34
Author: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
Date:   Mon Apr 10 20:32:33 2023 +0200

    stdlib: make helper modules available in std (nushell#8841)

    > **Note**
    > waiting for the following to land
    > - nushell#8824 to avoid conflicts,
    i'll add this to `CONTRIBUTING.md` once it's ready 👍

    should close nushell#8839
    this PR moves the `log` submodule of `std` to the top of the call stack,
    making it available in the rest of the library as `log`.
    i've added some comments around the `submodules` list in
    `load_standard_library` to make it clear how it should work.
    `log` and `assert` are now available in the rest of `std`.
    - 🟢 `toolkit fmt`
    - 🟢 `toolkit clippy`
    - ⚫ `toolkit test`
    - 🟢 `toolkit test stdlib`
    ```
    $nothing
    ```

commit de76c7a
Author: WindSoilder <WindSoilder@outlook.com>
Date:   Tue Apr 11 01:23:22 2023 +0800

    Remove autoprinting of `for` loop (nushell#8843)

    It's an addition to nushell#8618
    And I think it's good to keep the same behavior when we use for loop for
    list.

    Don't forget to add tests that cover your changes.

    Make sure you've run and fixed any issues with these commands:

    - `cargo fmt --all -- --check` to check standard code formatting (`cargo
    fmt --all` applies these changes)
    - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
    clippy::needless_collect` to check that you're using the standard code
    style
    - `cargo test --workspace` to check that all tests pass
    - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
    standard library

    > **Note**
    > from `nushell` you can also use the `toolkit` as follows
    > ```bash
    > use toolkit.nu # or use an `env_change` hook to activate it
    automatically
    > toolkit check pr
    > ```

    If your PR had any user-facing changes, update [the
    documentation](https://github.com/nushell/nushell.github.io) after the
    PR is merged, if necessary. This will help us keep the docs up to date.

commit 0e23400
Author: Stefan Holderbach <sholderbach@users.noreply.github.com>
Date:   Mon Apr 10 03:42:43 2023 +0200

    Follow up nushell#8758 with a style fix (nushell#8822)

    The old comment around the question mark operator doesn't make sense
     to me based on the closure signature.
    The `match` expressions were thus superfluous.

    None

    No change

commit d0a83fe
Author: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
Date:   Mon Apr 10 00:59:57 2023 +0200

    stdlib: add completion to `help` commands (nushell#8799)

    > **Note**
    > waiting for
    > - nushell#8770
    > - nushell#8815
    this PR adds a very basic completion support to the `help`
    implementations of the `std`.
    completion on all the `std help ...` commands, based on the names in
    `$nu.scope.`
    - ⚫ `toolkit fmt`
    - ⚫ `toolkit clippy`
    - ⚫ `toolkit test`
    - ⚫ `toolkit test stdlib`
    ```
    $nothing
    ```

commit 57510f2
Author: Stefan Holderbach <sholderbach@users.noreply.github.com>
Date:   Mon Apr 10 00:56:47 2023 +0200

    Move CLI related commands to `nu-cli` (nushell#8832)

    Part of the larger cratification effort.

    Moves all `reedline` or shell line editor specific commands to `nu-cli`.
    - `commandline`
    - This shouldn't have moved there. Doesn't directly depend on reedline
    but assumes parts in the engine state that are specific to the use of
    reedline or a REPL
    - `keybindings` and subcommands
      - `keybindings default`
      - `keybindings list`
      - `keybindings listen`
        - very `reedline` specific
    - `history`
      - needs `reedline`
    - `history session`
    Instead of having a separate `create_default_context()` that calls
    `nu-command`'s `create_default_context()`, I added a `add_cli_context()`
    that updates an `EngineState`

    None

    `cargo build --timings` from a `cargo clean --profile dev`
    main: 64 secs
    this: 59 secs

    branch | total| codegen | fraction
    ---|---|---|---
    main | 14.0s | 6.2s | (44%)
    this | 12.5s | 5.5s | (44%)

    `nu-cli` depends on `nu-command` at the moment.
    Thus it is built during the code-gen phase of `nu-command` (on 16
    virtual cores)

    I removed the `test_example()` facilities for now as we had not run any
    of the commands in an `Example` test and importing the right context for
    those tests seemed more of a hassle than the duplicated
    `test_examples()` implementations in `nu-cmd-lang` and `nu-command`

commit 58b96fd
Author: JT <547158+jntrnr@users.noreply.github.com>
Date:   Mon Apr 10 10:55:29 2023 +1200

    Add option to not load std-lib. Default tests to not use std-lib (nushell#8833)

    this adds a `--no-std-lib` flag. Moves `nu!` to use the `--no-std-lib`.
    Adds a new `nu_with_std!` macro for future tests that need the std-lib.

    _(Thank you for improving Nushell. Please, check our [contributing
    guide](../CONTRIBUTING.md) and talk to the core team before making major
    changes.)_

    _(Description of your pull request goes here. **Provide examples and/or
    screenshots** if your changes affect the user experience.)_

    _(List of all changes that impact the user experience here. This helps
    us keep track of breaking changes.)_

    Don't forget to add tests that cover your changes.

    Make sure you've run and fixed any issues with these commands:

    - `cargo fmt --all -- --check` to check standard code formatting (`cargo
    fmt --all` applies these changes)
    - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
    clippy::needless_collect` to check that you're using the standard code
    style
    - `cargo test --workspace` to check that all tests pass
    - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
    standard library

    > **Note**
    > from `nushell` you can also use the `toolkit` as follows
    > ```bash
    > use toolkit.nu # or use an `env_change` hook to activate it
    automatically
    > toolkit check pr
    > ```

    If your PR had any user-facing changes, update [the
    documentation](https://github.com/nushell/nushell.github.io) after the
    PR is merged, if necessary. This will help us keep the docs up to date.

commit 9e3d6c3
Author: JT <547158+jntrnr@users.noreply.github.com>
Date:   Mon Apr 10 08:55:47 2023 +1200

    Only add the std lib files once (nushell#8830)

    We were seeing duplicate entries for the std lib files, and this PR
    addresses that. Each file should now only be added once.

    Note: they are still parsed twice because it's hard to recover the
    module from the output of `parse` but a bit of clever hacking in a
    future PR might be able to do that.

    _(List of all changes that impact the user experience here. This helps
    us keep track of breaking changes.)_

    Don't forget to add tests that cover your changes.

    Make sure you've run and fixed any issues with these commands:

    - `cargo fmt --all -- --check` to check standard code formatting (`cargo
    fmt --all` applies these changes)
    - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
    clippy::needless_collect` to check that you're using the standard code
    style
    - `cargo test --workspace` to check that all tests pass
    - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
    standard library

    > **Note**
    > from `nushell` you can also use the `toolkit` as follows
    > ```bash
    > use toolkit.nu # or use an `env_change` hook to activate it
    automatically
    > toolkit check pr
    > ```

    If your PR had any user-facing changes, update [the
    documentation](https://github.com/nushell/nushell.github.io) after the
    PR is merged, if necessary. This will help us keep the docs up to date.

commit 4a955d7
Author: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
Date:   Sun Apr 9 19:00:20 2023 +0200

    stdlib: refactor into a multi-module library (nushell#8815)

commit 637283f
Author: mike <98623181+1Kinoti@users.noreply.github.com>
Date:   Sat Apr 8 23:04:57 2023 +0300

    allow register to accept a const argument (nushell#8758)

    this pr allows `register` to be used with const variables
    ```nu
    const math_plugin = "~/.config/nushell/plugins/nu_plugin_math"
    register $math_plugin
    ```

    should close nushell#8208, previous work nushell#8435

commit 5afbfb5
Author: Maria José Solano <majosolano99@gmail.com>
Date:   Sat Apr 8 11:52:37 2023 -0700

    Use `pretty_assertions` in the root crate (nushell#8818)

    This PR is just a minor development improvement. While working on
    another feature, I noticed that the root crate lists the super useful
    `pretty_assertions` in the root crate but doesn't use it in most tests.
    With this change `pretty_assertions::assert_eq!` is used instead of
    `core::assert_eq!` for better diffs when debugging the tests.

    I thought of adding the dependency to other crates but I decided not to
    since I didn't want a huge disruptive PR :)

commit d128c0e
Author: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
Date:   Sat Apr 8 14:35:16 2023 +0200

    stdlib: use the loaded library in tests and update `README` (nushell#8811)

    Should close nushell#8809.
    this PR uses the automatically loaded library from the tests by
    replacing `use std.nu ...` with `use std ...`.

    the `README` has been updated by
    - removing the very deprencated "concrete examples"
    - fixing the `use std` and the "run the tests" sections

    the `README` can be previewed
    [here](https://github.com/amtoine/nushell/blob/refactor/stdlib/use-std-in-tests-and-update-readme/crates/nu-std/README.md)
    👍
    ```
    $nothing
    ```
    - 🟢 `toolkit test stdlib`
    ```
    $nothing
    ```

commit 60e6ea5
Author: Michael Angerman <1809991+stormasm@users.noreply.github.com>
Date:   Sat Apr 8 04:53:43 2023 -0700

    remove nu_cli crate dependency from nu_std (nushell#8807)

    now nu_std only depends on nu_parser, nu_protocol and miette
    and removes the nu_cli dependency

    this enables developers moving forward to come along and implement their
    own CLI's without having to pull in a redundant nu-cli which will not be
    needed for them.

    I did this by moving report_error into nu_protocol
    which nu_std already has a dependency on anyway....

    - `cargo fmt --all -- --check` to check standard code formatting (`cargo
    fmt --all` applies these changes)
    - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
    clippy::needless_collect` to check that you're using the standard code
    style
    - `cargo test --workspace` to check that all tests pass
    - `cargo run -- crates/nu-std/tests.nu` to run the tests for the
    standard library

    > **Note**
    > from `nushell` you can also use the `toolkit` as follows
    > ```bash
    > use toolkit.nu # or use an `env_change` hook to activate it
    automatically
    > toolkit check pr
    > ```

commit 4156077
Author: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
Date:   Sat Apr 8 13:19:09 2023 +0200

    remove the "MODULE NOT FOUND" print from the parser (nushell#8816)

    related to nushell#8765.
    should close nushell#8812.
    this PR simply removes the `prinln("MODULE NOT FOUND")` from the parser.
    no more `MODULE NOT FOUND` while typing a `use` command
bobhy added a commit to bobhy/nushell that referenced this pull request Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
std-library Defining and improving the standard library written in nu and the core Rust ccommands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants