Skip to content

Cannot import modules in .nimble during nimble install #1259

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

Open
madonuko opened this issue Aug 14, 2024 · 11 comments
Open

Cannot import modules in .nimble during nimble install #1259

madonuko opened this issue Aug 14, 2024 · 11 comments

Comments

@madonuko
Copy link

nimble install nimsutils fails with the following error:

Downloading https://github.com/FyraLabs/nimsutils using git
   Warning: The package has no tagged releases, downloading HEAD instead.
  Verifying dependencies for nimsutils@0.1.0
 Installing nimsutils@0.1.0
       Tip: 3 messages have been suppressed, use --verbose to show them.
nimble.nim(399)          packageExists

    Error:  The package inside "/home/mado/.nimble/pkgs2/nimsutils-0.1.0-3d97d4dd06c39f7943ddb0b1dd28b05136077e63" is invalid.
  Details:  Could not read package info file in /home/mado/.nimble/pkgs2/nimsutils-0.1.0-3d97d4dd06c39f7943ddb0b1dd28b05136077e63/nimsutils.nimble;
        ...   Reading as ini file failed with: 
        ...     Invalid section: .
        ...   Evaluating as NimScript file failed with: 
        ...     /home/mado/.nimble/pkgs2/nimsutils-0.1.0-3d97d4dd06c39f7943ddb0b1dd28b05136077e63/nimsutils.nimble(1, 11) Error: cannot open file: src/nimsutils
        ... printPkgInfo() failed.

However, if you run nimble inside the repository directly, it works absolutely fine.

Since I can't find any docs saying you aren't allowed to import things in the .nimble file, I feel like this should be a bug from nimble install.

@xTrayambak
Copy link
Contributor

image

The Nimble manifest for that package seems to be completely invalid. Running nimble install on it with Nimble 0.16.2 results in an error in both the cases.

@ringabout This is not reproducible.

@madonuko
Copy link
Author

madonuko commented Dec 4, 2024

Have you tried running nimble tasks?

@xTrayambak
Copy link
Contributor

image
It does seem to parse it with no issues, but it cannot evaluate it.

@madonuko
Copy link
Author

madonuko commented Dec 4, 2024

If it can parse it, and if running nimble mytask even works, then I mean… supposedly it can evaluate it?

@xTrayambak
Copy link
Contributor

No, I mean "interpretation" when I say "evaluation". It cannot execute that.

@madonuko
Copy link
Author

madonuko commented Dec 5, 2024

Sorry for my ignorance, but there a particular reason why nimble install can't import the file but in other situations you can?
The xtask thing clearly works (nimble mytask runs fine, nimble tasks can find it too, etc), I feel like the import system is broken particularly in nimble install only.

@daylinmorgan
Copy link
Contributor

here a particular reason why nimble install can't import the file but in other situations you can?

Yes, this is a combination of missing import paths and nimble install behavior.
When nimble installs a package it only copies over the srcDir so the on-disk representation in the .nimble/pkgs2 directory is like this:

nimsutils-0.1.0-e22ac7bf6b80f9650b3a2a0eb5871186c52e7a27
├── htmldocs
│   └── nimdoc.out.css
├── basedefs.nim
├── btrfmt.nim
├── common_imports.nim
├── exec.nim
├── nimblemeta.json
├── nimsutils.nim
├── nimsutils.nimble
├── time.nim
└── xtask.nim

Meaning that there is now no module at ./src/nimsutils.nim.

A possible workaround is you doing some conditional import like this in your nimble file:

when not (compiles do: import src/nimsutils):
  import ./nimsutils
else:
  import src/nimsutils

madonuko added a commit to FyraLabs/nimsutils that referenced this issue Mar 14, 2025
@madonuko
Copy link
Author

madonuko commented Mar 14, 2025

That unfortunately doesn't work (probably because Nim VM just fails on errors from compiles do:)

Update: by using:

when (compiles do: import ./nimsutils):
  import ./nimsutils
else:
  import src/nimsutils

we force the VM to check for ./nimsutils first, so there is no failure path during nimble install. This seems to work now.

@daylinmorgan
Copy link
Contributor

I would make sure to remove any versions of nimsutils from ~/.nimble first.

This works fine for me:

nimble install https://github.com/daylinmorgan/nimsutils/

What is the error?
What version of nim and nimble are you using?

@madonuko
Copy link
Author

Using latest devel (choosenim)

I have no idea why but somehow nimble install https://github.com/daylinmorgan/nimsutils/ also works (probably some random nimble caching issues)

Maybe it's not a bad idea to document this behaviour somewhere?

@daylinmorgan
Copy link
Contributor

daylinmorgan commented Mar 14, 2025

I have no idea why but somehow nimble install https://github.com/daylinmorgan/nimsutils/ also works (probably some random nimble caching issues)

Ya probably,

TBF I think the original error message indicates the problem.

But it may be good to add info to the nimble-guide about how packages are actually installed and how that relates to scrDir.

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

4 participants