hpack.py: new generator
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Anna “CyberTailor” 2023-06-22 04:14:02 +05:00
parent d8e453ec29
commit 3811c8bb33
Signed by: CyberTaIlor
GPG Key ID: E7B76EDC50864BB1
15 changed files with 642 additions and 0 deletions

View File

@ -14,6 +14,7 @@ Supported generators
* [Bower](https://github.com/bower/spec/blob/master/json.md)
* Crystal ([Shards](https://github.com/crystal-lang/shards/blob/master/docs/shard.yml.adoc))
* Haskell ([Hpack](https://github.com/sol/hpack/blob/main/README.md))
* Node.js ([npm](https://docs.npmjs.com/files/package.json/))
* PHP ([Composer](https://getcomposer.org/doc/04-schema.md))
* Python ([PEP 621](https://peps.python.org/pep-0621/))

View File

@ -16,6 +16,7 @@ from gentle.metadata import MetadataXML
import gentle.generators.bower
import gentle.generators.cargo
import gentle.generators.composer
import gentle.generators.hpack
import gentle.generators.npm
import gentle.generators.pyproject
import gentle.generators.shards

View File

@ -0,0 +1,79 @@
# SPDX-License-Identifier: WTFPL
# SPDX-FileCopyrightText: 2023 Anna <cyber@sysrq.in>
# No warranty
"""
Metadata XML generator for Haskell Hpack.
The following attributes are supported:
* Upstream maintainer(s)
* Upstream documentation
* Remote ID
"""
import logging
from pathlib import Path
from gentle.generators import AbstractGenerator
from gentle.metadata import MetadataXML, RemoteID
from gentle.metadata.utils import extract_name_email, extract_remote_id
try:
import yaml
from yaml import CLoader
_HAS_PYYAML = True
except ModuleNotFoundError:
_HAS_PYYAML = False
logger = logging.getLogger("hpack")
class HpackGenerator(AbstractGenerator):
def __init__(self, srcdir: Path):
self.package_yaml = srcdir / "package.yaml"
def update_metadata_xml(self, mxml: MetadataXML) -> None:
with open(self.package_yaml) as file:
if (package := yaml.load(file, CLoader)) is None:
package = {}
maint_key = "maintainer"
if maint_key not in package:
maint_key = "author"
maintainers = package.get(maint_key, [])
if isinstance(maintainers, str):
maintainers = [maintainers]
for maint in map(extract_name_email, maintainers):
if maint is None:
continue
logger.info("Found upstream maintainer: %s", maint)
mxml.add_upstream_maintainer(maint)
if (bugs_to := package.get("bug-reports")) is not None:
logger.info("Found bug tracker: %s", bugs_to)
mxml.set_upstream_bugs_to(bugs_to)
if (homepage := package.get("homepage")) is not None:
logger.info("Found homepage: %s", homepage)
if (remote_id := extract_remote_id(homepage)) is not None:
mxml.add_upstream_remote_id(remote_id)
if (github := package.get("github")) is not None:
logger.info("Found GitHub repo: %s", github)
# strip subdirectory
github_repo = "/".join(github.split("/")[:2])
remote_id = RemoteID(attr="github", value=github_repo)
mxml.add_upstream_remote_id(remote_id)
if (git := package.get("git")) is not None:
logger.info("Found Git repo: %s", git)
if (remote_id := extract_remote_id(git)) is not None:
mxml.add_upstream_remote_id(remote_id)
@property
def active(self) -> bool:
return _HAS_PYYAML and self.package_yaml.is_file()

0
tests/hpack/__init__.py Normal file
View File

View File

@ -0,0 +1,9 @@
<pkgmetadata>
<upstream>
<maintainer>
<name>Simon Hengel</name>
<email>sol@typeful.net</email>
</maintainer>
<remote-id type="github">sol/hpack</remote-id>
</upstream>
</pkgmetadata>

View File

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Anna <cyber@sysrq.in>
SPDX-License-Identifier: CC0-1.0

View File

@ -0,0 +1,73 @@
name: hpack
version: 0.35.2
synopsis: A modern format for Haskell packages
description: See README at <https://github.com/sol/hpack#readme>
maintainer: Simon Hengel <sol@typeful.net>
github: sol/hpack
category: Development
extra-source-files:
- CHANGELOG.md
- resources/**/*
ghc-options: -Wall -fno-warn-incomplete-uni-patterns
dependencies:
- base >= 4.9 && < 5
- bytestring
- deepseq
- directory >= 1.2.5.0
- filepath
- Glob >= 0.9.0
- text
- containers
- unordered-containers
- yaml >= 0.10.0
- aeson >= 1.4.3.0
- scientific
- Cabal >= 3.0.0.0 && < 3.11
- pretty
- bifunctors
- cryptonite
- transformers
- http-types
- http-client
- http-client-tls
- vector
- infer-license >= 0.2.0 && < 0.3
# See https://github.com/haskell/network/pull/552.
when:
condition: impl(ghc >= 9.4.5) && os(windows)
dependencies: network >= 3.1.2.9
library:
source-dirs: src
exposed-modules:
- Hpack
- Hpack.Config
- Hpack.Render
- Hpack.Yaml
- Hpack.Error
executable:
main: Main.hs
source-dirs: driver
dependencies:
- hpack
tests:
spec:
cpp-options: -DTEST
main: Spec.hs
source-dirs:
- test
- src
dependencies:
- hspec == 2.*
- QuickCheck
- temporary
- mockery >= 0.3
- interpolate
- template-haskell
- HUnit >= 1.6.0.0
build-tools: hspec-discover

View File

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Simon Hengel <sol@typeful.net>
SPDX-License-Identifier: MIT

View File

View File

View File

@ -0,0 +1,5 @@
<pkgmetadata>
<upstream>
<remote-id type="github">commercialhaskell/stack</remote-id>
</upstream>
</pkgmetadata>

View File

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Anna <cyber@sysrq.in>
SPDX-License-Identifier: CC0-1.0

View File

@ -0,0 +1,422 @@
# Hpack >= 0.35.0 is provided by Stack >= 2.9.1.
spec-version: 0.35.0
name: stack
version: '2.12.0'
synopsis: The Haskell Tool Stack
description: |
Please see the documentation at <https://docs.haskellstack.org>
for usage information.
.
If building a 'stack' executable for distribution, please download the
source code from <https://github.com/commercialhaskell/stack/releases>
and build it using Stack itself in order to ensure identical behaviour
to official binaries. This package on Hackage is provided for convenience
and bootstrapping purposes.
.
Note that the API for the library is not currently stable, and may
change significantly, even between minor releases. It is
currently only intended for use by the executable.
category: Development
author: Commercial Haskell SIG
maintainer: manny@fpcomplete.com
license: BSD3
github: commercialhaskell/stack
homepage: http://haskellstack.org
custom-setup:
dependencies:
- base >= 4.14.3.0 && < 5
- Cabal < 3.10
- filepath
extra-source-files:
# note: leaving out 'package.yaml' because it causes confusion with hackage metadata revisions
- CONTRIBUTING.md
- ChangeLog.md
- README.md
- stack.yaml
- doc/*.md
- src/setup-shim/StackSetupShim.hs
- test/package-dump/ghc-7.10.txt
- test/package-dump/ghc-7.8.4-osx.txt
- test/package-dump/ghc-7.8.txt
- test/package-dump/ghc-head.txt
- src/test/Stack/Untar/test1.tar.gz
- src/test/Stack/Untar/test2.tar.gz
# Support for people who prefer, or need, to build Stack with Cabal (the tool):
- cabal.project
- cabal.config
# GHC's GHC2021 language extension is supported by GHC >= 9.2.1
language: GHC2021
ghc-options:
- -fwrite-ide-info
- -hiedir=.hie
- -Wall
- -Wmissing-export-lists
# Workaround for https://github.com/haskell/cabal/issues/4739.
# -Wnon-noportable-include-path is a Clang diagnostic flag. See
# https://clang.llvm.org/docs/DiagnosticsReference.html#wnonportable-include-path
- -optP-Wno-nonportable-include-path
dependencies:
- base >= 4.14.3.0 && < 5
- Cabal >= 3.8.1.0
- aeson >= 2.0.3.0
- ansi-terminal >= 1.0
- array
- async
- attoparsec
- base64-bytestring
- bytestring
- casa-client
- conduit
- conduit-extra
- containers
- cryptonite
- directory
- echo
- exceptions
- extra
- file-embed
- filelock
- filepath
- fsnotify >= 0.4.1
- generic-deriving
- hi-file-parser >= 0.1.4.0
- hpack
- hpc
- http-client
- http-client-tls
- http-conduit
- http-download
- http-types
- memory
- microlens
- mtl
- mustache
- neat-interpolation
- open-browser
- optparse-applicative >= 0.18.1.0
- pantry >= 0.8.2.2
- path
- path-io
# In order for Cabal (the tool) to build Stack, it needs to be told of the
# upper bound on persistent. See
# https://github.com/commercialhaskell/stack/pull/5677#issuecomment-1193318542
- persistent >= 2.14.0.0 && < 2.15
- persistent-sqlite
- pretty
- process >= 1.6.13.2
- project-template
- random
- rio >= 0.1.22.0
- rio-prettyprint >= 0.1.4.0
- split
- stm
- tar
- template-haskell
- text
- time
- transformers
- unix-compat
- unordered-containers
- vector
- yaml
- zlib
when:
- condition: os(windows)
then:
cpp-options: -DWINDOWS
dependencies:
- Win32
else:
verbatim: |
build-tool-depends:
hsc2hs:hsc2hs
dependencies:
- unix
# See https://github.com/haskell/network/pull/552.
- condition: impl(ghc >= 9.4.5) && os(windows)
dependencies: network >= 3.1.2.9
- condition: flag(developer-mode)
then:
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=True
else:
cpp-options: -DSTACK_DEVELOPER_MODE_DEFAULT=False
library:
source-dirs: src/
ghc-options:
- -Widentities
generated-exposed-modules:
- Paths_stack
exposed-modules:
- Control.Concurrent.Execute
- Data.Attoparsec.Args
- Data.Attoparsec.Combinators
- Data.Attoparsec.Interpreter
- Data.Monoid.Map
- Network.HTTP.StackClient
- Options.Applicative.Args
- Options.Applicative.Builder.Extra
- Options.Applicative.Complicated
- Path.CheckInstall
- Path.Extra
- Path.Find
- Stack.Build
- Stack.Build.Cache
- Stack.Build.ConstructPlan
- Stack.Build.Execute
- Stack.Build.Haddock
- Stack.Build.Installed
- Stack.Build.Source
- Stack.Build.Target
- Stack.BuildPlan
- Stack.Clean
- Stack.Config
- Stack.Config.Build
- Stack.Config.Docker
- Stack.Config.Nix
- Stack.ConfigCmd
- Stack.Constants
- Stack.Constants.Config
- Stack.Coverage
- Stack.DefaultColorWhen
- Stack.Docker
- Stack.DockerCmd
- Stack.Dot
- Stack.Eval
- Stack.Exec
- Stack.FileWatch
- Stack.GhcPkg
- Stack.Ghci
- Stack.Ghci.Script
- Stack.Hoogle
- Stack.IDE
- Stack.Init
- Stack.List
- Stack.Ls
- Stack.Lock
- Stack.New
- Stack.Nix
- Stack.Options.BenchParser
- Stack.Options.BuildMonoidParser
- Stack.Options.BuildParser
- Stack.Options.CleanParser
- Stack.Options.ConfigParser
- Stack.Options.Completion
- Stack.Options.DockerParser
- Stack.Options.DotParser
- Stack.Options.EvalParser
- Stack.Options.ExecParser
- Stack.Options.GhcBuildParser
- Stack.Options.GhciParser
- Stack.Options.GhcVariantParser
- Stack.Options.GlobalParser
- Stack.Options.HaddockParser
- Stack.Options.HpcReportParser
- Stack.Options.InitParser
- Stack.Options.LogLevelParser
- Stack.Options.LsParser
- Stack.Options.NewParser
- Stack.Options.NixParser
- Stack.Options.PackageParser
- Stack.Options.PathParser
- Stack.Options.ResolverParser
- Stack.Options.SDistParser
- Stack.Options.ScriptParser
- Stack.Options.SetupParser
- Stack.Options.TestParser
- Stack.Options.UpgradeParser
- Stack.Options.UploadParser
- Stack.Options.Utils
- Stack.Package
- Stack.PackageDump
- Stack.Path
- Stack.Prelude
- Stack.Query
- Stack.Runners
- Stack.Script
- Stack.SDist
- Stack.Setup
- Stack.Setup.Installed
- Stack.SetupCmd
- Stack.SourceMap
- Stack.Storage.Project
- Stack.Storage.User
- Stack.Storage.Util
- Stack.Templates
- Stack.Types.AddCommand
- Stack.Types.AllowNewerDeps
- Stack.Types.ApplyGhcOptions
- Stack.Types.ApplyProgOptions
- Stack.Types.Build
- Stack.Types.Build.Exception
- Stack.Types.BuildConfig
- Stack.Types.BuildOpts
- Stack.Types.CabalConfigKey
- Stack.Types.ColorWhen
- Stack.Types.CompilerBuild
- Stack.Types.CompilerPaths
- Stack.Types.Compiler
- Stack.Types.Config
- Stack.Types.Config.Exception
- Stack.Types.ConfigMonoid
- Stack.Types.ConfigureOpts
- Stack.Types.Curator
- Stack.Types.Docker
- Stack.Types.DockerEntrypoint
- Stack.Types.DownloadInfo
- Stack.Types.DumpLogs
- Stack.Types.DumpPackage
- Stack.Types.EnvConfig
- Stack.Types.EnvSettings
- Stack.Types.ExtraDirs
- Stack.Types.GHCDownloadInfo
- Stack.Types.GHCVariant
- Stack.Types.GhcOptionKey
- Stack.Types.GhcOptions
- Stack.Types.GhcPkgId
- Stack.Types.GlobalOpts
- Stack.Types.GlobalOptsMonoid
- Stack.Types.IsMutable
- Stack.Types.LockFileBehavior
- Stack.Types.NamedComponent
- Stack.Types.Nix
- Stack.Types.Package
- Stack.Types.PackageName
- Stack.Types.ParentMap
- Stack.Types.Platform
- Stack.Types.Project
- Stack.Types.ProjectAndConfigMonoid
- Stack.Types.ProjectConfig
- Stack.Types.PvpBounds
- Stack.Types.Resolver
- Stack.Types.Runner
- Stack.Types.SCM
- Stack.Types.SetupInfo
- Stack.Types.SourceMap
- Stack.Types.StackYamlLoc
- Stack.Types.TemplateName
- Stack.Types.UnusedFlags
- Stack.Types.Version
- Stack.Types.VersionedDownloadInfo
- Stack.Uninstall
- Stack.Unpack
- Stack.Update
- Stack.Upgrade
- Stack.Upload
- System.Info.ShortPathName
- System.Permissions
- System.Process.Pager
- System.Terminal
when:
- condition: 'os(windows)'
then:
source-dirs: src/windows/
else:
source-dirs: src/unix/
c-sources: src/unix/cbits/uname.c
executables:
stack:
main: Main.hs
source-dirs: src/main
generated-other-modules:
- Build_stack
- Paths_stack
ghc-options:
- -threaded
- -rtsopts
dependencies:
- stack
when:
- condition: flag(static)
ld-options:
- -static
- -pthread
- condition: ! '!(flag(disable-git-info))'
cpp-options: -DUSE_GIT_INFO
dependencies:
- githash
- optparse-simple
- condition: flag(hide-dependency-versions)
cpp-options: -DHIDE_DEP_VERSIONS
- condition: flag(supported-build)
cpp-options: -DSUPPORTED_BUILD
stack-integration-test:
main: IntegrationSpec.hs
source-dirs:
- test/integration
- test/integration/lib
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- filepath
- hspec
- optparse-generic
when:
- condition: ! '!(flag(integration-tests))'
buildable: false
- condition: flag(static)
ld-options:
- -static
- -pthread
tests:
stack-test:
main: Spec.hs
source-dirs: src/test
when:
- condition: 'os(windows)'
then:
source-dirs: src/test/windows/
else:
source-dirs: src/test/unix/
ghc-options:
- -threaded
dependencies:
- QuickCheck
- hspec
- raw-strings-qq
- stack
verbatim: |
build-tool-depends:
hspec-discover:hspec-discover
flags:
static:
description: >-
When building the Stack executable, or the stack-integration-test
executable, pass the -static and -pthread flags to the linker used by GHC.
manual: true
default: false
disable-git-info:
description: >-
Disable inclusion of current Git information in the Stack executable when
it is built.
manual: true
default: false
hide-dependency-versions:
description: >-
Hides dependency versions from 'stack --version'. Used only when building
a Stack executable for official release. Note to packagers/distributors:
DO NOT OVERRIDE THIS FLAG IF YOU ARE BUILDING STACK ANY OTHER WAY (e.g.
using Cabal or from Hackage), as it makes debugging support requests more
difficult.
manual: true
default: false
integration-tests:
description: Run the integration test suite.
manual: true
default: false
supported-build:
description: >-
If false, causes 'stack --version' to issue a warning about the build
being unsupported. Used only when building a Stack executable for official
release. Note to packagers/distributors: DO NOT OVERRIDE THIS FLAG IF YOU
ARE BUILDING STACK ANY OTHER WAY (e.g. using Cabal or from Hackage), as it
makes debugging support requests more difficult.
manual: true
default: false
developer-mode:
description: >-
By default, output extra developer information.
manual: true
default: false

View File

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2023 Commercial Haskell SIG
SPDX-License-Identifier: BSD

View File

@ -0,0 +1,40 @@
# SPDX-License-Identifier: WTFPL
# SPDX-FileCopyrightText: 2023 Anna <cyber@sysrq.in>
# No warranty
from copy import deepcopy
from pathlib import Path
import pytest
from gentle.generators.hpack import HpackGenerator
from gentle.metadata import MetadataXML
from tests.utils import compare_mxml
def test_pkg_none(mxml: MetadataXML):
gen = HpackGenerator(Path(__file__).parent / "pkg_none")
assert not gen.active
def test_pkg_empty(mxml: MetadataXML):
gen = HpackGenerator(Path(__file__).parent / "pkg_empty")
assert gen.active
mxml_old = deepcopy(mxml)
gen.update_metadata_xml(mxml)
assert compare_mxml(mxml_old, mxml) == ""
@pytest.mark.parametrize("dirname", ["hpack", "stack"])
def test_pkg(mxml: MetadataXML, dirname: str):
gen = HpackGenerator(Path(__file__).parent / dirname)
assert gen.active
gen.update_metadata_xml(mxml)
with open(Path(__file__).parent / dirname / "metadata.xml") as file:
assert mxml.dumps() == file.read().rstrip()
mxml_prev = deepcopy(mxml)
gen.update_metadata_xml(mxml)
assert compare_mxml(mxml_prev, mxml) == ""