Skip to content

Commit

Permalink
Add [PypiTypes] badge (#10774)
Browse files Browse the repository at this point in the history
* add python typing badge

* prettier

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

Co-authored-by: jNullj <[email protected]>

* address comments

* rename

* fix test

---------

Co-authored-by: jNullj <[email protected]>
  • Loading branch information
yangdanny97 and jNullj authored Dec 31, 2024
1 parent 85b44b9 commit bf91e26
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
40 changes: 40 additions & 0 deletions services/pypi/pypi-types.service.js
Original file line number Diff line number Diff line change
@@ -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 })
}
}
14 changes: 14 additions & 0 deletions services/pypi/pypi-types.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createServiceTester } from '../tester.js'
export const t = await createServiceTester()

t.create('types (yes)')
.get('/pyre-check.json')
.expectBadge({ label: 'types', message: 'typed' })

t.create('types (no)')
.get('/z3-solver.json')
.expectBadge({ label: 'types', message: 'untyped' })

t.create('types (invalid)')
.get('/not-a-package.json')
.expectBadge({ label: 'types', message: 'package or version not found' })

0 comments on commit bf91e26

Please sign in to comment.