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

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

Open
curusarn opened this issue Feb 24, 2022 · 5 comments
Open

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

curusarn opened this issue Feb 24, 2022 · 5 comments
Labels
component/jsonnet Everything regarding the jsonnet language kind/bug Something isn't working

Comments

@curusarn
Copy link
Contributor

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

@curusarn curusarn changed the title Import matches files that don't match the specified path Import finds files that don't match the specified path Feb 24, 2022
@Duologic
Copy link
Member

This is a peculiar edge case, for sure.

I also get a result with Jsonnet when doing this:

➜ jsonnet -J a.jsonnet main.jsonnet
{
   "import": {
      "x": "this should not work imho"
   },
   "relative_import": {
      "x": "this should not work imho"
   }
}

Not sure if bug or feature. 🤔

@curusarn
Copy link
Contributor Author

Some extra observations:

  • I have put a.jsonnet into "tanka root" just for this example. When I discovered the issue the file was nested quite deep in the directory structure. So this issue does not seem to be just "tanka root is added to jsonnetpath"
  • Adding more ../ into the import path causes the import to fail as expected.

Ad. "your example how to replicate this with just jsonnet": It's definitely surprising to me that "jsonnetpath" is used even for relative imports that start with ./.

@stale
Copy link

stale bot commented Mar 30, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Mar 30, 2022
@curusarn
Copy link
Contributor Author

not stale

@stale stale bot removed the stale label Apr 11, 2022
@Elfo404 Elfo404 added this to Tanka May 27, 2024
@github-project-automation github-project-automation bot moved this to Triage in Tanka May 27, 2024
@zerok
Copy link
Contributor

zerok commented May 28, 2024

Can still reproduce this with v0.26.0.

@zerok zerok moved this from Triage to Backlog in Tanka May 28, 2024
@zerok zerok added kind/bug Something isn't working component/jsonnet Everything regarding the jsonnet language labels May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/jsonnet Everything regarding the jsonnet language kind/bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

3 participants