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 description field to package metadata #174

Merged
merged 3 commits into from
Aug 22, 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
12 changes: 10 additions & 2 deletions src/Nirum/Package/Metadata.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{-# LANGUAGE GADTs, QuasiQuotes, RankNTypes, ScopedTypeVariables,
StandaloneDeriving, TypeFamilies #-}
module Nirum.Package.Metadata ( Author (Author, email, name, uri)
, Metadata (Metadata, authors, target, version)
, Metadata ( Metadata
, authors
, target
, version
, description
)
, MetadataError ( FieldError
, FieldTypeError
, FieldValueError
Expand Down Expand Up @@ -91,10 +96,11 @@ 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
, authors :: [Author]
, target :: (Eq t, Ord t, Show t, Target t) => t
}
Expand Down Expand Up @@ -172,6 +178,7 @@ parseMetadata metadataPath' tomlText = do
Right t -> Right t
version' <- versionField "version" table
authors' <- authorsField "authors" table
description' <- optional $ stringField "description" table
targets <- case tableField "targets" table of
Left (FieldError _) -> Right HM.empty
otherwise' -> otherwise'
Expand All @@ -184,6 +191,7 @@ parseMetadata metadataPath' tomlText = do
$ prependMetadataErrorField targetName' e
otherwise' -> otherwise'
return Metadata { version = version'
, description = description'
, authors = authors'
, target = target'
}
Expand Down
12 changes: 11 additions & 1 deletion src/Nirum/Targets/Python.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ import Nirum.Package ( BoundModule
, types
)
import Nirum.Package.Metadata ( Author (Author, name, email)
, Metadata (Metadata, authors, target, version)
, Metadata ( Metadata
, authors
, target
, version
, description
)
, MetadataError ( FieldError
, FieldTypeError
, FieldValueError
Expand Down Expand Up @@ -1186,6 +1191,7 @@ if sys.version_info < (3, 0):
setup(
name='{pName}',
version='{pVersion}',
description=$pDescription,
author=$author,
author_email=$authorEmail,
package_dir=\{'': SOURCE_ROOT},
Expand All @@ -1207,6 +1213,10 @@ setup(
pName = packageName $ target metadata'
pVersion :: Code
pVersion = SV.toText $ version metadata'
pDescription :: Code
pDescription = case description 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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ modules' = case m of
package :: Package DummyTarget
package = Package { metadata = Metadata { version = SV.version 0 0 1 [] []
, authors = []
, description = 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 @@ -121,6 +121,13 @@ spec =
, "string"
, "array of 0 values"
)
, ( [q|version = "1.2.3"
description = 123
|]
, "description"
, "string"
, "integer (123)"
)
] $ \ (toml, field, expected, actual) -> do
let Left e = parse toml
FieldTypeError field' expected' actual' = e
Expand Down
9 changes: 8 additions & 1 deletion test/Nirum/PackageSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ import Nirum.Package ( BoundModule (boundPackage, modulePath)
, scanPackage
, types
)
import Nirum.Package.Metadata ( Metadata (Metadata, authors, target, version)
import Nirum.Package.Metadata ( Metadata ( Metadata
, authors
, target
, version
, description
)
, MetadataError (FormatError)
, Target (targetName)
)
Expand All @@ -56,6 +61,7 @@ createPackage metadata' modules' =
createValidPackage :: t -> Package t
createValidPackage t = createPackage Metadata { version = SV.initial
, authors = []
, description = Nothing
, target = t
} validModules

Expand Down Expand Up @@ -103,6 +109,7 @@ testPackage target' = do
] :: [(ModulePath, Module)]
metadata' = Metadata { version = SV.version 0 3 0 [] []
, authors = []
, description = Nothing
, target = target'
}
metadata package `shouldBe` metadata'
Expand Down
7 changes: 6 additions & 1 deletion test/Nirum/Targets/PythonSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ import Nirum.Constructs.TypeExpression ( TypeExpression ( ListModifier
)
import Nirum.Package (Package (metadata, modules), resolveBoundModule)
import Nirum.Package.Metadata ( Author (Author, email, name, uri)
, Metadata (Metadata, authors, target, version)
, Metadata ( Metadata
, authors
, target
, version
, description)
, Target (compilePackage)
)
import qualified Nirum.Package.ModuleSet as MS
Expand Down Expand Up @@ -95,6 +99,7 @@ makeDummySource' pathPrefix m renames =
, uri = Nothing
}
]
, description = Just "Package description"
, 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,4 +1,5 @@
version = "0.3.0"
description = "Package description"

[[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 @@ -21,3 +21,4 @@ def test_setup_metadata():
'renamed', 'renamed.foo', 'renamed.foo.bar',
}
assert ['0.3.0'] == pkg['Version']
assert ['Package description'] == pkg['Summary']