From c348adeb4c443ed51f4902e2911140b6dafa873b Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Sat, 12 May 2018 18:06:04 +0900 Subject: [PATCH] Add classifiers field to package metadata close #100 --- CHANGES.md | 4 ++++ docs/package.md | 12 ++++++++++++ examples/package.toml | 4 ++++ src/Nirum/Package/Metadata.hs | 7 ++++--- src/Nirum/Targets/Python.hs | 18 +++++++++++++++--- src/Nirum/Targets/Python/CodeGen.hs | 1 + test/Nirum/Package/MetadataSpec.hs | 11 +++++++++++ test/Nirum/PackageSpec.hs | 10 +++++++++- test/Nirum/Targets/Python/CodeGenSpec.hs | 2 +- test/Nirum/TypeInstance/BoundModuleSpec.hs | 2 +- test/nirum_fixture/package.toml | 4 ++++ test/python/setup_test.py | 6 ++++++ 12 files changed, 72 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index df87bf8..df268d9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -175,6 +175,8 @@ To be released. Under the hood, all generated `import`s are now aliased with a name prefixed an underscore. + - Added Python classifier metadata field. [[#100], [#269]] + ### Et cetera - The officially distributed executable binaries for Linux became @@ -184,6 +186,7 @@ To be released. March 2018. [#13]: https://github.com/spoqa/nirum/issues/13 +[#100]: https://github.com/spoqa/nirum/issues/100 [#217]: https://github.com/spoqa/nirum/issues/217 [#220]: https://github.com/spoqa/nirum/issues/220 [#227]: https://github.com/spoqa/nirum/pull/227 @@ -193,6 +196,7 @@ To be released. [#257]: https://github.com/spoqa/nirum/pull/257 [#258]: https://github.com/spoqa/nirum/pull/258 [#259]: https://github.com/spoqa/nirum/pull/259 +[#269]: https://github.com/spoqa/nirum/pull/269 [entry points]: https://setuptools.readthedocs.io/en/latest/pkg_resources.html#entry-points [python2-numbers-integral]: https://docs.python.org/2/library/numbers.html#numbers.Integral [python2-int]: https://docs.python.org/2/library/functions.html#int diff --git a/docs/package.md b/docs/package.md index 9ea6383..7d63923 100644 --- a/docs/package.md +++ b/docs/package.md @@ -97,6 +97,18 @@ of the package to be generated by Nirum, hence `name`: [targets.python] name = "py-foobar" # will be submitted to: pypi.python.org/pypi/py-foobar + minimum_runtime = "0.3.9" + classifiers = [ + "Development Status :: 3 - Alpha", + "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)" + ] + +There are two optional fields, `minimum_runtime` and `classifiers`. +`minimum_runtime` is a version of [nirum-python][] that +is required by generated python package. `classifiers` contains a list of +classifier which is listed on [classifier list][pypi-classifier-list]. + +[pypi-classifier-list]: https://pypi.org/pypi?%3Aaction=list_classifiers Text encoding diff --git a/examples/package.toml b/examples/package.toml index 817b6c8..17f20c9 100644 --- a/examples/package.toml +++ b/examples/package.toml @@ -3,6 +3,10 @@ version = "0.3.0" [targets.python] name = "nirum-examples" minimum_runtime = "0.3.9" +classifiers = [ + "Development Status :: 3 - Alpha", + "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)" +] [targets.docs] title = "Nirum Examples" diff --git a/src/Nirum/Package/Metadata.hs b/src/Nirum/Package/Metadata.hs index 3dfc344..dba7e96 100644 --- a/src/Nirum/Package/Metadata.hs +++ b/src/Nirum/Package/Metadata.hs @@ -3,11 +3,11 @@ module Nirum.Package.Metadata ( Author (Author, email, name, uri) , Metadata ( Metadata , authors - , target - , version , description - , license , keywords + , license + , target + , version ) , MetadataError ( FieldError , FieldTypeError @@ -47,6 +47,7 @@ module Nirum.Package.Metadata ( Author (Author, email, name, uri) , readMetadata , stringField , tableField + , textArrayField , versionField ) where diff --git a/src/Nirum/Targets/Python.hs b/src/Nirum/Targets/Python.hs index e0192e4..e9af30c 100644 --- a/src/Nirum/Targets/Python.hs +++ b/src/Nirum/Targets/Python.hs @@ -66,10 +66,10 @@ import Nirum.Docs.ReStructuredText (ReStructuredText, render) import Nirum.Package hiding (target) import Nirum.Package.Metadata ( Author (Author, name, email) , Metadata ( authors - , target - , version , description , license + , target + , version ) , MetadataError ( FieldError , FieldTypeError @@ -86,6 +86,7 @@ import Nirum.Package.Metadata ( Author (Author, name, email) ) , stringField , tableField + , textArrayField , versionField ) import qualified Nirum.Package.ModuleSet as MS @@ -1319,6 +1320,7 @@ compilePackageMetadata Package , target = target'@Python { packageName = packageName' , minimumRuntimeVersion = minRuntimeVer + , classifiers = classifiers' } } , modules = modules' @@ -1384,13 +1386,18 @@ SOURCE_ROOT = #{stringLiteral $ sourceDirectory Python3} if sys.version_info < (3, 0): SOURCE_ROOT = #{stringLiteral $ sourceDirectory Python2} -# TODO: long_description, url, classifiers +# TODO: long_description, url setup( name=#{stringLiteral packageName'}, version=#{stringLiteral $ SV.toText version'}, description=#{nStringLiteral description'}, license=#{nStringLiteral license'}, keywords=#{stringLiteral $ T.intercalate " " keywords'}, + classifiers=[ +%{ forall classifier <- classifiers' } + #{stringLiteral classifier}, +%{ endforall } + ], author=', '.join([ %{ forall Author { name = name } <- authors' } (#{stringLiteral name}), @@ -1529,9 +1536,14 @@ instance Target Python where MD.fieldType v | (k, v) <- HM.toList renameTable ] + classifiers' <- case textArrayField "classifiers" table of + Right t -> Right t + Left (FieldError _) -> Right [] + otherwise' -> otherwise' return Python { packageName = name' , minimumRuntimeVersion = max minRuntime minimumRuntime , renames = M.fromList renamePairs + , classifiers = classifiers' } compilePackage = compilePackage' showCompileError _ e = e diff --git a/src/Nirum/Targets/Python/CodeGen.hs b/src/Nirum/Targets/Python/CodeGen.hs index 8c655c1..ad16319 100644 --- a/src/Nirum/Targets/Python/CodeGen.hs +++ b/src/Nirum/Targets/Python/CodeGen.hs @@ -68,6 +68,7 @@ type RenameMap = Map ModulePath ModulePath data Python = Python { packageName :: Text , minimumRuntimeVersion :: Version , renames :: RenameMap + , classifiers :: [Text] } deriving (Eq, Ord, Show, Typeable) data PythonVersion = Python2 diff --git a/test/Nirum/Package/MetadataSpec.hs b/test/Nirum/Package/MetadataSpec.hs index ee7cc8b..6265c81 100644 --- a/test/Nirum/Package/MetadataSpec.hs +++ b/test/Nirum/Package/MetadataSpec.hs @@ -40,6 +40,7 @@ import Nirum.Package.Metadata ( Metadata (Metadata, version) , readFromPackage , readMetadata , stringField + , textArrayField , versionField ) @@ -250,6 +251,16 @@ spec = fieldType (get "t1") `shouldBe` "table of an item" fieldType (get "t2") `shouldBe` "table of 2 items" fieldType (get "ta") `shouldBe` "array of 2 tables" + specify "textArrayField" $ do + let Right table = parseTomlDoc "" + [q|ta = [] + sa = ["a", "b", "c"] + i = 1|] + textArrayField "ta" table `shouldBe` Right [] + textArrayField "sa" table `shouldBe` Right ["a", "b", "c"] + textArrayField "i" table `shouldBe` Left (FieldTypeError + "i" "array" "integer (1)") + where parse :: Text -> Either MetadataError (Metadata DummyTarget) parse = parseMetadata "" diff --git a/test/Nirum/PackageSpec.hs b/test/Nirum/PackageSpec.hs index 50539e6..c0a79b7 100644 --- a/test/Nirum/PackageSpec.hs +++ b/test/Nirum/PackageSpec.hs @@ -4,6 +4,7 @@ module Nirum.PackageSpec where import Data.Either (isLeft, isRight) import Data.Proxy (Proxy (Proxy)) +import Data.Text import System.IO.Error (isDoesNotExistError) import qualified Data.SemVer as SV @@ -53,8 +54,15 @@ createValidPackage t = createPackage Metadata { version = SV.initial spec :: Spec spec = do - testPackage (Python "nirum-examples" minimumRuntime []) + testPackage (Python "nirum-examples" minimumRuntime [] classifiers') testPackage DummyTarget + where + classifiers' :: [Text] + classifiers' = + [ "Development Status :: 3 - Alpha" + , append "License :: OSI Approved :: " + "GNU General Public License v3 or later (GPLv3+)" + ] testPackage :: forall t . Target t => t -> Spec testPackage target' = do diff --git a/test/Nirum/Targets/Python/CodeGenSpec.hs b/test/Nirum/Targets/Python/CodeGenSpec.hs index cd4ee55..3691988 100644 --- a/test/Nirum/Targets/Python/CodeGenSpec.hs +++ b/test/Nirum/Targets/Python/CodeGenSpec.hs @@ -48,7 +48,7 @@ makeDummySource' pathPrefix m renames = , description = Just "Package description" , license = Just "MIT" , Nirum.Package.Metadata.keywords = ["sample", "example", "nirum"] - , target = Python "sample-package" minimumRuntime renames + , target = Python "sample-package" minimumRuntime renames ["classifier"] } pkg :: Package Python pkg = createPackage diff --git a/test/Nirum/TypeInstance/BoundModuleSpec.hs b/test/Nirum/TypeInstance/BoundModuleSpec.hs index a604163..4c8f5f9 100644 --- a/test/Nirum/TypeInstance/BoundModuleSpec.hs +++ b/test/Nirum/TypeInstance/BoundModuleSpec.hs @@ -21,7 +21,7 @@ import Nirum.TypeInstance.BoundModule spec :: Spec spec = do - testPackage (Python "nirum-examples" minimumRuntime []) + testPackage (Python "nirum-examples" minimumRuntime [] []) testPackage DummyTarget testPackage :: forall t . Target t => t -> Spec diff --git a/test/nirum_fixture/package.toml b/test/nirum_fixture/package.toml index a567475..f428ef0 100644 --- a/test/nirum_fixture/package.toml +++ b/test/nirum_fixture/package.toml @@ -9,6 +9,10 @@ email = "dev@nirum.org" [targets.python] name = "nirum_fixture" +classifiers = [ + "Development Status :: 3 - Alpha", + "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)" +] [targets.python.renames] "renames.test" = "renamed" diff --git a/test/python/setup_test.py b/test/python/setup_test.py index f03a597..f09c07f 100644 --- a/test/python/setup_test.py +++ b/test/python/setup_test.py @@ -28,6 +28,12 @@ def test_setup_metadata(): assert ['0.3.0'] == pkg['Version'] assert ['Package description'] == pkg['Summary'] assert ['MIT'] == pkg['License'] + expected = [ + "Development Status :: 3 - Alpha", + "License :: OSI Approved :: " + "GNU General Public License v3 or later (GPLv3+)", + ] + assert expected == pkg['Classifier'] def test_module_entry_points():