Skip to content

Commit

Permalink
Merge pull request #5299 from unisonweb/cp/kill-config
Browse files Browse the repository at this point in the history
Kill Configurator
  • Loading branch information
aryairani authored Aug 26, 2024
2 parents e9ca76f + 2e71dff commit 6299fc3
Show file tree
Hide file tree
Showing 17 changed files with 215 additions and 325 deletions.
1 change: 0 additions & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ These are listed in alphabetical order.
| [comonad-5.0.6](https://hackage.haskell.org/package/comonad-5.0.6) | [BSD3](https://hackage.haskell.org/package/comonad-5.0.6/src/LICENSE) |
| [concurrent-supply-0.1.8](https://hackage.haskell.org/package/concurrent-supply-0.1.8) | [BSD3](https://hackage.haskell.org/package/concurrent-supply-0.1.8/src/LICENSE) |
| [conduit-1.3.2](https://hackage.haskell.org/package/conduit-1.3.2) | [MIT](https://hackage.haskell.org/package/conduit-1.3.2/src/LICENSE) |
| [configurator-0.3.0.0](https://hackage.haskell.org/package/configurator-0.3.0.0) | [BSD3](https://hackage.haskell.org/package/configurator-0.3.0.0/src/LICENSE) |
| [containers-0.6.2.1](https://hackage.haskell.org/package/containers-0.6.2.1) | [BSD3](https://hackage.haskell.org/package/containers-0.6.2.1/src/LICENSE) |
| [contravariant-1.5.2](https://hackage.haskell.org/package/contravariant-1.5.2) | [BSD3](https://hackage.haskell.org/package/contravariant-1.5.2/src/LICENSE) |
| [cryptohash-md5-0.11.100.1](https://hackage.haskell.org/package/cryptohash-md5-0.11.100.1) | [BSD3](https://hackage.haskell.org/package/cryptohash-md5-0.11.100.1/src/LICENSE) |
Expand Down
5 changes: 0 additions & 5 deletions contrib/cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ packages:
unison-syntax
yaks/easytest

source-repository-package
type: git
location: https://github.com/unisonweb/configurator.git
tag: e47e9e9fe1f576f8c835183b9def52d73c01327a

source-repository-package
type: git
location: https://github.com/unisonweb/haskeline.git
Expand Down
1 change: 0 additions & 1 deletion nix/unison-project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ in
}
];
branchMap = {
"https://github.com/unisonweb/configurator.git"."e47e9e9fe1f576f8c835183b9def52d73c01327a" = "unison";
"https://github.com/unisonweb/shellmet.git"."2fd348592c8f51bb4c0ca6ba4bc8e38668913746" = "topic/avoid-callCommand";
};
}
1 change: 0 additions & 1 deletion parser-typechecker/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ dependencies:
- cereal
- clock
- concurrent-output
- configurator
- containers >= 0.6.3
- cryptonite
- data-default
Expand Down
2 changes: 0 additions & 2 deletions parser-typechecker/unison-parser-typechecker.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ library
, cereal
, clock
, concurrent-output
, configurator
, containers >=0.6.3
, crypton-x509
, crypton-x509-store
Expand Down Expand Up @@ -437,7 +436,6 @@ test-suite parser-typechecker-tests
, clock
, code-page
, concurrent-output
, configurator
, containers >=0.6.3
, crypton-x509
, crypton-x509-store
Expand Down
3 changes: 0 additions & 3 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ packages:
resolver: lts-22.26

extra-deps:
# broken version in snapshot
- github: unisonweb/configurator
commit: e47e9e9fe1f576f8c835183b9def52d73c01327a
# This custom Haskeline alters ANSI rendering on Windows.
# If changing the haskeline dependency, please ensure color renders properly in a
# Windows terminal.
Expand Down
11 changes: 0 additions & 11 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@
# https://docs.haskellstack.org/en/stable/lock_files

packages:
- completed:
name: configurator
pantry-tree:
sha256: 90547cd983fd15ebdc803e057d3ef8735fe93a75e29a00f8a74eadc13ee0f6e9
size: 955
sha256: d4fd87fb7bfc5d8e9fbc3e4ee7302c6b1500cdc00fdb9b659d0f4849b6ebe2d5
size: 15989
url: https://github.com/unisonweb/configurator/archive/e47e9e9fe1f576f8c835183b9def52d73c01327a.tar.gz
version: 0.3.0.0
original:
url: https://github.com/unisonweb/configurator/archive/e47e9e9fe1f576f8c835183b9def52d73c01327a.tar.gz
- completed:
name: haskeline
pantry-tree:
Expand Down
1 change: 0 additions & 1 deletion unison-cli/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ dependencies:
- co-log-core
- code-page
- concurrent-output
- configurator
- containers >= 0.6.3
- cryptonite
- directory
Expand Down
2 changes: 0 additions & 2 deletions unison-cli/src/Unison/Cli/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import Control.Lens
import Control.Monad.Reader (MonadReader (..))
import Control.Monad.State.Strict (MonadState)
import Control.Monad.State.Strict qualified as State
import Data.Configurator.Types qualified as Configurator
import Data.List.NonEmpty qualified as List (NonEmpty)
import Data.List.NonEmpty qualified as List.NonEmpty
import Data.List.NonEmpty qualified as NonEmpty
Expand Down Expand Up @@ -160,7 +159,6 @@ type SourceName = Text
data Env = Env
{ authHTTPClient :: AuthenticatedHttpClient,
codebase :: Codebase IO Symbol Ann,
config :: Configurator.Config,
credentialManager :: CredentialManager,
-- | Generate a unique name.
generateUniqueName :: IO Parser.UniqueName,
Expand Down
16 changes: 1 addition & 15 deletions unison-cli/src/Unison/Cli/MonadUtils.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
-- | This module contains miscellaneous helper utils for rote actions in the Cli monad, like resolving a relative path
-- to an absolute path, per the current path.
module Unison.Cli.MonadUtils
( -- * @.unisonConfig@ things
getConfig,

-- * Paths
( -- * Paths
getCurrentPath,
getCurrentProjectName,
getCurrentProjectBranchName,
Expand Down Expand Up @@ -88,8 +85,6 @@ where
import Control.Lens
import Control.Monad.Reader (ask)
import Control.Monad.State
import Data.Configurator qualified as Configurator
import Data.Configurator.Types qualified as Configurator
import Data.Foldable
import Data.Set qualified as Set
import U.Codebase.Branch qualified as V2 (Branch)
Expand Down Expand Up @@ -138,15 +133,6 @@ import Unison.UnisonFile.Names qualified as UFN
import Unison.Util.Set qualified as Set
import Unison.Var qualified as Var

------------------------------------------------------------------------------------------------------------------------
-- .unisonConfig things

-- | Lookup a config value by key.
getConfig :: (Configurator.Configured a) => Text -> Cli (Maybe a)
getConfig key = do
Cli.Env {config} <- ask
liftIO (Configurator.lookup config key)

------------------------------------------------------------------------------------------------------------------------
-- Getting paths, path resolution, etc.

Expand Down
28 changes: 4 additions & 24 deletions unison-cli/src/Unison/Codebase/Transcript/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import Crypto.Random qualified as Random
import Data.Aeson qualified as Aeson
import Data.Aeson.Encode.Pretty qualified as Aeson
import Data.ByteString.Lazy.Char8 qualified as BL
import Data.Configurator qualified as Configurator
import Data.Configurator.Types (Config)
import Data.IORef
import Data.List (isSubsequenceOf)
import Data.List.NonEmpty qualified as NonEmpty
Expand All @@ -24,9 +22,7 @@ import Data.These (These (..))
import Data.UUID.V4 qualified as UUID
import Network.HTTP.Client qualified as HTTP
import System.Environment (lookupEnv)
import System.Exit (die)
import System.IO qualified as IO
import System.IO.Error (catchIOError)
import Text.Megaparsec qualified as P
import U.Codebase.Sqlite.DbId qualified as Db
import U.Codebase.Sqlite.Project (Project (..))
Expand Down Expand Up @@ -96,16 +92,15 @@ withRunner ::
Verbosity ->
UCMVersion ->
FilePath ->
Maybe FilePath ->
(Runner -> m r) ->
m r
withRunner isTest verbosity ucmVersion nrtp configFile action = do
withRuntimes nrtp \runtime sbRuntime nRuntime -> withConfig \config -> do
withRunner isTest verbosity ucmVersion nrtp action = do
withRuntimes nrtp \runtime sbRuntime nRuntime -> do
action \transcriptName transcriptSrc (codebaseDir, codebase) -> do
Server.startServer (Backend.BackendEnv {Backend.useNamesIndex = False}) Server.defaultCodebaseServerOpts runtime codebase \baseUrl -> do
let parsed = Transcript.stanzas transcriptName transcriptSrc
result <- for parsed \stanzas -> do
liftIO $ run isTest verbosity codebaseDir stanzas codebase runtime sbRuntime nRuntime config ucmVersion (tShow baseUrl)
liftIO $ run isTest verbosity codebaseDir stanzas codebase runtime sbRuntime nRuntime ucmVersion (tShow baseUrl)
pure . join $ first ParseError result
where
withRuntimes ::
Expand All @@ -115,19 +110,6 @@ withRunner isTest verbosity ucmVersion nrtp configFile action = do
RTI.withRuntime True RTI.Persistent ucmVersion \sbRuntime -> do
action runtime sbRuntime
=<< liftIO (RTI.startNativeRuntime ucmVersion nrtp)
withConfig :: forall a. ((Maybe Config -> m a) -> m a)
withConfig action = do
case configFile of
Nothing -> action Nothing
Just configFilePath -> do
let loadConfig = liftIO do
catchIOError
(watchConfig configFilePath)
\_ -> die "Your .unisonConfig could not be loaded. Check that it's correct!"
UnliftIO.bracket
loadConfig
(\(_config, cancelConfig) -> liftIO cancelConfig)
(\(config, _cancelConfig) -> action (Just config))

run ::
-- | Whether to treat this transcript run as a transcript test, which will try to make output deterministic
Expand All @@ -139,11 +121,10 @@ run ::
Runtime.Runtime Symbol ->
Runtime.Runtime Symbol ->
Runtime.Runtime Symbol ->
Maybe Config ->
UCMVersion ->
Text ->
IO (Either Error Text)
run isTest verbosity dir stanzas codebase runtime sbRuntime nRuntime config ucmVersion baseURL = UnliftIO.try do
run isTest verbosity dir stanzas codebase runtime sbRuntime nRuntime ucmVersion baseURL = UnliftIO.try do
httpManager <- HTTP.newManager HTTP.defaultManagerSettings
(initialPP, emptyCausalHashId) <- Codebase.runTransaction codebase do
(_, emptyCausalHashId) <- Codebase.emptyCausalHash
Expand Down Expand Up @@ -427,7 +408,6 @@ run isTest verbosity dir stanzas codebase runtime sbRuntime nRuntime config ucmV
Cli.Env
{ authHTTPClient = authenticatedHTTPClient,
codebase,
config = fromMaybe Configurator.empty config,
credentialManager = credMan,
generateUniqueName = do
i <- atomicModifyIORef' seedRef \i -> let !i' = i + 1 in (i', i)
Expand Down
15 changes: 0 additions & 15 deletions unison-cli/src/Unison/CommandLine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module Unison.CommandLine
( allow,
parseInput,
prompt,
watchConfig,
watchFileSystem,
)
where
Expand All @@ -15,9 +14,6 @@ import Control.Concurrent (forkIO, killThread)
import Control.Lens hiding (aside)
import Control.Monad.Except
import Control.Monad.Trans.Except
import Data.Configurator (autoConfig, autoReload)
import Data.Configurator qualified as Config
import Data.Configurator.Types (Config, Worth (..))
import Data.List (isPrefixOf, isSuffixOf)
import Data.Map qualified as Map
import Data.Semialign qualified as Align
Expand Down Expand Up @@ -50,23 +46,12 @@ import Unison.Util.TQueue qualified as Q
import UnliftIO.STM
import Prelude hiding (readFile, writeFile)

disableWatchConfig :: Bool
disableWatchConfig = False

allow :: FilePath -> Bool
allow p =
-- ignore Emacs .# prefixed files, see https://github.com/unisonweb/unison/issues/457
not (".#" `isPrefixOf` takeFileName p)
&& (isSuffixOf ".u" p || isSuffixOf ".uu" p)

watchConfig :: FilePath -> IO (Config, IO ())
watchConfig path =
if disableWatchConfig
then pure (Config.empty, pure ())
else do
(config, t) <- autoReload autoConfig [Optional path]
pure (config, killThread t)

watchFileSystem :: Q.TQueue Event -> FilePath -> IO (IO ())
watchFileSystem q dir = do
(cancel, watcher) <- Watch.watchDirectory dir allow
Expand Down
5 changes: 1 addition & 4 deletions unison-cli/src/Unison/CommandLine/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Control.Exception (catch, displayException, finally, mask)
import Control.Lens ((?~))
import Control.Lens.Lens
import Crypto.Random qualified as Random
import Data.Configurator.Types (Config)
import Data.IORef
import Data.List.NonEmpty qualified as NEL
import Data.List.NonEmpty qualified as NonEmpty
Expand Down Expand Up @@ -124,7 +123,6 @@ main ::
FilePath ->
Welcome.Welcome ->
PP.ProjectPathIds ->
Config ->
[Either Event Input] ->
Runtime.Runtime Symbol ->
Runtime.Runtime Symbol ->
Expand All @@ -135,7 +133,7 @@ main ::
(PP.ProjectPathIds -> IO ()) ->
ShouldWatchFiles ->
IO ()
main dir welcome ppIds config initialInputs runtime sbRuntime nRuntime codebase serverBaseUrl ucmVersion lspCheckForChanges shouldWatchFiles = Ki.scoped \scope -> do
main dir welcome ppIds initialInputs runtime sbRuntime nRuntime codebase serverBaseUrl ucmVersion lspCheckForChanges shouldWatchFiles = Ki.scoped \scope -> do
_ <- Ki.fork scope do
-- Pre-load the project root in the background so it'll be ready when a command needs it.
projectRoot <- Codebase.expectProjectBranchRoot codebase ppIds.project ppIds.branch
Expand Down Expand Up @@ -221,7 +219,6 @@ main dir welcome ppIds config initialInputs runtime sbRuntime nRuntime codebase
Cli.Env
{ authHTTPClient,
codebase,
config,
credentialManager,
loadSource = loadSourceFile,
writeSource = writeSourceFile,
Expand Down
Loading

0 comments on commit 6299fc3

Please sign in to comment.