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

Add license field to package metadata #180

Merged
merged 4 commits into from
Aug 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions docs/package.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 { target = 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
15 changes: 10 additions & 5 deletions src/Nirum/Targets/Python.hs
Original file line number Diff line number Diff line change
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 @@ -1186,12 +1187,12 @@ SOURCE_ROOT = '{sourceDirectory Python3}'
if sys.version_info < (3, 0):
SOURCE_ROOT = '{sourceDirectory Python2}'

# TODO: description, long_description, url, license,
# keywords, classifiers
# TODO: long_description, url, keywords, classifiers
setup(
name='{pName}',
version='{pVersion}',
description=$pDescription,
license=$pLicense,
author=$author,
author_email=$authorEmail,
package_dir=\{'': SOURCE_ROOT},
Expand All @@ -1213,10 +1214,14 @@ setup(
pName = packageName $ target metadata'
pVersion :: Code
pVersion = SV.toText $ version metadata'
fromMaybeToMeta :: Maybe T.Text -> T.Text
fromMaybeToMeta s = case s of
Just value -> stringLiteral value
Nothing -> "None"
pDescription :: Code
pDescription = case description metadata' of
Just value -> stringLiteral value
Nothing -> "None"
pDescription = fromMaybeToMeta $ description metadata'
pLicense :: Code
pLicense = fromMaybeToMeta $ license metadata'
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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']