commercialhaskell / commercialhaskell/stack

Local packages are not allowed when using the script command.

Open
#3,370 6 comments 0 reactions 0 assignees View on GitHub
awaiting pull request component: docs (online) component: script interpreter
Dominant language
Haskell
Stars
4.1k
Forks
850
Avg merge
10h 37m
Merged PRs (30d)
4

Description

### General summary/comments (optional)

It seems packges outside stackage are not allowed in stack scripts.

Is there any fix?

### Steps to reproduce

Execute

```haskell
#!/usr/bin/env stack
{- stack --resolver lts-9.1 script --optimize
--package turtle
--package charsetdetect
--package iconv
--package bytestring
-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
import Codec.Text.Detect (detectEncodingName)
import Codec.Text.IConv (convert)
import Turtle.Options
import qualified Data.ByteString.Lazy as BL
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.Encoding as TE
import qualified Data.Text.Lazy.IO as TIO
import Control.Monad (when, forM_)
import Data.Monoid ((<>))

data Option = Option { notest :: Bool, files :: [FilePath] }

optParser :: Parser Option
optParser = Option
<$> switch "notest" 'n' "Actually convert files"
<*> some (argPath "FILE")

desc :: String
desc = "It converts the encoding of each file's content to UTF-8, and \
\remove carriage returns."

-- processFile :: Bool -> FilePath -> IO ()
processFile notest file = do
bs <- BL.readFile file
case detectEncodingName bs of
Nothing -> echo "Encoding detection failed."
Just "UTF-8" -> echo "Character encoding is already UTF-8"
Just enc -> do
echo $ "Detected encoding : " <> enc
when notest $ do
TIO.writeFile $ T.filter (/='\r') $ TE.decodeUtf8 $
convert enc "UTF-8" bs
putStrLn "File encoding has been converted to UTF-8."

main :: IO ()
main = do
Option{..} <- options desc optParser
let process = processFile notest
putStrLn ""
forM_ files $ \file -> do
putStrLn $ file <> ":"
process file
putStrLn ""
```

### Expected

Help message is printed.

### Actual

```
$ charset.hs
Local packages are not allowed when using the script command. Packages found:
- charsetdetect-1.1.0.2
```

### Stack version

```
$ stack --version
Version 1.5.1 x86_64
```

### Method of installation

* Haskell gentoo overlay

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.