8000 wolf runs into error with env vars · Issue #52 · Duroktar/Wolf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

wolf runs into error with env vars #52

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

Closed
Almenon opened this issue Nov 26, 2020 · 3 comments · Fixed by #54
Closed

wolf runs into error with env vars #52

Almenon opened this issue Nov 26, 2020 · 3 comments · Fixed by #54

Comments

@Almenon
Copy link
Contributor
Almenon commented Nov 26, 2020

Python code:

import os

test=os.environ['USERNAME'] #?
path=os.environ['Path'] # also fails
print(path)

Expected result: logs 'almenon'
Actual result:
image

In AREPL I avoid this problem by using python-shell and passing the env vars in like so:

Constructor of arepl-backend:

		if (!options.env) options.env = {}
		if (process.platform == "darwin") {
			// needed for Mac to prevent ENOENT
			options.env.PATH = ["/usr/local/bin", process.env.PATH].join(":")
		}
		else if (process.platform == "win32") {
			// needed for windows for encoding to match what it would be in terminal
			// https://docs.python.org/3/library/sys.html#sys.stdin
			options.env.PYTHONIOENCODING = "utf8"
		}

In start() method in backend:
https://github.com/Almenon/AREPL-backend/blob/209eb5b8ae8cda1677f925749a10cd263f6d9860/index.ts#L171

this.pyshell = new PythonShell('arepl_python_evaluator.py', this.options)

In arepl-vscode I borrowed some code from the python extension, adapted it a bit and hardcoded it into a folder called "env": https://github.com/Almenon/AREPL-vscode/tree/7ed81bd83b8b30b1d18366c7f1254b13b6dc6ba6/src/env

Then in https://github.com/Almenon/AREPL-vscode/blob/d8c9f32d573213163f27e903e31df197be1e8248/src%2FPreviewManager.ts#L5 I have:

    async loadAndWatchEnvVars(){
        const platformService = new PlatformService()
        const envVarsService = new EnvironmentVariablesService(new PathUtils(platformService.isWindows))
        const workspaceService = new WorkspaceService()
        const e = new EnvironmentVariablesProvider(envVarsService,
            this.subscriptions,
            platformService,
            workspaceService,
            process)
        return e.getEnvironmentVariables(areplUtils.getEnvFilePath(), vscodeUtils.getCurrentWorkspaceFolderUri())
    }
        // basically all this does is load a file.. why does it need to be async *sob*
        const env = await this.loadAndWatchEnvVars()

        this.PythonEvaluator = new PythonEvaluator({
            pythonOptions,
            pythonPath,
            env,
        })

The python extension code has the benefit of also reading from the workspace .env file. The downside is that it is very large and complex, probably overengineered IMO.

@Almenon Almenon changed the title env vars don't work wolf runs into error with env vars Nov 26, 2020
@Almenon
Copy link
Contributor Author
Almenon commented Nov 26, 2020

I took a look in the code in #54 - did this fix the problem when you tested it? I think you would still have the same issue - the environment vars you pass in just has the PATH in darwin OS's but it should have the USERNAME and other env vars too.

I'm guessing you need to pass in process.env.

@Duroktar
Copy link
Owner

Hehe, I had to hotfix it afterwards: d2c59d9

And you were 100% right :D I really don't know how it got passed the unit tests to begin with (local pytest cache maybe?), merging in process.env was the magic bit.

PS: Really good to hear from you again old friend :)

@Almenon
Copy link
Contributor Author
Almenon commented Nov 27, 2020

Good to see you again too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0