jsonnet icon indicating copy to clipboard operation
jsonnet copied to clipboard

Relative path import in windows10

Open VanHWZ opened this issue 5 years ago • 2 comments

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()

VanHWZ avatar Nov 30 '20 07:11 VanHWZ

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/?

sbarzowski avatar Nov 30 '20 13:11 sbarzowski

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.

VanHWZ avatar Dec 02 '20 02:12 VanHWZ