Skip to content

Proper subpackage cwd in stack repl #5448

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

Merged
merged 3 commits into from
Dec 3, 2020
Merged

Conversation

qrilka
Copy link
Contributor

@qrilka qrilka commented Dec 2, 2020

Note: Documentation fixes for https://docs.haskellstack.org/en/stable/ should target the "stable" branch, not master.

Please include the following checklist in your PR:

  • Any changes that could be relevant to users have been recorded in the ChangeLog.md
  • The documentation has been updated, if necessary.

Resolves #5421. Tested manually

@qrilka qrilka force-pushed the 5421-subpackage-cwd-repl branch from bfcb723 to a636e26 Compare December 2, 2020 12:18
Copy link
Contributor

@snoyberg snoyberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please merge when ready

@jneira
Copy link
Contributor

jneira commented Dec 3, 2020

Hi, many thanks for trying fix this.
Unfortunately my tests continue failing, as the subpacakge module continue having cwd at main project root using the repl:

D:\ws\haskell\stack-test>stack --version
Version 2.6.0, Git revision a636e262579753326cde8d0f38f19e137bb872a2 (dirty) (8261 commits) PRE-RELEASE x86_64 hpack-0.33.0

D:\ws\haskell\stack-test>type subpackage\src\MyLib.hs
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
module MyLib (cwd, val, val1) where
import System.Directory
import Data.Yaml (Value)
import Data.Yaml.TH (decodeFile)
import Language.Haskell.TH
import Language.Haskell.TH.Syntax

cwd :: FilePath
cwd = $$(runIO getCurrentDirectory >>= \d-> fmap TExp (lift (d :: FilePath)))


val :: Value
val = $$(do
           file <- runIO $ do
                    exist <- doesFileExist "config/value.yaml"
                    return $ if exist then "config/value.yaml"
                                      else "subpackage/config/value.yaml"
           decodeFile file :: Q (TExp Value)
        )

val1 :: Value
val1 = $$(decodeFile "config/value.yaml" :: Q (TExp Value))

D:\ws\haskell\stack-test>dir config /B
No se encuentra el archivo

D:\ws\haskell\stack-test>dir subpackage\config /B
value.yaml

D:\ws\haskell\stack-test>type app\Main.hs
module Main where

import Lib
import MyLib

main :: IO ()
main = do
    putStrLn $ cwd
    putStrLn $ show val
    putStrLn $ show val1

D:\ws\haskell\stack-test>stack run
.................
D:\ws\haskell\stack-test\subpackage
Number 2.0
Number 2.0

D:\ws\haskell\stack-test>stack repl
.............................

D:\\\\ws\haskell\stack-test\subpackage\src\MyLib.hs:24:11: error:
    • Exception when trying toto run compile-time code:
        InvalidYaml (Just (YamlException "Yaml file not found: config/value.yaml"))
      Code: decodeFile "config/value.yaml" :: Q (TExp Value)
    • In the Template Haskell splice:
        $$(decodeFile "config/value.yaml" :: Q (TExp Value))
      In the expression:
        $$(decodeFile "config/value.yaml" :: Q (TExp Value))
      In an equation for ‘val1’:
          val1 = $$(decodeFile "config/value.yaml" :: Q (TExp Value))
   |
24 | val1 = $$(decodeFile "config/value.yaml" :: Q (TExp Value))
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, one module loaded.

<no location info>: error:
    Could not load module ‘MyLib’
    It is a member of the hidden package ‘subpackage-0.1.0.0’.
    You can run ‘:set -package subpackage’ to expose it.
    (Note: this unloads all the modules in the current scope.)
Loaded GHCi configuration from C:\\TEMP\\haskell-stack-ghci\\9dd5157a\\ghci-scri
pt
*Lib>

@qrilka
Copy link
Contributor Author

qrilka commented Dec 3, 2020

@jneira have you read my comment #5421 (comment) stating

we can't have different working directories for different packages in GHCi.

?
You have even replied that adding a multi-package warning is a suitable way to resolve the situation.
Unfortunately there seem to be no other way around as e.g. https://gitlab.haskell.org/ghc/ghc/-/issues/10827 is 5 years old already and https://gitlab.haskell.org/ghc/ghc/-/wikis/Multi-Session-GHC-API lists a couple of previous GSoC projects on the topic and some still not merged MRs as well.

@jneira
Copy link
Contributor

jneira commented Dec 3, 2020

@qrilka uh, my bad, i did read what i want to and not what you wrote, sorry
I've tested that stack repl subpackage works so the pr works as intended.

Only note that the pr would not close the issue afaiu, as stack repl (and hls) still does not work. Maybe it could be marked as blocked upstream, though.

@qrilka
Copy link
Contributor Author

qrilka commented Dec 3, 2020

Yeah, a proper resolution is blocked by upstream but I need to check if there are other issues on this topic so maybe we could at least minimize duplication in the issue tracker :)
Thanks for your feedback @jneira

@qrilka
Copy link
Contributor Author

qrilka commented Dec 3, 2020

@jneira I think we could close #5421 in favor of #3310 (probably with intero removed) and add some more info into that issue, does this sound OK to you?

@jneira
Copy link
Contributor

jneira commented Dec 3, 2020

@qrilka sure!

@qrilka qrilka merged commit c234573 into master Dec 3, 2020
@mpilgrem mpilgrem deleted the 5421-subpackage-cwd-repl branch October 16, 2022 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stack repl subpackage compile time cwd is different from stack build subpackage one
3 participants