Skip to content

Import finds files that don't match the specified path #673

Open

Description

Steps to reproduce

We are creating following directory structure:

❯ tree tanka-import-bug 
tanka-import-bug
└── tanka-root
    ├── a.jsonnet
    ├── main.jsonnet
    └── tkrc.yaml

1 directory, 3 files

And these files:

❯ cat tanka-import-bug/tanka-root/main.jsonnet
{
"import": import "../a.jsonnet",
"relative_import": import "./../a.jsonnet",
}

❯ cat tanka-import-bug/tanka-root/a.jsonnet   
{ x: "this should not work imho" }

Setup steps

cd /tmp
mkdir -p tanka-import-bug/tanka-root
touch tanka-import-bug/tanka-root/tkrc.yaml
echo -e '{\n"import": import "../a.jsonnet",\n"relative_import": import "./../a.jsonnet",\n}' > tanka-import-bug/tanka-root/main.jsonnet
echo '{ x: "this should not work imho" }' > tanka-import-bug/tanka-root/a.jsonnet
cd tanka-import-bug/tanka-root

The issue

Evaluate with jsonnet for reference:

/tmp/tanka-import-bug/tanka-root
❯ jsonnet main.jsonnet
RUNTIME ERROR: couldn't open import "../a.jsonnet": no match locally or in the Jsonnet library paths.
	main.jsonnet:2:11-32	object <anonymous>
	During manifestation	

❯ jsonnet --version
Jsonnet commandline interpreter v0.17.0

You can see that the import fails as expected because the relative path should be ./a.jsonnet (or equivalent) not ./../a.jsonnet.

Evaluate with tanka:

/tmp/tanka-import-bug/tanka-root
❯ PAGER=cat tk eval main.jsonnet
{
  "import": {
    "x": "this should not work imho"
  },
  "relative_import": {
    "x": "this should not work imho"
  }
}

❯ tk --version
tk version v0.15.1

Here we see that something weird is happening when jsonnet is evaluated in tanka.
I originally thought that this is caused by paths that are added by Tanka into "jsonnetpath".
But when you look above you can see that even relative import import "./../a.jsonnet" evaluates without errors.
I assumed that the relative import starting with ./ is strictly relative to current file but that does not seem to be the case.

Let me know if anything is unclear of if you can't reproduce the issue.

Simon Let

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

Metadata

Assignees

No one assigned

    Labels

    component/jsonnetEverything regarding the jsonnet languagekind/bugSomething isn't working

    Type

    No type

    Projects

    • Status

      Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions