Skip to content

Relative path import in windows10 #867

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
VanHWZ opened this issue Nov 30, 2020 · 3 comments
Closed

Relative path import in windows10 #867

VanHWZ opened this issue Nov 30, 2020 · 3 comments

Comments

@VanHWZ
Copy link

VanHWZ commented Nov 30, 2020

I call jsonnet in python with _jsonnet.evaluate_file() with part of jsonnet file as the following code block

//  /MyProjetc/env/test/deploy.jsonnet
local app = '../../app/helloworld.jsonnet'

/MyProject/app/helloworld.jsonnet is the jsonnet file I want to get imported.

However I cannot do it with an ERROR:

RuntimeError: RUNTIME ERROR: couldn't open import "../../apps/helloworld.jsonnet": no match locally or in the Jsonnet library paths.

Strangely, jsonnet CLI runs as expect with this relative path.

After many attempts, I find that the program works when /MyProjetc/env/test/deploy.jsonnet is modified as

//  /MyProjetc/env/test/deploy.jsonnet
local app = 'app/helloworld.jsonnet'

But in this case, jsonnet CLI encounters an ERROR:

RUNTIME ERROR: couldn't open import "apps/helloworld.jsonnet": no match locally or in the Jsonnet library paths

I try to run jsonnet CLI in python with os.popen(), and get the same result as _jsonnet.evaluate_file()

@sbarzowski
Copy link
Collaborator

Thanks for reporting and sorry for the inconvenience.

This looks like either:

  • a difference in how CWD is handled.
  • a consequence of some path being normalized as a Windows path internally (with \ instead of /).

This part is very interesting:

I try to run jsonnet CLI in python with os.popen(), and get the same result as _jsonnet.evaluate_file()

It suggests that it's not an issue with Python bindings, but something about running it from Python environment.

We'll need to investigate more.

Can you see if you get the same results using _gojsonnet instead of jsonnet? You can just install gojsonnet package from pip and it's a drop-in replacement. The installation may require Go toolchain, though.

Can you try running it from Python from different directories and observe the results? Did all your experiments run from /MyProject/?

@VanHWZ
Copy link
Author

VanHWZ commented Dec 2, 2020

Thanks for your advice.

It is very strange that both jsonnet CLI and _jsonnet.evaluate_file() can handle the relative path now, and I haven't done anything consciously to sovle the problem. Maybe reboot makes a difference.

I will share once I know the reason of the phenomenon. And again thanks for your help.

@johnbartholomew
Copy link
Collaborator

Pretty old issue now (which apparently mysteriously resolved itself?). I'm hoping that some underlying path handling problems on Windows were resolved by #1137 (which included some path processing fixes) but it's difficult to be sure whether it solved this problem. Anyway, I'll optimistically assume this has been fixed.

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

No branches or pull requests

3 participants