Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support AbstractFilePath #192

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
a266326
Removed .ghci file
mmhat Jun 18, 2024
23afae1
Added hie.yaml
mmhat Jun 20, 2024
ad55906
Moved sources of validity-test to own directory
mmhat Jun 18, 2024
6e9ca25
Better use of IS_WINDOWS
mmhat Jun 18, 2024
7030cb8
Renamed the Foo type class to CheckInstantiated
mmhat Jun 20, 2024
1467bd3
Testsuite test: Moved TH stuff to own modules
mmhat Jun 20, 2024
e1b88b7
Testsuite test: Preliminary work to move more tests into the Common m…
mmhat Jun 20, 2024
79f0740
Testsuite test: Moved 'dirname' tests to Common modules
mmhat Jun 20, 2024
25f480e
Testsuite test: Moved 'filename' tests to Common modules
mmhat Jun 20, 2024
fa8c390
Testsuite test: Moved 'parent' tests to Common modules
mmhat Jun 20, 2024
fe559b9
Testsuite test: Moved 'splitDrive' tests to Common modules
mmhat Jun 20, 2024
16de840
Testsuite test: Moved 'isProperPrefixOf' tests to Common modules
mmhat Jun 20, 2024
d5b1bd1
Testsuite test: Moved 'stripProperPrefix' tests to Common modules
mmhat Jun 20, 2024
0fdb2e6
Testsuite test: Moved '</>' tests to Common modules
mmhat Jun 20, 2024
532ae73
Testsuite test: Moved some utilities to Common modules
mmhat Jun 20, 2024
9ef2340
Replicated source code to OsPath namespace
mmhat Jun 18, 2024
4db62ad
Adjusted version constraints and added os-string dependency
mmhat Jun 18, 2024
b5b8833
Use platform filepaths in OsPath.Internal modules
mmhat Jun 18, 2024
7a25335
Use platform filepaths in the OsPath modules of the public API
mmhat Jun 20, 2024
c04a187
Replicated test testsuite to test-ospath testsuite
mmhat Jun 20, 2024
588b90c
Use OsPath modules in test-ospath
mmhat Jun 20, 2024
b2a0cac
Moved normalization functions to Internal modules
mmhat Jun 20, 2024
1a527de
Moved validation functions to Internal modules
mmhat Jun 20, 2024
202529e
Replicated validity-test testsuite to validity-test-ospath testsuite
mmhat Jun 20, 2024
296930f
validity-test-ospath: Different modules for different platforms
mmhat Jun 20, 2024
f48c66e
Added orphan instance for OsPath paths to validity-test-ospath
mmhat Jun 20, 2024
5200bbd
Use OsPath modules in validity-test-ospath
mmhat Jun 20, 2024
8f2ba1c
Updated Stack configuration
mmhat Jun 21, 2024
d22abd4
Updated Stack configuration again
mmhat Jun 21, 2024
06dc7e4
Applied suggestions
mmhat Jun 24, 2024
3cf6556
Better documentation for FromJSON/ToJSON instances
mmhat Jun 25, 2024
55fe3bd
Better GenValid instance for PosixPath/WindowsPath
mmhat Jun 25, 2024
3f4c450
Moved aeson instances of OsPath to OsPath.Aeson namespace
mmhat Jun 25, 2024
e73559b
Provide newtype wrappers to control the decoding/encoding in OsPath a…
mmhat Jun 25, 2024
32c140e
Added Path.Internal.{Posix,Windows}.isWindows and removed some CPP fr…
mmhat Jun 25, 2024
5a16815
Added explicit conversion functions to OsPath.Aeson modules
mmhat Jun 26, 2024
db0807f
Removed Aeson instances for OsPath
mmhat Jul 14, 2024
9de73ab
Empty `Validity PLATFORM_PATH` instance
mmhat Jul 19, 2024
f8ded6a
Some small, final changes
Jul 29, 2024
179f6ef
Updated CI, tested-with and removed some dependencies
Jul 29, 2024
e2c1ec9
Support for filepath >=1.4.100.0 && <1.5
mmhat Jul 29, 2024
b2d8b95
Fixed Cabal conditionals, stack setup and HIE configuration
mmhat Jul 29, 2024
fe1eae9
Better compat sublibrary
mmhat Jul 30, 2024
3706145
Conditional filepath dependency for main library
mmhat Jul 30, 2024
56fb8cb
Added Stack configuration for +old-os-string
mmhat Jul 30, 2024
0fb94c9
Better backwards compatibility
mmhat Aug 9, 2024
1c000ee
Updated CI: Test Stack build with os-string flag
mmhat Aug 9, 2024
c105f76
Updated CI: Better cache keys
mmhat Aug 9, 2024
383ce37
Updated CI: Better naming of stack jobs
mmhat Aug 9, 2024
9b2bbe1
Updated CI: Use actions/cache@v4
mmhat Aug 9, 2024
7e1bf06
Removed extra-deps from stack.yaml
mmhat Aug 9, 2024
36a6cdf
Applied suggestions
mmhat Aug 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,23 @@
-- PLATFORM_CHAR = PosixChar | WindowsChar
-- IS_WINDOWS = 0 | 1

{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE StandaloneDeriving #-}

{-# OPTIONS_GHC -Wno-deprecations #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module System.OsString.Compat.PLATFORM_NAME
#if MIN_VERSION_os_string(2,0,0)
( OsString.all
, OsString.any
, OsString.break
, OsString.breakEnd
, OsString.dropWhileEnd
, OsString.empty
, OsString.init
, OsString.isInfixOf
, OsString.isPrefixOf
, OsString.isSuffixOf
, OsString.length
, OsString.map
, OsString.null
, OsString.replicate
, OsString.singleton
, OsString.span
, OsString.spanEnd
, OsString.stripPrefix
, OsString.uncons
( PLATFORM_STRING(..)
, PLATFORM_CHAR(..)
, module OsString
)
#else
( System.OsString.Compat.PLATFORM_NAME.all
( PLATFORM_STRING(..)
, PLATFORM_CHAR(..)
, OsString.pstr
, System.OsString.Compat.PLATFORM_NAME.all
, System.OsString.Compat.PLATFORM_NAME.any
, System.OsString.Compat.PLATFORM_NAME.break
, System.OsString.Compat.PLATFORM_NAME.breakEnd
Expand All @@ -52,11 +43,12 @@ module System.OsString.Compat.PLATFORM_NAME
#endif
where

import Data.Data (Data)
import System.OsString.Internal.Types (PLATFORM_STRING(..), PLATFORM_CHAR(..))
import System.OsString.PLATFORM_NAME as OsString

#if !MIN_VERSION_os_string(2,0,0)
import Data.Coerce (coerce)
import System.OsString.Internal.Types (PLATFORM_STRING(..), PLATFORM_CHAR(..))

#if IS_WINDOWS
import qualified System.OsPath.Data.ByteString.Short.Word16 as BSP
Expand All @@ -65,6 +57,8 @@ import qualified System.OsPath.Data.ByteString.Short as BSP
#endif
#endif

deriving instance Data PLATFORM_STRING

#if !MIN_VERSION_os_string(2,0,0)
all :: (PLATFORM_CHAR -> Bool) -> PLATFORM_STRING -> Bool
all = coerce BSP.all
Expand Down
25 changes: 8 additions & 17 deletions path.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build-type: Simple
tested-with: GHC==9.2.8, GHC==9.4.8, GHC==9.6.6, GHC==9.8.2, GHC==9.10.1
extra-source-files: README.md
, CHANGELOG
, compat/System/OsString/Compat/Include.hs
, os-string-compat/System/OsString/Compat/Include.hs
, src/Path/Include.hs
, src/Path/Internal/Include.hs
, src/OsPath/Include.hs
Expand Down Expand Up @@ -74,21 +74,15 @@ library
, deepseq
, exceptions >= 0.4 && < 0.11
, hashable >= 1.2 && < 1.5
, path:compat
, path:os-string-compat
, text
, template-haskell
, filepath >= 1.4.100.0

if flag(old-os-string)
build-depends: filepath >= 1.4.100.0
, os-string < 2.0.0
else
build-depends: filepath >= 1.5.0.0
, os-string >= 2.0.0

library compat
library os-string-compat
mmhat marked this conversation as resolved.
Show resolved Hide resolved
import: language

hs-source-dirs: compat
hs-source-dirs: os-string-compat
visibility: private

exposed-modules: System.OsString.Compat.Posix
Expand All @@ -100,8 +94,7 @@ library compat
build-depends: filepath >= 1.4.100.0
, os-string < 2.0.0
else
build-depends: filepath >= 1.5.0.0
, os-string >= 2.0.0
build-depends: os-string >= 2.0.0

test-suite test
import: language
Expand Down Expand Up @@ -147,9 +140,8 @@ test-suite test-ospath
, exceptions
, filepath
, hspec >= 2.0 && < 3
, os-string
, path
, path:compat
, path:os-string-compat
, template-haskell

test-suite validity-test
Expand Down Expand Up @@ -189,9 +181,8 @@ test-suite validity-test-ospath
, genvalidity >= 1.0
, genvalidity-hspec >= 0.7
, hspec >= 2.0 && < 3
, os-string
, path
, path:compat
, path:os-string-compat
, validity-bytestring >=0.4.1.0

source-repository head
Expand Down
43 changes: 20 additions & 23 deletions src/OsPath/Include.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RankNTypes #-}

{-# OPTIONS_GHC -Wno-deprecations #-}

module OsPath.PLATFORM_NAME
(-- * Types
Path
Expand Down Expand Up @@ -119,11 +117,10 @@ import Language.Haskell.TH.Syntax (lift)
import Language.Haskell.TH.Quote (QuasiQuoter(..))
import System.OsPath.PLATFORM_NAME (PLATFORM_PATH)
import qualified System.OsPath.PLATFORM_NAME as OsPath
import System.OsString.PLATFORM_NAME (PLATFORM_STRING)
import qualified System.OsString.PLATFORM_NAME as OsString

import OsPath.Internal.PLATFORM_NAME
import qualified System.OsString.Compat.PLATFORM_NAME as OsString.Compat
import System.OsString.Compat.PLATFORM_NAME (PLATFORM_STRING)
import qualified System.OsString.Compat.PLATFORM_NAME as OsString

--------------------------------------------------------------------------------
-- Types
Expand Down Expand Up @@ -282,10 +279,10 @@ infixr 5 </>
stripProperPrefix :: MonadThrow m
=> Path b Dir -> Path b t -> m (Path Rel t)
stripProperPrefix (Path p) (Path l) =
case OsString.Compat.stripPrefix p l of
case OsString.stripPrefix p l of
Nothing -> throwM (NotAProperPrefix p l)
Just result
| OsString.Compat.null result -> throwM (NotAProperPrefix p l)
| OsString.null result -> throwM (NotAProperPrefix p l)
| otherwise -> return (Path result)

-- | Determines if the path in the first parameter is a proper prefix of the
Expand Down Expand Up @@ -329,7 +326,7 @@ replaceProperPrefix src dst fp = (dst </>) <$> stripProperPrefix src fp
--
parent :: Path b t -> Path b Dir
parent (Path fp)
| OsString.Compat.null fp = Path OsString.Compat.empty
| OsString.null fp = Path OsString.empty
| OsPath.isDrive fp = Path fp
| otherwise =
Path
Expand All @@ -342,7 +339,7 @@ parent (Path fp)
splitDrive :: Path Abs t -> (Path Abs Dir, Maybe (Path Rel t))
splitDrive (Path fp) =
let (d, rest) = OsPath.splitDrive fp
mRest = if OsString.Compat.null rest then Nothing else Just (Path rest)
mRest = if OsString.null rest then Nothing else Just (Path rest)
in (Path d, mRest)

-- | Get the drive from an absolute path. On POSIX, @/@ is a drive.
Expand Down Expand Up @@ -382,8 +379,8 @@ filename (Path l) =
--
dirname :: Path b Dir -> Path Rel Dir
dirname (Path l)
| OsString.Compat.null l = Path OsString.Compat.empty
| OsPath.isDrive l = Path OsString.Compat.empty
| OsString.null l = Path OsString.empty
| OsPath.isDrive l = Path OsString.empty
| otherwise = Path (last (OsPath.splitPath l))

-- | 'splitExtension' is the inverse of 'addExtension'. It splits the given
Expand Down Expand Up @@ -420,28 +417,28 @@ dirname (Path l)
-- @since 0.7.0
splitExtension :: MonadThrow m => Path b File -> m (Path b File, PLATFORM_STRING)
splitExtension (Path ospath) =
if OsString.Compat.null nameDot
|| OsString.Compat.null name
|| OsString.Compat.null ext
if OsString.null nameDot
|| OsString.null name
|| OsString.null ext
|| name == [OsString.pstr|.|]
|| name == [OsString.pstr|..|]
then throwM $ HasNoExtension ospath
else return ( Path (normalizeDrive drv <> dir <> name)
, OsString.Compat.singleton OsPath.extSeparator <> ext
, OsString.singleton OsPath.extSeparator <> ext
)
where

-- trailing separators are ignored for the split and considered part of the
-- second component in the split.
splitLast isSep str =
let (withoutTrailingSeps, trailingSeps) = OsString.Compat.spanEnd isSep str
(oneSep, rest) = OsString.Compat.breakEnd isSep withoutTrailingSeps
let (withoutTrailingSeps, trailingSeps) = OsString.spanEnd isSep str
(oneSep, rest) = OsString.breakEnd isSep withoutTrailingSeps
in (oneSep, rest <> trailingSeps)

(drv, ospathRel) = OsPath.splitDrive ospath
(dir, file) = splitLast OsPath.isPathSeparator ospathRel
(nameDot, ext) = splitLast OsPath.isExtSeparator file
name = OsString.Compat.init nameDot
name = OsString.init nameDot

-- | Get extension from given file path. Throws 'HasNoExtension' exception if
-- the file does not have an extension. The following laws hold:
Expand Down Expand Up @@ -484,26 +481,26 @@ addExtension :: MonadThrow m
-> Path b File -- ^ Old file name
-> m (Path b File) -- ^ New file name with the desired extension added at the end
addExtension ext (Path path) = do
(sep, xtn) <- case OsString.Compat.uncons ext of
(sep, xtn) <- case OsString.uncons ext of
Nothing -> throwM $ InvalidExtension ext
Just result -> pure result

let withoutTrailingSeps = OsString.Compat.dropWhileEnd OsPath.isExtSeparator xtn
let withoutTrailingSeps = OsString.dropWhileEnd OsPath.isExtSeparator xtn

-- Has to start with a "."
unless (OsPath.isExtSeparator sep) $
throwM $ InvalidExtension ext

-- Cannot have path separators
when (OsString.Compat.any OsPath.isPathSeparator xtn) $
when (OsString.any OsPath.isPathSeparator xtn) $
throwM $ InvalidExtension ext

-- All "."s is not a valid extension
when (OsString.Compat.null withoutTrailingSeps) $
when (OsString.null withoutTrailingSeps) $
throwM $ InvalidExtension ext

-- Cannot have "."s except in trailing position
when (OsString.Compat.any OsPath.isExtSeparator withoutTrailingSeps) $
when (OsString.any OsPath.isExtSeparator withoutTrailingSeps) $
throwM $ InvalidExtension ext

-- Must be valid as a filename
Expand Down
Loading
Loading