Skip to content

Commit

Permalink
Update fourmolu (#194)
Browse files Browse the repository at this point in the history
* Update Fourmolu

* Cabal freeze
  • Loading branch information
tchoutri authored Sep 10, 2022
1 parent 25b2674 commit 5c6a322
Show file tree
Hide file tree
Showing 30 changed files with 330 additions and 324 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/checkout@v2

- uses: fourmolu/fourmolu-action@v3
- uses: fourmolu/fourmolu-action@v4
with:
pattern: |
src/**/*.hs
Expand Down
5 changes: 5 additions & 0 deletions cabal.project.freeze
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
active-repositories: hackage.haskell.org:merge
constraints: any.Cabal ==3.6.3.0,
Cabal -bundled-binary-generic,
any.Cabal-syntax ==3.8.1.0,
any.HUnit ==1.6.2.0,
any.OneTuple ==0.3.1,
Expand Down Expand Up @@ -302,6 +303,7 @@ constraints: any.Cabal ==3.6.3.0,
any.terminal-size ==0.3.3,
any.terminfo ==0.4.1.5,
any.text ==2.0.1,
text -developer +simdutf,
any.text-conversions ==0.3.1.1,
any.text-display ==0.0.3.0,
any.text-manipulate ==0.3.1.0,
Expand Down Expand Up @@ -381,6 +383,9 @@ constraints: any.Cabal ==3.6.3.0,
any.x509-store ==1.6.9,
any.x509-system ==1.6.7,
any.x509-validation ==1.6.12,
any.xml-conduit ==1.9.1.1,
any.xml-conduit-writer ==0.1.1.2,
any.xml-types ==0.3.8,
any.zlib ==0.6.3.0,
zlib -bundled-c-zlib -non-blocking-ffi -pkg-config
index-state: hackage.haskell.org 2022-08-23T14:54:28Z
3 changes: 2 additions & 1 deletion fourmolu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import-export-style: leading
record-brace-space: false # rec {x = 1} vs. rec{x = 1}
indent-wheres: true # 'false' means save space by only half-indenting the 'where' keyword
respectful: true # don't be too opinionated about newlines etc.
haddock-style: multi-line # '--' vs. '{-'
haddock-style: multi-line-compact # '--' vs. '{-'
newlines-between-decls: 1 # number of newlines between top-level declarations
fixities: []
function-arrows: leading
12 changes: 6 additions & 6 deletions src/Flora/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ data TestEnv = TestEnv
}
deriving stock (Generic)

mkPool ::
PG.ConnectInfo -> -- Database access information
Int -> -- Number of sub-pools
NominalDiffTime -> -- Allowed timeout
Int -> -- Number of connections
Eff '[IOE] (Pool PG.Connection)
mkPool
:: PG.ConnectInfo -- Database access information
-> Int -- Number of sub-pools
-> NominalDiffTime -- Allowed timeout
-> Int -- Number of connections
-> Eff '[IOE] (Pool PG.Connection)
mkPool connectInfo subPools timeout' connections =
liftIO $
Pool.newPool $
Expand Down
14 changes: 7 additions & 7 deletions src/Flora/Environment/OddJobs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import OddJobs.Types (ConcurrencyControl (..), Job, UIConfig (..))
import Flora.Environment.Config
import Flora.OddJobs.Types

makeConfig ::
JobsRunnerEnv ->
FloraConfig ->
Logger ->
Pool PG.Connection ->
(Job -> JobsRunner ()) ->
Config
makeConfig
:: JobsRunnerEnv
-> FloraConfig
-> Logger
-> Pool PG.Connection
-> (Job -> JobsRunner ())
-> Config
makeConfig runnerEnv cfg logger pool runnerContinuation =
mkConfig
(\level event -> structuredLogging cfg logger level event)
Expand Down
106 changes: 53 additions & 53 deletions src/Flora/Import/Package.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# OPTIONS_GHC -Wno-redundant-constraints #-}

{- |
{-|
Module: Flora.Import.Package
This module contains all the code to import Cabal packages into Flora. The import process
Expand Down Expand Up @@ -77,7 +77,7 @@ import Flora.Model.Requirement
import Flora.Model.User
import GHC.Stack (HasCallStack)

{- | This tuple represents the package that depends on any associated dependency/requirement.
{-| This tuple represents the package that depends on any associated dependency/requirement.
It is used in the recursive loading of Cabal files
-}
type DependentName = (Namespace, PackageName)
Expand Down Expand Up @@ -127,17 +127,17 @@ coreLibraries =
, PackageName "unix"
]

{- | Imports a Cabal file into the database by:
{-| Imports a Cabal file into the database by:
* first, reading and parsing the file using 'loadFile'
* then, extracting relevant information using 'extractPackageDataFromCabal'
* finally, inserting that data into the database
-}
importFile ::
([DB, IOE, Logging, Time] :>> es) =>
UserId ->
-- | The absolute path to the Cabal file
FilePath ->
Eff es ()
importFile
:: ([DB, IOE, Logging, Time] :>> es)
=> UserId
-> FilePath
-- ^ The absolute path to the Cabal file
-> Eff es ()
importFile userId path = loadFile path >>= extractPackageDataFromCabal userId >>= persistImportOutput

importRelFile :: ([DB, IOE, Logging, Time] :>> es) => UserId -> FilePath -> Eff es ()
Expand All @@ -146,11 +146,11 @@ importRelFile user dir = do
importFile user workdir

-- | Loads and parses a Cabal file
loadFile ::
([DB, IOE, Logging, Time] :>> es) =>
-- | The absolute path to the Cabal file
FilePath ->
Eff es GenericPackageDescription
loadFile
:: ([DB, IOE, Logging, Time] :>> es)
=> FilePath
-- ^ The absolute path to the Cabal file
-> Eff es GenericPackageDescription
loadFile path = do
exists <- liftIO $ System.doesFileExist path
unless exists $
Expand All @@ -160,14 +160,14 @@ loadFile path = do
content <- liftIO $ BS.readFile path
parseString parseGenericPackageDescription path content

parseString ::
(HasCallStack, [Logging, Time] :>> es) =>
-- | File contents to final value parser
(BS.ByteString -> ParseResult a) ->
-- | File name
String ->
BS.ByteString ->
Eff es a
parseString
:: (HasCallStack, [Logging, Time] :>> es)
=> (BS.ByteString -> ParseResult a)
-- ^ File contents to final value parser
-> String
-- ^ File name
-> BS.ByteString
-> Eff es a
parseString parser name bs = do
let (_warnings, result) = runParseResult (parser bs)
case result of
Expand All @@ -179,7 +179,7 @@ parseString parser name bs = do
loadAndExtractCabalFile :: ([DB, IOE, Logging, Time] :>> es) => UserId -> FilePath -> Eff es ImportOutput
loadAndExtractCabalFile userId filePath = loadFile filePath >>= extractPackageDataFromCabal userId

{- | Persists an 'ImportOutput' to the database. An 'ImportOutput' can be obtained
{-| Persists an 'ImportOutput' to the database. An 'ImportOutput' can be obtained
by extracting relevant information from a Cabal file using 'extractPackageDataFromCabal'
-}
persistImportOutput :: [DB, IOE] :>> es => ImportOutput -> Eff es ()
Expand All @@ -206,7 +206,7 @@ persistImportOutput (ImportOutput package categories release components) = do
Update.upsertPackage (dep.package)
Update.upsertRequirement (dep.requirement)

{- | Transforms a 'GenericPackageDescription' from Cabal into an 'ImportOutput'
{-| Transforms a 'GenericPackageDescription' from Cabal into an 'ImportOutput'
that can later be inserted into the database. This function produces stable, deterministic ids,
so it should be possible to extract and insert a single package many times in a row.
-}
Expand Down Expand Up @@ -330,16 +330,16 @@ extractBenchmark =
(^. #benchmarkName % to unUnqualComponentName % to T.pack)
(^. #benchmarkBuildInfo % #targetBuildDepends)

{- | Traverses the provided 'CondTree' and applies the given 'ComponentExtractor'
{-| Traverses the provided 'CondTree' and applies the given 'ComponentExtractor'
to every node, returning a list of 'ImportComponent'
-}
extractCondTree ::
(Package -> Release -> Maybe UnqualComponentName -> Maybe (Condition ConfVar) -> component -> ImportComponent) ->
Package ->
Release ->
Maybe UnqualComponentName ->
CondTree ConfVar [Dependency] component ->
[ImportComponent]
extractCondTree
:: (Package -> Release -> Maybe UnqualComponentName -> Maybe (Condition ConfVar) -> component -> ImportComponent)
-> Package
-> Release
-> Maybe UnqualComponentName
-> CondTree ConfVar [Dependency] component
-> [ImportComponent]
extractCondTree extractor package release defaultComponentName = go Nothing
where
go cond tree =
Expand All @@ -351,33 +351,33 @@ extractCondTree extractor package release defaultComponentName = go Nothing
condIfFalseComponents = maybe [] (go (Just . CNot $ condBranchCondition)) condBranchIfFalse
in condIfTrueComponents <> condIfFalseComponents

{- | Cabal often models conditional components as a list of 'CondTree' associated with an 'UnqualComponentName'.
{-| Cabal often models conditional components as a list of 'CondTree' associated with an 'UnqualComponentName'.
This function builds upon 'extractCondTree' to make it easier to extract fields such as 'condExecutables', 'condTestSuites' etc.
from a 'GenericPackageDescription'
-}
extractCondTrees ::
(Package -> Release -> Maybe UnqualComponentName -> Maybe (Condition ConfVar) -> component -> ImportComponent) ->
Package ->
Release ->
[(UnqualComponentName, CondTree ConfVar [Dependency] component)] ->
[ImportComponent]
extractCondTrees
:: (Package -> Release -> Maybe UnqualComponentName -> Maybe (Condition ConfVar) -> component -> ImportComponent)
-> Package
-> Release
-> [(UnqualComponentName, CondTree ConfVar [Dependency] component)]
-> [ImportComponent]
extractCondTrees extractor package release trees =
trees >>= \case (name, tree) -> extractCondTree extractor package release (Just name) tree

genericComponentExtractor ::
forall component.
() =>
ComponentType ->
-- | Extract name from component
(component -> Text) ->
-- | Extract dependencies
(component -> [Dependency]) ->
Package ->
Release ->
Maybe UnqualComponentName ->
Maybe (Condition ConfVar) ->
component ->
(PackageComponent, [ImportDependency])
genericComponentExtractor
:: forall component
. ()
=> ComponentType
-> (component -> Text)
-- ^ Extract name from component
-> (component -> [Dependency])
-- ^ Extract dependencies
-> Package
-> Release
-> Maybe UnqualComponentName
-> Maybe (Condition ConfVar)
-> component
-> (PackageComponent, [ImportDependency])
genericComponentExtractor
componentType
getName
Expand Down
10 changes: 5 additions & 5 deletions src/Flora/Import/Package/Bulk.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ importAllFilesInDirectory appLogger user dir = do
traverse_ persistImportOutput chunk
liftIO . putStrLn $ "✅ Processed " <> show newCount <> " new cabal files"

{- | Finds all cabal files in the provided directory recursively
{-| Finds all cabal files in the provided directory recursively
Hits are written to the output channel as they are found, so it should be possible to process
large amounts of Cabal files efficiently
-}
findAllCabalFilesInDirectory ::
IOE :> es =>
FilePath ->
Stream (Of FilePath) (Eff es) ()
findAllCabalFilesInDirectory
:: IOE :> es
=> FilePath
-> Stream (Of FilePath) (Eff es) ()
findAllCabalFilesInDirectory workdir = do
liftIO . putStrLn $ "🔎 Searching cabal files in " <> workdir
liftIO $ System.createDirectoryIfMissing True workdir
Expand Down
20 changes: 10 additions & 10 deletions src/Flora/Model/Category/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ data PackageCategory = PackageCategory
mkCategoryId :: IO CategoryId
mkCategoryId = CategoryId <$> UUID.nextRandom

mkCategory ::
-- | Id of the category in the database
CategoryId ->
-- | Name
Text ->
-- | Optional slug, can be inferred from the name
Maybe Text ->
-- | Synopsis
Text ->
Category
mkCategory
:: CategoryId
-- ^ Id of the category in the database
-> Text
-- ^ Name
-> Maybe Text
-- ^ Optional slug, can be inferred from the name
-> Text
-- ^ Synopsis
-> Category
mkCategory categoryId name Nothing synopsis =
mkCategory categoryId name (Just $ slugify name) synopsis
mkCategory categoryId name (Just slug) synopsis =
Expand Down
Loading

0 comments on commit 5c6a322

Please sign in to comment.