Skip to content

Commit

Permalink
Add license field to package metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
earlbread committed Aug 29, 2017
1 parent 73ea891 commit d060adc
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/package.md
Expand Up @@ -43,6 +43,7 @@ is an example:

version = "1.0.0" # (required)
description = "Short description on the package"
license = "MIT"

[[authors]]
name = "John Doe" # (required)
Expand All @@ -57,6 +58,9 @@ It consists of the following fields (*emphasized fields* are required):
`description` (string)
: An optional short description of the package.

`license` (string)
: An optional license of the package.

`authors` (array of tables)
: The list of authors. Note that it can be empty, but `name` field is
required if any author is provided. Each author table consists of
Expand Down
6 changes: 5 additions & 1 deletion src/Nirum/Package/Metadata.hs
Expand Up @@ -6,6 +6,7 @@ module Nirum.Package.Metadata ( Author (Author, email, name, uri)
, target
, version
, description
, license
)
, MetadataError ( FieldError
, FieldTypeError
Expand Down Expand Up @@ -96,11 +97,12 @@ deriving instance (Ord t, Target t) => Ord (Package t)
deriving instance (Show t, Target t) => Show (Package t)

packageTarget :: Target t => Package t -> t
packageTarget Package { metadata = Metadata _ _ _ t } = t
packageTarget Package { metadata = Metadata _ _ _ _ t } = t

data Metadata t =
Metadata { version :: SV.Version
, description :: Maybe Text
, license :: Maybe Text
, authors :: [Author]
, target :: (Eq t, Ord t, Show t, Target t) => t
}
Expand Down Expand Up @@ -181,6 +183,7 @@ parseMetadata metadataPath' tomlText = do
version' <- versionField "version" table
authors' <- authorsField "authors" table
description' <- optional $ stringField "description" table
license' <- optional $ stringField "license" table
targets <- case tableField "targets" table of
Left (FieldError _) -> Right HM.empty
otherwise' -> otherwise'
Expand All @@ -194,6 +197,7 @@ parseMetadata metadataPath' tomlText = do
otherwise' -> otherwise'
return Metadata { version = version'
, description = description'
, license = license'
, authors = authors'
, target = target'
}
Expand Down
6 changes: 6 additions & 0 deletions src/Nirum/Targets/Python.hs
Expand Up @@ -122,6 +122,7 @@ import Nirum.Package.Metadata ( Author (Author, name, email)
, target
, version
, description
, license
)
, MetadataError ( FieldError
, FieldTypeError
Expand Down Expand Up @@ -1192,6 +1193,7 @@ setup(
name='{pName}',
version='{pVersion}',
description=$pDescription,
license=$pLicense,
author=$author,
author_email=$authorEmail,
package_dir=\{'': SOURCE_ROOT},
Expand All @@ -1217,6 +1219,10 @@ setup(
pDescription = case description metadata' of
Just value -> stringLiteral value
Nothing -> "None"
pLicense :: Code
pLicense = case license metadata' of
Just value -> stringLiteral value
Nothing -> "None"
strings :: [Code] -> Code
strings values = T.intercalate ", " $ map stringLiteral (L.sort values)
author :: Code
Expand Down
1 change: 1 addition & 0 deletions test/Nirum/CodeBuilderSpec.hs
Expand Up @@ -39,6 +39,7 @@ package :: Package DummyTarget
package = Package { metadata = Metadata { version = SV.version 0 0 1 [] []
, authors = []
, description = Nothing
, license = Nothing
, target = DummyTarget
}
, modules = modules'
Expand Down
7 changes: 7 additions & 0 deletions test/Nirum/Package/MetadataSpec.hs
Expand Up @@ -128,6 +128,13 @@ spec =
, "string"
, "integer (123)"
)
, ( [q|version = "1.2.3"
license = 123
|]
, "license"
, "string"
, "integer (123)"
)
] $ \ (toml, field, expected, actual) -> do
let Left e = parse toml
FieldTypeError field' expected' actual' = e
Expand Down
3 changes: 3 additions & 0 deletions test/Nirum/PackageSpec.hs
Expand Up @@ -40,6 +40,7 @@ import Nirum.Package.Metadata ( Metadata ( Metadata
, target
, version
, description
, license
)
, MetadataError (FormatError)
, Target (targetName)
Expand All @@ -62,6 +63,7 @@ createValidPackage :: t -> Package t
createValidPackage t = createPackage Metadata { version = SV.initial
, authors = []
, description = Nothing
, license = Nothing
, target = t
} validModules

Expand Down Expand Up @@ -110,6 +112,7 @@ testPackage target' = do
metadata' = Metadata { version = SV.version 0 3 0 [] []
, authors = []
, description = Nothing
, license = Nothing
, target = target'
}
metadata package `shouldBe` metadata'
Expand Down
4 changes: 3 additions & 1 deletion test/Nirum/Targets/PythonSpec.hs
Expand Up @@ -41,7 +41,8 @@ import Nirum.Package.Metadata ( Author (Author, email, name, uri)
, authors
, target
, version
, description)
, description
, license)
, Target (compilePackage)
)
import qualified Nirum.Package.ModuleSet as MS
Expand Down Expand Up @@ -100,6 +101,7 @@ makeDummySource' pathPrefix m renames =
}
]
, description = Just "Package description"
, license = Just "MIT"
, target = Python "sample-package" minimumRuntime renames
}
pkg :: Package Python
Expand Down
1 change: 1 addition & 0 deletions test/nirum_fixture/package.toml
@@ -1,5 +1,6 @@
version = "0.3.0"
description = "Package description"
license = "MIT"

[[authors]]
name = "nirum"
Expand Down
1 change: 1 addition & 0 deletions test/python/setup_test.py
Expand Up @@ -22,3 +22,4 @@ def test_setup_metadata():
}
assert ['0.3.0'] == pkg['Version']
assert ['Package description'] == pkg['Summary']
assert ['MIT'] == pkg['License']

0 comments on commit d060adc

Please sign in to comment.