Skip to content

Commit c1c5f41

Browse files
committed
Accept a list for category (fixes #624)
1 parent 05b8c03 commit c1c5f41

File tree

10 files changed

+52
-24
lines changed

10 files changed

+52
-24
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- os: windows-latest
3838
ghc: '9.10'
3939
steps:
40-
- uses: actions/checkout@v3
40+
- uses: actions/checkout@v5
4141
- uses: hspec/setup-haskell@v1
4242
with:
4343
ghc-version: ${{ matrix.ghc }}
@@ -54,6 +54,6 @@ jobs:
5454
- run: false
5555
if: needs.build.result != 'success'
5656

57-
- uses: actions/checkout@v3
57+
- uses: actions/checkout@v5
5858
- name: Check for trailing whitespace
5959
run: '! git grep -I "\s\+$"'

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## Changes in 0.38.3
2+
- Accept a list for `category` (see #624)
3+
14
## Changes in 0.38.2
25
- Infer `cabal-version: 3.12` when `PackageInfo_*` is used (see #620)
36

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ library:
131131
| `version` | · | `0.0.0` | | | |
132132
| `synopsis` | · | | | | |
133133
| `description` | · | | | | |
134-
| `category` | · | | | | |
134+
| `category` | · | | May be a list (since `0.38.3`) | | |
135135
| `stability` | · | | | | |
136136
| `homepage` | · | If `github` given, `<repo>#readme` | | | |
137137
| `bug-reports` | · | If `github` given, `<repo>/issues` | | | |

hpack.cabal

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
spec-version: 0.36.0
22
name: hpack
3-
version: 0.38.2
3+
version: 0.38.3
44
synopsis: A modern format for Haskell packages
55
description: See README at <https://github.com/sol/hpack#readme>
66
author: Simon Hengel <sol@typeful.net>
7-
maintainer: Simon Hengel <sol@typeful.net>
87
github: sol/hpack
98
category: Development
10-
extra-source-files:
11-
- CHANGELOG.md
12-
- resources/**/*
9+
10+
extra-source-files: resources/**/*
11+
12+
extra-doc-files: CHANGELOG.md
1313

1414
ghc-options: -Wall -fno-warn-incomplete-uni-patterns
1515

src/Hpack/Config.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ package name version = Package {
148148
, packageDescription = Nothing
149149
, packageHomepage = Nothing
150150
, packageBugReports = Nothing
151-
, packageCategory = Nothing
151+
, packageCategory = []
152152
, packageStability = Nothing
153153
, packageAuthor = []
154154
, packageMaintainer = []
@@ -591,7 +591,7 @@ data PackageConfig_ library executable = PackageConfig {
591591
, packageConfigDescription :: Maybe String
592592
, packageConfigHomepage :: Maybe (Maybe String)
593593
, packageConfigBugReports :: Maybe (Maybe String)
594-
, packageConfigCategory :: Maybe String
594+
, packageConfigCategory :: Maybe (List String)
595595
, packageConfigStability :: Maybe String
596596
, packageConfigAuthor :: Maybe (List String)
597597
, packageConfigMaintainer :: Maybe (Maybe (List String))
@@ -1032,7 +1032,7 @@ data Package = Package {
10321032
, packageDescription :: Maybe String
10331033
, packageHomepage :: Maybe String
10341034
, packageBugReports :: Maybe String
1035-
, packageCategory :: Maybe String
1035+
, packageCategory :: [String]
10361036
, packageStability :: Maybe String
10371037
, packageAuthor :: [String]
10381038
, packageMaintainer :: [String]
@@ -1326,7 +1326,7 @@ toPackage_ dir (Product g PackageConfig{..}) = do
13261326
, packageDescription = packageConfigDescription
13271327
, packageHomepage = homepage
13281328
, packageBugReports = bugReports
1329-
, packageCategory = packageConfigCategory
1329+
, packageCategory = fromMaybeList packageConfigCategory
13301330
, packageStability = packageConfigStability
13311331
, packageAuthor = fromMaybeList packageConfigAuthor
13321332
, packageMaintainer = fromMaybeList maintainer

src/Hpack/Render.hs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,30 @@ renderPackageWith settings headerFieldsAlignment existingFieldOrder sectionsFiel
118118
, ("version", Just packageVersion)
119119
, ("synopsis", packageSynopsis)
120120
, ("description", (formatDescription packageCabalVersion headerFieldsAlignment <$> packageDescription))
121-
, ("category", packageCategory)
121+
, formatList "category" packageCategory
122122
, ("stability", packageStability)
123123
, ("homepage", packageHomepage)
124124
, ("bug-reports", packageBugReports)
125-
, ("author", formatList packageAuthor)
126-
, ("maintainer", formatList packageMaintainer)
127-
, ("copyright", formatList packageCopyright)
125+
, formatList "author" packageAuthor
126+
, formatList "maintainer" packageMaintainer
127+
, formatList "copyright" packageCopyright
128128
, ("license", packageLicense)
129129
, case packageLicenseFile of
130130
[file] -> ("license-file", Just file)
131-
files -> ("license-files", formatList files)
131+
files -> formatList "license-files" files
132132
, ("build-type", Just (show packageBuildType))
133133
]
134134

135-
formatList :: [String] -> Maybe String
136-
formatList xs = guard (not $ null xs) >> (Just $ intercalate separator xs)
135+
formatList :: String -> [String] -> (String, Maybe String)
136+
formatList field = (,) field . formatValues
137137
where
138-
separator = let Alignment n = headerFieldsAlignment in ",\n" ++ replicate n ' '
138+
formatValues :: [String] -> Maybe String
139+
formatValues values = guard (not $ null values) >> (Just $ intercalate separator values)
140+
where
141+
separator :: String
142+
separator = ",\n" ++ replicate n ' '
143+
where
144+
Alignment n = max headerFieldsAlignment (Alignment $ length field + 2)
139145

140146
sortStanzaFields :: [(String, [String])] -> [Element] -> [Element]
141147
sortStanzaFields sectionsFieldOrder = go

src/Hpack/Render/Dsl.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ newtype Nesting = Nesting Int
4646
deriving (Eq, Show, Num, Enum)
4747

4848
newtype Alignment = Alignment Int
49-
deriving (Eq, Show, Num)
49+
deriving (Eq, Ord, Show, Num)
5050

5151
data RenderSettings = RenderSettings {
5252
renderSettingsIndentation :: Int

test/EndToEndSpec.hs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,24 @@ spec = around_ (inTempDirectoryNamed "my-package") $ do
103103
baz
104104
|]) { packageCabalVersion = "3.0" }
105105

106+
describe "category" $ do
107+
it "accepts a single category" $ do
108+
[i|
109+
category: Testing
110+
|] `shouldRenderTo` package [i|
111+
category: Testing
112+
|]
113+
114+
it "accepts a list of categories" $ do
115+
[i|
116+
category:
117+
- Development
118+
- Testing
119+
|] `shouldRenderTo` package [i|
120+
category: Development,
121+
Testing
122+
|]
123+
106124
describe "handling of Paths_ module" $ do
107125
it "adds Paths_ to other-modules" $ do
108126
[i|

test/Hpack/ConfigSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ spec = do
225225
withPackageConfig_ [i|
226226
category: Data
227227
|]
228-
(`shouldBe` package {packageCategory = Just "Data"})
228+
(`shouldBe` package {packageCategory = ["Data"]})
229229

230230
it "accepts author" $ do
231231
withPackageConfig_ [i|

0 commit comments

Comments
 (0)