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

Can't use standard library module within the standard library (?) #8839

Closed
bobhy opened this issue Apr 10, 2023 · 15 comments · Fixed by #8841
Closed

Can't use standard library module within the standard library (?) #8839

bobhy opened this issue Apr 10, 2023 · 15 comments · Fixed by #8841
Labels
std-library Defining and improving the standard library written in nu and the core Rust ccommands
Milestone

Comments

@bobhy
Copy link
Contributor

bobhy commented Apr 10, 2023

Describe the bug

Trying to add a call to std log info in crates/nu-std/lib/dirs.nu for, e.g, std dirs next, another module in the standard library.

It would be a grave restriction indeed if some commands in the standard library could not be used within other commands of the standard library.

How to reproduce

  1. in crates/nu-std/lib/dirs.nu (for example), add use std log info in either of the locations indicated below (or both).
  2. `〉cargo run -- -c 'use std *; dirs next'
  3. or do a build and run the binary: > cargo build; target/debug/nu -c 'use std *; dirs next'

Expected behavior

Info log output from invoked dirs next command

Screenshots

10 repetitions of the 'module not found' error, all from the same source line.

~/src/rust/nushell〉cargo run -- -c 'use std *; dirs next'
    Finished dev [unoptimized + debuginfo] target(s) in 0.25s
     Running `target/debug/nu -c 'use std *; dirs next'`
Error: nu::parser::module_not_found

  × Module not found.
    ╭─[dirs:33:1]
 33 │ ] {
 34 │     use std "log info"
    ·         ─┬─
    ·          ╰── module not found
 35 │ 
    ╰────
  help: module files and their paths must be available before your script is run as parsing occurs before anything
        is evaluated

Error: nu::parser::module_not_found

  × Module not found.
    ╭─[dirs:33:1]
 33 │ ] {
 34 │     use std "log info"
    ·         ─┬─
    ·          ╰── module not found
 35 │ 
    ╰────
  help: module files and their paths must be available before your script is run as parsing occurs before anything
        is evaluated

Error: nu::parser::module_not_found

  × Module not found.
    ╭─[dirs:33:1]
 33 │ ] {
 34 │     use std "log info"
    ·         ─┬─
    ·          ╰── module not found
 35 │ 
    ╰────
  help: module files and their paths must be available before your script is run as parsing occurs before anything
        is evaluated

Error: nu::parser::module_not_found

  × Module not found.
    ╭─[dirs:33:1]
 33 │ ] {
 34 │     use std "log info"
    ·         ─┬─
    ·          ╰── module not found
 35 │ 
    ╰────
  help: module files and their paths must be available before your script is run as parsing occurs before anything
        is evaluated

Error: nu::parser::module_not_found

  × Module not found.
    ╭─[dirs:33:1]
 33 │ ] {
 34 │     use std "log info"
    ·         ─┬─
    ·          ╰── module not found
 35 │ 
    ╰────
  help: module files and their paths must be available before your script is run as parsing occurs before anything
        is evaluated

Error: nu::parser::module_not_found

  × Module not found.
    ╭─[dirs:33:1]
 33 │ ] {
 34 │     use std "log info"
    ·         ─┬─
    ·          ╰── module not found
 35 │ 
    ╰────
  help: module files and their paths must be available before your script is run as parsing occurs before anything
        is evaluated

Error: nu::parser::module_not_found

  × Module not found.
    ╭─[dirs:33:1]
 33 │ ] {
 34 │     use std "log info"
    ·         ─┬─
    ·          ╰── module not found
 35 │ 
    ╰────
  help: module files and their paths must be available before your script is run as parsing occurs before anything
        is evaluated

Error: nu::parser::module_not_found

  × Module not found.
    ╭─[dirs:33:1]
 33 │ ] {
 34 │     use std "log info"
    ·         ─┬─
    ·          ╰── module not found
 35 │ 
    ╰────
  help: module files and their paths must be available before your script is run as parsing occurs before anything
        is evaluated

Error: nu::parser::module_not_found

  × Module not found.
    ╭─[dirs:33:1]
 33 │ ] {
 34 │     use std "log info"
    ·         ─┬─
    ·          ╰── module not found
 35 │ 
    ╰────
  help: module files and their paths must be available before your script is run as parsing occurs before anything
        is evaluated

Error: nu::parser::module_not_found

  × Module not found.
    ╭─[dirs:33:1]
 33 │ ] {
 34 │     use std "log info"
    ·         ─┬─
    ·          ╰── module not found
 35 │ 
    ╰────
  help: module files and their paths must be available before your script is run as parsing occurs before anything
        is evaluated

thread 'main' panicked at 'Internal error: can't run a predeclaration without a body', crates/nu-protocol/src/signature.rs:686:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: nu::shell::column_not_found

  

Configuration

key value
version 0.78.1
branch stdlib_contributing
commit_hash f2b977b
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.66.1 (90743e729 2023-01-10)
rust_channel 1.66.1-x86_64-unknown-linux-gnu
cargo_version cargo 1.66.1 (ad779e08b 2023-01-10)
build_time 2023-04-07 21:17:57 -04:00
build_rust_channel debug
features default, zip
installed_plugins

Additional context

Here's the relevant chunk of dirs.nu:

# Maintain a list of working directories and navigates them

use std "log info"

# the directory stack
export-env {
    let-env DIRS_POSITION = 0
    let-env DIRS_LIST = [($env.PWD | path expand)]
}

# Add one or more directories to the list.
# PWD becomes first of the newly added directories.
export def-env "dirs add" [
    ...paths: string    # directory or directories to add to working list
    ] {
        mut abspaths = []
        for p in $paths {
            let exp = ($p | path expand)
            if ($exp | path type) != 'dir' {
                let span = (metadata $p).span
                error make {msg: "not a directory", label: {text: "not a directory", start: $span.start, end: $span.end } }
            }
        $abspaths = ($abspaths | append $exp)

        }
        let-env DIRS_LIST = ($env.DIRS_LIST | insert ($env.DIRS_POSITION + 1) $abspaths | flatten)
        let-env DIRS_POSITION = $env.DIRS_POSITION + 1

    _fetch 0
}

# Advance to the next directory in the list or wrap to beginning.
export def-env "dirs next" [
    N:int = 1   # number of positions to move.
] {
    use std "log info"

    _fetch $N
    log info $"advancing to position ($env.DIRS_POSITION)"
}
@amtoine
Copy link
Member

amtoine commented Apr 10, 2023

i can reproduce this on latest main (0e23400)

here is a patch to apply to change the library in the way it breaks on latest main

diff --git a/crates/nu-std/lib/dirs.nu b/crates/nu-std/lib/dirs.nu
index d2e966446..5b2138eac 100644
--- a/crates/nu-std/lib/dirs.nu
+++ b/crates/nu-std/lib/dirs.nu
@@ -1,5 +1,7 @@
 # Maintain a list of working directories and navigates them
 
+use log 'log info'
+
 # the directory stack
 export-env {
     let-env DIRS_POSITION = 0
@@ -31,6 +33,8 @@ export def-env "dirs add" [
 export def-env "dirs next" [
     N:int = 1   # number of positions to move.
 ] {
+    log info "`dirs next` from global import"
+
     _fetch $N    
 }
 
@@ -56,6 +60,9 @@ export def-env "dirs drop" [] {
 
 # Display current working directories.
 export def-env "dirs show" [] {
+    use log 'log warning'
+    log warning "`dirs show` from local import"
+
     mut out = []
     for $p in ($env.DIRS_LIST | enumerate) {
         $out = ($out | append [

then

cargo run -- -c 'use std *; dirs next'

as said above 👍

@amtoine
Copy link
Member

amtoine commented Apr 10, 2023

cargo run will already produce this error.
then a use std * won't actually import anything and dirs show gives

Error: nu::shell::external_command

  × External command failed
    ╭─[dirs:63:1]
 63 │ export def-env "dirs show" [] {
 64 │     log info "dirs show"
    ·     ─┬─
    ·      ╰── executable was not found
 65 │     mut out = []
    ╰────
  help: No such file or directory (os error 2)

and interestingly enough,

  • dirs next will make nushell panic
  • dirs show will only give an error without panicking

both with the same chain of nu::parser::module_not_found errors[

@amtoine
Copy link
Member

amtoine commented Apr 10, 2023

📯 📯 i know what is happening here

in the loader, i.e. load_standard_library in nu-std, the modules are loaded in that very order:

  • assert from lib/assert.nu
  • dirs from lib/dirs.nu
  • help from lib/help.nu
  • log from lib/log.nu
  • xml from lib/xml.nu
  • and finally the main std module from lib/mod.nu (the std help commands of the prelude are loaded here)

❓ here you are trying to perform some kind of cyclic import right?
importing std inside of std itself 🤔

i think this will be tideous...

🔧 the first fix is to use log 'log info' instead of use std 'log info'

there is a second issue, it's that, as now, dirs is parsed BEFORE log and thus the log module is not available...

🔧 the second fix is to change the loading order with

diff --git a/crates/nu-std/src/lib.rs b/crates/nu-std/src/lib.rs
index 7c847cb49..6e6c20078 100644
--- a/crates/nu-std/src/lib.rs
+++ b/crates/nu-std/src/lib.rs
@@ -68,9 +68,10 @@ pub fn load_standard_library(
 
         let submodules = vec![
             ("assert", include_str!("../lib/assert.nu")),
+            ("log", include_str!("../lib/log.nu")),
+
             ("dirs", include_str!("../lib/dirs.nu")),
             ("help", include_str!("../lib/help.nu")),
-            ("log", include_str!("../lib/log.nu")),
             ("xml", include_str!("../lib/xml.nu")),
         ];

to make things like assert and log available in the other modules

then you can apply the patch above to the dirs module and it will work as expected!

Warning
these are just fixes for now, not a direction to follow in the future.
it's how the loading and parsing of std currently works 😌

Note
with the two patches

  • cargo run -- --no-config-file -c 'use std *; dirs next' will give
INF|...|`dirs next` from global import
  • cargo run -- --no-config-file -c 'use std *; dirs show' will give
WRN|...|`dirs show` from local import
╭───┬────────┬──────╮
│ # │ active │ path │
├───┼────────┼──────┤
│ 0 │ true   │ ...  │
╰───┴────────┴──────╯

@kubouch
Copy link
Contributor

kubouch commented Apr 10, 2023

Instead of trying to use std log info, can you use log.nu inside dirs.nu and use just log info?

@amtoine
Copy link
Member

amtoine commented Apr 10, 2023

Instead of trying to use std log info, can you use log.nu inside dirs.nu and use just log info?

no we can not because log.nu is not a runtime thing for nushell => there is no log.nu file in the final binary nor on the user's filesystem.

we can change the loading to name the module log.nu instead of log but that adds 3 unnecessary characters here and we still need to

  • use log.nu * to have access to log info and log warning
  • put the log.nu line at the top of the submodules in load_standard_library

🤔

@amtoine
Copy link
Member

amtoine commented Apr 10, 2023

we have a namespace issue in the library, that's quite clear i think 😋

=> unticked the "structure" point of the roadmap and added a "namespace item" for now 😌

@kubouch
Copy link
Contributor

kubouch commented Apr 10, 2023

Ah, I see. Seems like we should finally create the long-awaited file cache and make use etc. aware of it. Then, when calling use log.nu, the parser would look into the cache first, see that log.nu was already parsed before and give the parsed module without reparsing. That way you don't need the file to be on disk. Since the file is not in the file system, there is no chance it could change, so it should be safe to do so. We could` also write out the stdlib into real files but that brings issues with versioning etc.

If possible, I'd prefer not having submodules aware of being a part of some top module because it adds a lot of complexity and hinders code reuse. So far, we used a simple file-based module system that I think works quite well and is very straightforward. The stdlib is special because it doesn't have real files at runtime, but I think that's the only case where you'd have a Nushell module without a corresponding .nu file. The only other one I can think of are plugins in the future. If we make the file cache aware of this, we should be able to get around it.

@fdncred
Copy link
Collaborator

fdncred commented Apr 10, 2023

@amtoine, as a quick fix, it seems reasonable to me to load helpers first so they can be used by all, like log and assert.

@amtoine
Copy link
Member

amtoine commented Apr 10, 2023

@kubouch
agree with the fact that std is a special case of a "runtime module" without any .nu files 👍

@fdncred
cool, i can write a patch for this right now 👍

@bobhy
Copy link
Contributor Author

bobhy commented Apr 10, 2023

The key thing about the standard library is that we want all script modules to be able to use the tools defined in it. Ideally, the rules for importing stdlib tools would be literally the same for user written and stdlib modules (beyond a few, really core, stdlib modules if we can't avoid that).

If I'm understanding correctly, the file cache idea would allow us to say the rule is use use std 'log xxx' to import from stdlib in all module, full stop. Specifically, it would be use std log xxxinstd dirs, std clip, etc. @kubouch, is that where we'd be heading? It sounds like you're more concerned about whether the used module is on disk or not, which sound like an internal implementation detail that should not be exposed in an external API (the use` command and its usage).

For now, it sounds the patch to declare the helpers (my "core") first is good enough to document the long-term rule, which will be used by stdlib developers who are not working on the helpers (log, assert, etc.). I'll do that as soon as I can verify it works. Then we can drop in the more robust solution later on and not rewrite the interface contract.

External interfaces are sticky things, and I think the boundary between interpreter and standard library is one of those, even if they are (currently) produced by the same team. So, I'm using the need to document things in CONTRIBUTING as a forcing function to stabilize (and rationalize) the interface. Maybe I'm being too pedantic, or I'm off on a tangent? If you don't agree, don't hesitate to let me know!

@amtoine
Copy link
Member

amtoine commented Apr 10, 2023

i think the goal is to have

  • std for the top-level library to import all
  • std log for the log commands
  • std assert for the assertion commands
  • ...

two things that might change (which i do not think is a problem as this is at a very early stage) though

that can sound like a lot, but we do not have that much in the library for now anyway 😋
apart from the prelude, use std ... will probably say i'd say? 😌

@amtoine
Copy link
Member

amtoine commented Apr 10, 2023

i hope that answers a bit what you said above 😮

we do not have to plan too much, let's keep it growing and fix and define things as we get more contributions 😉

@bobhy
Copy link
Contributor Author

bobhy commented Apr 10, 2023

With the fix from #8841, I'm finding that this does not work:

dirs.nu
export def-env "dirs next" [
    N:int = 1   # number of positions to move.
] {
    use std 'log debug'

    log debug $"position was ($env.DIRS_POSITION)"
    _fetch $N    
    log debug $"position is now ($env.DIRS_POSITION)"
    
}

I get the 'module not found' error.

But if I change use std 'log debug' to use log 'log debug', it does work.

Can't let the perfect be the enemy of the good. I think this is good enough for now.

I'll document this as one rule for stdlib developers (use log 'log ...', in CONTRIBUTING) and a second rule for ordinary script module developers (use std 'log ...', README). If that's still wrong, you'll correct me in the PR review.

@amtoine
Copy link
Member

amtoine commented Apr 10, 2023

yeahh... this is the namespace issue mentionned in the roadmap 👀

fdncred pushed a commit that referenced this issue Apr 10, 2023
> **Note**
> waiting for the following to land
> - #8824 to avoid conflicts,
i'll add this to `CONTRIBUTING.md` once it's ready 👍

should close #8839 

# Description
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.
 
# User-Facing Changes
`log` and `assert` are now available in the rest of `std`.

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

# After Submitting
```
$nothing
```
@sholderbach sholderbach added the std-library Defining and improving the standard library written in nu and the core Rust ccommands label Apr 10, 2023
@hustcer hustcer added this to the v0.79.0 milestone Apr 11, 2023
@kubouch
Copy link
Contributor

kubouch commented Apr 11, 2023

@bobhy The file cache would allow you to use use log.nu from inside std.nu loaded inside Nushell without the files being on the disk. It would need to be marked as a "virtual file" or something like that which would bypass the otherwise mandatory check whether the file contents have changed (they cannot change because it's read-only). At least that's my idea how to solve this problem that doesn't require redesigning the current module system.

MariaSolOs added a commit to MariaSolOs/nushell that referenced this issue 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
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 a pull request may close this issue.

6 participants