parochial 0.1.0.0 → 0.2.0.0
raw patch · 4 files changed
+62/−21 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Parochial.Options: defaultTarget :: Maybe FilePath -> Target
- Parochial.Options: getCurrentProject :: Maybe Text -> IO Text
Files
- CHANGELOG +8/−0
- README.md +7/−10
- parochial.cabal +3/−1
- src/Parochial/Options.hs +44/−10
CHANGELOG view
@@ -1,3 +1,11 @@+parochial (0.2.0.0) stable; urgency=medium++ * Remove any leading dots on the project directory (eg .xmonad → xmonad)+ * Be cleverer about where to put the target directory. See+ https://gitlab.com/filterfish/parochial/-/issues/1 for more details.++ -- Richard Heycock <rgh@filterfish.org> Sun, 03 Jan 2021 15:07:01 +1100+ parochial (0.1.0.0) stable; urgency=medium * Initial release.
README.md view
@@ -11,10 +11,10 @@ The whole point behind Parochial is to group the documentation on a project by project basis. For the html documentation it simply builds a symlink farm to the installed documentation in `$HOME/.cabal/...` (you will need to set the `-haddock` ghc option or-set it in `$HOME/.cabal.broken/config` to ensure the documentation is built) in-a directory named after the current project. For the hoogle database it does much the-same but instead of building a symlink farm it builds a hoogle database, again named-after the project.+set it in `$HOME/.cabal/config` to ensure the documentation is built) to a directory+named after the current project in `$XDG_DATA_DIR/parochial`. For the hoogle database it+does much the same but instead of building a symlink farm it builds a hoogle database,+again named after the project. # Benefits@@ -38,7 +38,7 @@ * Only works for Simple distributions. * Only tested with nix-style local builds. * Only works for projects that build a binary. You can work around this by specifying- the state file with the --state command line option.+ the state file with the `--state` option. * It's tied to a specific hoogle version so if the docs in `$HOME/.cabal/...` were built with a different version parochial will fail with a version mismatch error. * It's tied to a specific version of cabal. I _think_@@ -46,7 +46,7 @@ I need to look into it more. * If you want to access the hoogle database from a browser you will need to run `hoogle server` manually. This is probably fine if you mainly work on one project but would- become annoying fairly quickly. The hoogle hrefs are file:///\<local/path\> which most+ become annoying fairly quickly. The hoogle hrefs are `file:///</local/path>` which most browsers will refuse to render. * I'm sure there are others as well! @@ -129,7 +129,7 @@ You can specify the database on the command line, like so: ```bash-hoogle --database=/srv/parochial/parochial.hoo Functor+hoogle --database=/$XDG_DATA_DIR/parochial/parochial.hoo Functor ``` or write a simple wrapper script that infers the name of the database from the CWD or@@ -138,9 +138,6 @@ # TODO -* Don't hardcode `/srv/parochial` as the default place to put the documentation (this- works for me and you can override it with the --target option but even so it's really- me being very lazy!). * Work out a better way of locating the `setup-config` parent directory. I basically recurse the dist directory searching for `setup-config` which works but is pretty simplistic. I would have thought `Cabal` would have a way of doing this but I can't
parochial.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.2 name: parochial-version: 0.1.0.0+version: 0.2.0.0 synopsis: Help Manage project specific documentation description: Parochial helps manage local documentation by creating an index of@@ -35,6 +35,7 @@ ghc-options: -Wall -Wredundant-constraints -Wincomplete-uni-patterns -Wwarn=deprecations -fhide-source-paths+ -fwrite-ide-info -hiedir=.hie build-depends: base == 4.* , protolude == 0.*@@ -71,6 +72,7 @@ ghc-options: -Wall -Wredundant-constraints -Wincomplete-uni-patterns -Wwarn=deprecations -fhide-source-paths+ -fwrite-ide-info -hiedir=.hie build-depends: base == 4.* , protolude == 0.*
src/Parochial/Options.hs view
@@ -7,8 +7,6 @@ module Parochial.Options ( Config(..)- , getCurrentProject- , defaultTarget , getAndMkTargetPath , getState , parseCmdOptions@@ -16,6 +14,8 @@ import Protolude hiding (state) +import qualified Data.Text as T+ import Distribution.Simple.Flag import Distribution.Simple.Utils hiding (findFile) import Distribution.Simple.Configure@@ -55,25 +55,37 @@ defaultDistDir :: FilePath defaultDistDir = "dist-newstyle" + getCurrentProject :: Maybe Text -> IO Text-getCurrentProject = maybe (toS . takeBaseName <$> getCurrentDirectory) pure+getCurrentProject = maybe (unhide . toS . takeFileName <$> getCurrentDirectory) pure --- This is me being laxy.--- FIXME put this in home somewhere.-defaultTarget :: Maybe FilePath -> Target-defaultTarget = fromMaybe "/srv/parochial"+unhide :: Text -> Text+unhide = T.dropWhile ('.' ==) +targetBaseName :: FilePath+targetBaseName = "parochial"+++defaultPath :: Target+defaultPath = "/srv" </> targetBaseName+++-- | What the target directory should be. This checks the --target option and if set uses+-- is otherwise it uses @bestTarget@ to work out what to do.+defaultTarget :: Maybe FilePath -> IO Target+defaultTarget = maybe bestTarget pure++ getAndMkTargetPath :: Maybe Text -> Maybe FilePath -> IO Target getAndMkTargetPath p t = getTarget >>= mkTargetPath where- getTarget = (defaultTarget t </>) <$> (toS <$> getCurrentProject p)+ getTarget = (</>) <$> defaultTarget t <*> (toS <$> getCurrentProject p) mkTargetPath p' = createDirectoryIfMissing True p' >> pure p' --- | Takes the value from either the --state option or tries to find the setup-config--- itself.+-- | Take the value from either the --state option or find the setup-config itself. getState :: Maybe FilePath -> IO FilePath getState = maybe findSetupConfig pure @@ -95,3 +107,25 @@ parseCmdOptions :: MonadIO m => m (Config Unwrapped) parseCmdOptions = unwrapRecord "Generate project specific haddocks"+++-- | Check if defaultTarget exists and if not check that the parent directory is writable.+-- If the parent directory is writable then create it otherwise use $HOME/.parochial.+-- I'm not sure if this is the best place but I'm not sure where to put it! $HOME/.local/srv+-- would be best but this isn't covered by any standard I know off and therefore really+-- confusing to everyone else. <general heavy sigh>+bestTarget :: IO Target+bestTarget = doesDefaultTargetExist >>= boolWithDef (isParentWritable >>= boolWithDef homeTarget)+ where+ doesDefaultTargetExist = doesDirectoryExist defaultPath+ isParentWritable = writable <$> getPermissions (takeDirectory defaultPath)+++-- | If the second argument is True then return the @defaultPath@ otherwise evaluate the+-- second argument.+boolWithDef :: Applicative f => f Target -> Bool -> f Target+boolWithDef = flip bool (pure defaultPath)+++homeTarget :: IO Target+homeTarget = getXdgDirectory XdgData targetBaseName