From 4221cc73569cb6c3b87f4a4f23a7a2d261ae1500 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Mon, 21 Aug 2017 15:01:27 +0900 Subject: [PATCH 1/3] Add description field to package metadata --- src/Nirum/Package/Metadata.hs | 12 ++++++++++-- src/Nirum/Targets/Python.hs | 12 +++++++++++- test/Nirum/CodeBuilderSpec.hs | 1 + test/Nirum/Package/MetadataSpec.hs | 7 +++++++ test/Nirum/PackageSpec.hs | 9 ++++++++- test/Nirum/Targets/PythonSpec.hs | 7 ++++++- test/nirum_fixture/package.toml | 1 + test/python/setup_test.py | 1 + 8 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/Nirum/Package/Metadata.hs b/src/Nirum/Package/Metadata.hs index 2a22ea5..10c905f 100644 --- a/src/Nirum/Package/Metadata.hs +++ b/src/Nirum/Package/Metadata.hs @@ -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 @@ -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 } @@ -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' @@ -184,6 +191,7 @@ parseMetadata metadataPath' tomlText = do $ prependMetadataErrorField targetName' e otherwise' -> otherwise' return Metadata { version = version' + , description = description' , authors = authors' , target = target' } diff --git a/src/Nirum/Targets/Python.hs b/src/Nirum/Targets/Python.hs index 48e6783..b7f1473 100644 --- a/src/Nirum/Targets/Python.hs +++ b/src/Nirum/Targets/Python.hs @@ -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 @@ -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}, @@ -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 -> T.intercalate "" ["'", value, "'"] + Nothing -> "None" strings :: [Code] -> Code strings values = T.intercalate ", " $ map stringLiteral (L.sort values) author :: Code diff --git a/test/Nirum/CodeBuilderSpec.hs b/test/Nirum/CodeBuilderSpec.hs index cf58968..58dca0e 100644 --- a/test/Nirum/CodeBuilderSpec.hs +++ b/test/Nirum/CodeBuilderSpec.hs @@ -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' diff --git a/test/Nirum/Package/MetadataSpec.hs b/test/Nirum/Package/MetadataSpec.hs index 25291ae..015a4fd 100644 --- a/test/Nirum/Package/MetadataSpec.hs +++ b/test/Nirum/Package/MetadataSpec.hs @@ -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 diff --git a/test/Nirum/PackageSpec.hs b/test/Nirum/PackageSpec.hs index eba5dd8..5d1304e 100644 --- a/test/Nirum/PackageSpec.hs +++ b/test/Nirum/PackageSpec.hs @@ -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) ) @@ -56,6 +61,7 @@ createPackage metadata' modules' = createValidPackage :: t -> Package t createValidPackage t = createPackage Metadata { version = SV.initial , authors = [] + , description = Nothing , target = t } validModules @@ -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' diff --git a/test/Nirum/Targets/PythonSpec.hs b/test/Nirum/Targets/PythonSpec.hs index be704b5..af4e6a0 100644 --- a/test/Nirum/Targets/PythonSpec.hs +++ b/test/Nirum/Targets/PythonSpec.hs @@ -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 @@ -95,6 +99,7 @@ makeDummySource' pathPrefix m renames = , uri = Nothing } ] + , description = Just "Package description" , target = Python "sample-package" minimumRuntime renames } pkg :: Package Python diff --git a/test/nirum_fixture/package.toml b/test/nirum_fixture/package.toml index 9223335..0de66ec 100644 --- a/test/nirum_fixture/package.toml +++ b/test/nirum_fixture/package.toml @@ -1,4 +1,5 @@ version = "0.3.0" +description = "Package description" [[authors]] name = "nirum" diff --git a/test/python/setup_test.py b/test/python/setup_test.py index b7c5547..aea50f4 100644 --- a/test/python/setup_test.py +++ b/test/python/setup_test.py @@ -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'] From 0d949301e5939e2824fc3610a0c54868d746f0ab Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Tue, 22 Aug 2017 13:07:56 +0900 Subject: [PATCH 2/3] Update spacing --- src/Nirum/Package/Metadata.hs | 2 +- src/Nirum/Targets/Python.hs | 2 +- test/Nirum/PackageSpec.hs | 2 +- test/Nirum/Targets/PythonSpec.hs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Nirum/Package/Metadata.hs b/src/Nirum/Package/Metadata.hs index 10c905f..a345df0 100644 --- a/src/Nirum/Package/Metadata.hs +++ b/src/Nirum/Package/Metadata.hs @@ -1,7 +1,7 @@ {-# LANGUAGE GADTs, QuasiQuotes, RankNTypes, ScopedTypeVariables, StandaloneDeriving, TypeFamilies #-} module Nirum.Package.Metadata ( Author (Author, email, name, uri) - , Metadata (Metadata + , Metadata ( Metadata , authors , target , version diff --git a/src/Nirum/Targets/Python.hs b/src/Nirum/Targets/Python.hs index b7f1473..2500d5e 100644 --- a/src/Nirum/Targets/Python.hs +++ b/src/Nirum/Targets/Python.hs @@ -117,7 +117,7 @@ import Nirum.Package ( BoundModule , types ) import Nirum.Package.Metadata ( Author (Author, name, email) - , Metadata (Metadata + , Metadata ( Metadata , authors , target , version diff --git a/test/Nirum/PackageSpec.hs b/test/Nirum/PackageSpec.hs index 5d1304e..99bc1d0 100644 --- a/test/Nirum/PackageSpec.hs +++ b/test/Nirum/PackageSpec.hs @@ -35,7 +35,7 @@ import Nirum.Package ( BoundModule (boundPackage, modulePath) , scanPackage , types ) -import Nirum.Package.Metadata ( Metadata (Metadata +import Nirum.Package.Metadata ( Metadata ( Metadata , authors , target , version diff --git a/test/Nirum/Targets/PythonSpec.hs b/test/Nirum/Targets/PythonSpec.hs index af4e6a0..bfce2c1 100644 --- a/test/Nirum/Targets/PythonSpec.hs +++ b/test/Nirum/Targets/PythonSpec.hs @@ -37,7 +37,7 @@ import Nirum.Constructs.TypeExpression ( TypeExpression ( ListModifier ) import Nirum.Package (Package (metadata, modules), resolveBoundModule) import Nirum.Package.Metadata ( Author (Author, email, name, uri) - , Metadata (Metadata + , Metadata ( Metadata , authors , target , version From 7f4aa39cba9a058bb468dbf2fcb7a55b991b8349 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Tue, 22 Aug 2017 13:08:39 +0900 Subject: [PATCH 3/3] Use stringLiteral to escape string --- src/Nirum/Targets/Python.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nirum/Targets/Python.hs b/src/Nirum/Targets/Python.hs index 2500d5e..3e63edc 100644 --- a/src/Nirum/Targets/Python.hs +++ b/src/Nirum/Targets/Python.hs @@ -1215,7 +1215,7 @@ setup( pVersion = SV.toText $ version metadata' pDescription :: Code pDescription = case description metadata' of - Just value -> T.intercalate "" ["'", value, "'"] + Just value -> stringLiteral value Nothing -> "None" strings :: [Code] -> Code strings values = T.intercalate ", " $ map stringLiteral (L.sort values)