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

test_virtualenv.nu errors #148

Closed
fdncred opened this issue Nov 20, 2024 · 7 comments
Closed

test_virtualenv.nu errors #148

fdncred opened this issue Nov 20, 2024 · 7 comments

Comments

@fdncred
Copy link
Collaborator

fdncred commented Nov 20, 2024

There's a script called test_virtualenv.nu in the nushell repo under scripts. It has many errors in it. So I'm just posting it here as a TODO.

Here's the script.

if $nu.os-info.family == 'windows' {
    # fix encoding on Windows https://stackoverflow.com/a/63573649
    load-env {
        PYTHONIOENCODING: utf-8
        PYTHONLEGACYWINDOWSSTDIO: utf-8
    }
}

let env_name = 'e-$ èрт🚒♞中片-j'

let paths = if $nu.os-info.family == 'windows' {
    ['Scripts', 'python.exe']
} else {
    ['bin', 'python']
}

let subdir = $paths.0
let exe = $paths.1

let test_lines = [
    "python -c 'import sys; print(sys.executable)'"                                  # 1
    "python -c 'import os; import sys; v = os.environ.get("VIRTUAL_ENV"); print(v)'" # 2
    $"overlay use '([$env.PWD $env_name $subdir activate.nu] | path join)'"
    "python -c 'import sys; print(sys.executable)'"                                  # 3
    "python -c 'import os; import sys; v = os.environ.get("VIRTUAL_ENV"); print(v)'" # 4
    "print $env.VIRTUAL_ENV_PROMPT"                                                  # 5
    "deactivate"
    "python -c 'import sys; print(sys.executable)'"                                  # 6
    "python -c 'import os; import sys; v = os.environ.get("VIRTUAL_ENV"); print(v)'" # 7
]

def main [] {
    let orig_python_interpreter = (python -c 'import sys; print(sys.executable)')

    let expected = [
        $orig_python_interpreter                           # 1
        "None"                                             # 2
        ([$env.PWD $env_name $subdir $exe] | path join)    # 3
        ([$env.PWD $env_name] | path join)                 # 4
        $env_name                                          # 5
        $orig_python_interpreter                           # 6
        "None"                                             # 7
    ]

    virtualenv $env_name

    $test_lines | save script.nu
    let out = (nu script.nu | lines)

    let o = ($out | str trim | str join (char nl))
    let e = ($expected | str trim | str join (char nl))
    if $o != $e {
        let msg = $"OUTPUT:\n($o)\n\nEXPECTED:\n($e)"
        error make {msg: $"Output does not match the expected value:\n($msg)"}
    }
    rm script.nu
}
@blindFS
Copy link
Contributor

blindFS commented Nov 20, 2024

I think it is a duplication of #125 ,
I feel it a little bit weird to allow " in " quoted strings, and fixing this seems not that easy, so personally I put lower priority to this.

@fdncred
Copy link
Collaborator Author

fdncred commented Nov 20, 2024

ya, double quotes within double quotes shouldn't work but I guess nushell handles it. Although, I've never ran this script to see but the vscode manual lsp handles it ok.

but single, backtick, and double quotes should all be embeddable within each other.

I'll close this as dupe and wait for when the other one is fixed. thanks!

@fdncred fdncred closed this as completed Nov 20, 2024
@blindFS
Copy link
Contributor

blindFS commented Nov 20, 2024

Yes, nushell handles this in a very flexible way. As long as there's no space inside the "inner string" and the quotes are properly paired, it's considered a valid string.

@fdncred
Copy link
Collaborator Author

fdncred commented Nov 20, 2024

We may be able to write that clearer with raw strings in the script too. Not sure if that works here or not.

@blindFS
Copy link
Contributor

blindFS commented Nov 20, 2024

I think it's definitely a better idea to suggest users to use raw strings in these scenarios. But tree-sitter-nu doesn't support raw string either for now. I think I can copy it from the rust grammar, which uses a scanner for raw strings.

@fdncred
Copy link
Collaborator Author

fdncred commented Nov 20, 2024

@mrdgo has been working on a raw strings scanner for a while now. It must be pretty complicated. I'm sure you've seen it.

@blindFS
Copy link
Contributor

blindFS commented Nov 20, 2024

Just had a glimpse of the code, seems pretty close to completion. I can take a look at the remaining issues if @mrdgo is not working on it any more.

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

No branches or pull requests

2 participants