Skip to content

Commit

Permalink
Add classifiers field to package metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
earlbread committed May 12, 2018
1 parent 4fb4391 commit c348ade
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions docs/package.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions examples/package.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 4 additions & 3 deletions src/Nirum/Package/Metadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,6 +47,7 @@ module Nirum.Package.Metadata ( Author (Author, email, name, uri)
, readMetadata
, stringField
, tableField
, textArrayField
, versionField
) where

Expand Down
18 changes: 15 additions & 3 deletions src/Nirum/Targets/Python.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -86,6 +86,7 @@ import Nirum.Package.Metadata ( Author (Author, name, email)
)
, stringField
, tableField
, textArrayField
, versionField
)
import qualified Nirum.Package.ModuleSet as MS
Expand Down Expand Up @@ -1319,6 +1320,7 @@ compilePackageMetadata Package
, target = target'@Python
{ packageName = packageName'
, minimumRuntimeVersion = minRuntimeVer
, classifiers = classifiers'
}
}
, modules = modules'
Expand Down Expand Up @@ -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}),
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Nirum/Targets/Python/CodeGen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions test/Nirum/Package/MetadataSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import Nirum.Package.Metadata ( Metadata (Metadata, version)
, readFromPackage
, readMetadata
, stringField
, textArrayField
, versionField
)

Expand Down Expand Up @@ -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 "<string>"
[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 "<string>"
Expand Down
10 changes: 9 additions & 1 deletion test/Nirum/PackageSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/Nirum/Targets/Python/CodeGenSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/Nirum/TypeInstance/BoundModuleSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/nirum_fixture/package.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ email = "[email protected]"

[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"

Expand Down
6 changes: 6 additions & 0 deletions test/python/setup_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit c348ade

Please sign in to comment.