Skip to content

Commit

Permalink
Chore: Cardano.Wallet.Options (#4112)
Browse files Browse the repository at this point in the history
- [x] Decouple temp directory creation from the environment variables
reading by introducing a function parameter.
- [x] Extract functions to read environment variables into a separate
package.
- [x] Extract functions to read command line options into a separate
package.
- [x] Extract functions to manage temp directories into a separate
package `temporary-extra`
- [x] Extract utility functions for tracing/logging into a separate
package `iohk-monitoring-extra`
  • Loading branch information
Unisay authored Aug 31, 2023
2 parents df0f896 + 056d558 commit d9c0b32
Show file tree
Hide file tree
Showing 32 changed files with 3,505 additions and 2,457 deletions.
4 changes: 3 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,18 @@ packages:
, lib/delta-store/
, lib/delta-table
, lib/delta-types/
, lib/iohk-monitoring-extra/
, lib/launcher/
, lib/local-cluster/
, lib/numeric/
, lib/primitive/
, lib/read
, lib/temporary-extra/
, lib/test-utils/
, lib/text-class/
, lib/wai-middleware-logging/
, lib/wallet/
, lib/wallet-benchmarks/
, lib/wallet/

-- Using RDRAND instead of /dev/urandom as an entropy source for key
-- generation is dubious. Set the flag so we use /dev/urandom by default.
Expand Down
93 changes: 38 additions & 55 deletions lib/application-extras/cardano-wallet-application-extras.cabal
Original file line number Diff line number Diff line change
@@ -1,65 +1,48 @@
cabal-version: 3.0
name: cardano-wallet-application-extras
version: 0.1.0.0
synopsis: modules to support applications for the cardano wallet
-- description:
license: Apache-2.0
license-file: LICENSE
author: HAL, Cardano Foundation
maintainer: hal@cardanofoundation.org
-- copyright:
build-type: Simple
extra-doc-files: CHANGELOG.md
-- extra-source-files:
cabal-version: 3.0
name: cardano-wallet-application-extras
version: 0.1.0.0
synopsis: modules to support applications for the cardano wallet
license: Apache-2.0
license-file: LICENSE
author: HAL, Cardano Foundation
maintainer: hal@cardanofoundation.org
build-type: Simple
extra-doc-files: CHANGELOG.md

common options
library
default-language: Haskell2010
default-extensions:
OverloadedStrings
NoImplicitPrelude
DerivingStrategies
OverloadedStrings

ghc-options:
-O2 -Wall -Wincomplete-record-updates -Wincomplete-uni-patterns
-Wunused-foralls -Wunused-foralls
-fprint-explicit-foralls -fprint-explicit-kinds -Wcompat
-Widentities -Werror=incomplete-patterns -Wredundant-constraints
-Wpartial-fields -Wtabs -fhelpful-errors
-fprint-expanded-synonyms -fwarn-unused-do-bind
-fwarn-incomplete-uni-patterns -freverse-errors
-Wunused-foralls -Wunused-foralls -fprint-explicit-foralls
-fprint-explicit-kinds -Wcompat -Widentities
-Werror=incomplete-patterns -Wredundant-constraints
-Wpartial-fields -Wtabs -fhelpful-errors -fprint-expanded-synonyms
-fwarn-unused-do-bind -fwarn-incomplete-uni-patterns
-freverse-errors

common dependencies
build-depends:
, aeson
, base ^>=4.14.3.0
, bytestring
, contra-tracer
, deepseq
, exceptions
, fmt
, iohk-monitoring
, network
, network-uri
, optparse-applicative
, random-shuffle
, safe
, streaming-commons
, text
, text
, text-class
, temporary
, time
, tracer-transformers
, transformers
, unliftio
, unliftio-core
exposed-modules:
Cardano.Wallet.Network.Ports
System.Environment.Extended

library
import: options, dependencies
exposed-modules:
Cardano.Wallet.Logging
Cardano.Wallet.Options
Cardano.Wallet.Network.Ports
build-depends: base ^>=4.14.3.0
hs-source-dirs: lib
default-language: Haskell2010
hs-source-dirs: lib
build-depends:
, base ^>=4.14.3.0
, contra-tracer ^>=0.1.0.2
, iohk-monitoring ^>=0.1.11.3
, iohk-monitoring-extra ^>=0.1
, network ^>=3.1.4.0
, network-uri ^>=2.6.4.2
, optparse-applicative ^>=0.17.1
, random-shuffle ^>=0.0.4
, safe ^>=0.3.19
, streaming-commons ^>=0.2.2.6
, temporary ^>=1.3
, text ^>=1.2.4.1
, text-class ^>=2023.7.18
, unliftio ^>=0.2.24
, unliftio-core ^>=0.2.1
137 changes: 0 additions & 137 deletions lib/application-extras/lib/Cardano/Wallet/Options.hs

This file was deleted.

37 changes: 37 additions & 0 deletions lib/application-extras/lib/System/Environment/Extended.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module System.Environment.Extended
( module Reexport
, lookupEnvNonEmpty
, isEnvSet
, envFromText
) where

import System.Environment as Reexport

import Prelude

import Control.Monad
( mfilter )
import Data.Maybe
( isJust )
import Data.Text.Class
( FromText (..), TextDecodingError )
import UnliftIO
( MonadIO (liftIO), MonadUnliftIO )

import qualified Data.Text as T

-- | Looks up an environment variable, treating variables which are defined but
-- empty the same as variables which are undefined.
lookupEnvNonEmpty :: MonadUnliftIO m => String -> m (Maybe String)
lookupEnvNonEmpty = liftIO . (mfilter (not . null) <$>) . lookupEnv

-- | Returns true iff an environment variable is defined and non-empty.
isEnvSet :: MonadUnliftIO m => String -> m Bool
isEnvSet = fmap isJust . lookupEnvNonEmpty

-- | Parses an environment variable using text-class.
envFromText
:: (MonadUnliftIO m, FromText a)
=> String
-> m (Maybe (Either TextDecodingError a))
envFromText = liftIO . fmap (fmap (fromText . T.pack)) . lookupEnv
Loading

0 comments on commit d9c0b32

Please sign in to comment.