1
0
mirror of https://github.com/badges/shields.git synced 2025-11-28 18:04:09 +03:00

Add [PypiTypes] badge (#10774)

* add python typing badge

* prettier

* Update services/pypi/pypi-typing.service.js

Co-authored-by: jNullj <15849761+jNullj@users.noreply.github.com>

* address comments

* rename

* fix test

---------

Co-authored-by: jNullj <15849761+jNullj@users.noreply.github.com>
This commit is contained in:
Danny Yang
2024-12-31 11:33:36 -05:00
committed by GitHub
parent 85b44b9152
commit bf91e268d6
2 changed files with 54 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
import PypiBase, { pypiGeneralParams } from './pypi-base.js'
export default class PypiTypes extends PypiBase {
static category = 'platform-support'
static route = this.buildRoute('pypi/types')
static openApi = {
'/pypi/types/{packageName}': {
get: {
summary: 'PyPI - Types',
description:
'Whether the package provides type information, as indicated by the presence of the Typing :: Typed classifier in the package metadata',
parameters: pypiGeneralParams,
},
},
}
static defaultBadgeData = { label: 'types' }
static render({ isTyped }) {
if (isTyped) {
return {
message: 'typed',
color: 'brightgreen',
}
} else {
return {
message: 'untyped',
color: 'red',
}
}
}
async handle({ egg }, { pypiBaseUrl }) {
const packageData = await this.fetch({ egg, pypiBaseUrl })
const isTyped = packageData.info.classifiers.includes('Typing :: Typed')
return this.constructor.render({ isTyped })
}
}