You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot run a script using cabal run which depends on a local package with cabal-install 3.8 #8562
I'd like to run the following script with cabal v2-run:
#!/usr/bin/env cabal
{- cabal:build-depends: base , my-lib-}importqualifiedMyLib
main =pure()
The command cabal run scripts/MyScript.hs with cabal-install 3.6.2.0 works as expected. However, with cabal=install 3.8.1.0 I get an error like this:
Error: cabal: Could not resolve dependencies:
[__0] trying: fake-package-0 (user goal)
[__1] unknown package: my-lib (dependency of fake-package)
[__1] fail (backjumping, conflict set: fake-package, my-lib)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: fake-package, my-lib
changed the title [-]Cannot run a script using `cabal run` which depends on a local package[/-][+]Cannot run a script using `cabal run` which depends on a local package with cabal-install 3.8[/+]on Oct 30, 2022
@bacchanalia if you don't have time to take a look, would you be able to orient me so I can see what's going on? I.e. which Cabal module is responsible for determining if local packages are in-scope?
Unfortunately, all commits from #7851 were squashed, so I can't use git-bisect to pinpoint where exactly is the regression
I understand the desire to get back the feature that suddenly disappeared. But when I think about it in isolation of cabal history, it feels to me that scripts are meant to be self contained, and I consider them using a cabal.project a bug rather than a feature. Scripts support (a part of) cabal.project fields inside themselves not for nothing: for me, it's a clear indication that you're not supposed to have an external cabal.project.
Overall, this ticket sounds to me like a feature request to extend (back) abilities of scripts beyond what they are meant to be. It's a fine request, of course, but if not for the history, I'd probably prefer this ability to be controlled by a flag, which, by default, would ignore nearby project files. But then, there's "if not for the history bit", so perhaps it should be the other way around.
Another thought: if you really need a setup sophisticated enough to reach beyond basic project file capabilities supported in the script header, then you might as well bite the bullet and turn your code into a proper package. Sometimes, people dislike creating .cabal files, but with cabal init this is very-very easy. Maybe you'd want to give it a try while waiting for this feature request to be acted upon.
Reacted by Francesco Gazzetta and Michael Peyton Jones
I agree with @ulysses4ever. You could add a cabal.project to your project, with something like packages: my-lib.cabal scripts/scripts.cabal, and have a scripts package under the scripts directory with one executable per script. then you can cabal run scripts:myscript.
I think cabal scripts are mostly useful outside of projects
In this case, I think it would be useful to specify specific versions/revisions of script dependencies (i.e., versions not available on Hackage but only on Gitlab or GitHub, or somewhere else). Is this possible in a cabal script?
agree with @ulysses4ever. You could add a cabal.project to your project, with something like packages: my-lib.cabal scripts/scripts.cabal, and have a scripts package under the scripts directory with one executable per script. then you can cabal run scripts:myscript.
I think cabal scripts are mostly useful outside of projects
Thank you @fgaz , that's a great suggestion which works well. I'm satisfied.
@dschrempf see #8024. packages should work as long as you provide absolute paths, and it looks like source-repository-package doesn't work but I think it should.
Activity
[-]Cannot run a script using `cabal run` which depends on a local package[/-][+]Cannot run a script using `cabal run` which depends on a local package with cabal-install 3.8[/+]gbaz commentedon Oct 30, 2022
I suspect that the regression is likely due to refactors induced by #7851
ulysses4ever commentedon Oct 30, 2022
Yes, let’s page in @bacchanalia.
bacchanalia commentedon Oct 31, 2022
I'll try to take a look at it next week.
dschrempf commentedon Nov 17, 2022
I also have this problem. I tried adding a
cabal.projectfile referencing the local package (usingpackages: ..) to no avail.LaurentRDC commentedon Nov 26, 2022
@bacchanalia if you don't have time to take a look, would you be able to orient me so I can see what's going on? I.e. which Cabal module is responsible for determining if local packages are in-scope?
Unfortunately, all commits from #7851 were squashed, so I can't use git-bisect to pinpoint where exactly is the regression
Mikolaj commentedon Nov 29, 2022
@LaurentRDC: the commits seem preserved in the PR, so presumably also on the bacchanalia:master branch. Is it any help?
ulysses4ever commentedon Nov 29, 2022
I understand the desire to get back the feature that suddenly disappeared. But when I think about it in isolation of cabal history, it feels to me that scripts are meant to be self contained, and I consider them using a cabal.project a bug rather than a feature. Scripts support (a part of) cabal.project fields inside themselves not for nothing: for me, it's a clear indication that you're not supposed to have an external cabal.project.
Overall, this ticket sounds to me like a feature request to extend (back) abilities of scripts beyond what they are meant to be. It's a fine request, of course, but if not for the history, I'd probably prefer this ability to be controlled by a flag, which, by default, would ignore nearby project files. But then, there's "if not for the history bit", so perhaps it should be the other way around.
Another thought: if you really need a setup sophisticated enough to reach beyond basic project file capabilities supported in the script header, then you might as well bite the bullet and turn your code into a proper package. Sometimes, people dislike creating .cabal files, but with
cabal initthis is very-very easy. Maybe you'd want to give it a try while waiting for this feature request to be acted upon.fgaz commentedon Nov 29, 2022
I agree with @ulysses4ever. You could add a cabal.project to your project, with something like
packages: my-lib.cabal scripts/scripts.cabal, and have ascriptspackage under thescriptsdirectory with one executable per script. then you cancabal run scripts:myscript.I think cabal scripts are mostly useful outside of projects
dschrempf commentedon Nov 29, 2022
In this case, I think it would be useful to specify specific versions/revisions of script dependencies (i.e., versions not available on Hackage but only on Gitlab or GitHub, or somewhere else). Is this possible in a cabal script?
LaurentRDC commentedon Dec 1, 2022
Thank you @fgaz , that's a great suggestion which works well. I'm satisfied.
fgaz commentedon Dec 1, 2022
@dschrempf see #8024.
packagesshould work as long as you provide absolute paths, and it looks likesource-repository-packagedoesn't work but I think it should.ulysses4ever commentedon Dec 1, 2022
So, is resolution here: won't fix because doesn't align with the idea of scripts? It may still be a reasonable feature request...
Remove `--project-file` flag from build script
Bump dependencies and support GHC 9.6