Skip to content

Commit

Permalink
Mark Stubs-only packages with [PypiTypes] badge (#10864)
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

* check Typing :: Stubs Only

* change test package to typeshed

---------

Co-authored-by: jNullj <[email protected]>
  • Loading branch information
yangdanny97 and jNullj authored Feb 2, 2025
1 parent 4d9de9f commit 94909ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 11 additions & 3 deletions services/pypi/pypi-types.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ export default class PypiTypes extends PypiBase {
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',
'Type information provided by the package, as indicated by the presence of the `Typing :: Typed` and `Typing :: Stubs Only` classifiers in the package metadata',
parameters: pypiGeneralParams,
},
},
}

static defaultBadgeData = { label: 'types' }

static render({ isTyped }) {
static render({ isTyped, isStubsOnly }) {
if (isTyped) {
return {
message: 'typed',
color: 'brightgreen',
}
} else if (isStubsOnly) {
return {
message: 'stubs',
color: 'brightgreen',
}
} else {
return {
message: 'untyped',
Expand All @@ -35,6 +40,9 @@ export default class PypiTypes extends PypiBase {
async handle({ egg }, { pypiBaseUrl }) {
const packageData = await this.fetch({ egg, pypiBaseUrl })
const isTyped = packageData.info.classifiers.includes('Typing :: Typed')
return this.constructor.render({ isTyped })
const isStubsOnly = packageData.info.classifiers.includes(
'Typing :: Stubs Only',
)
return this.constructor.render({ isTyped, isStubsOnly })
}
}
4 changes: 4 additions & 0 deletions services/pypi/pypi-types.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ t.create('types (no)')
.get('/z3-solver.json')
.expectBadge({ label: 'types', message: 'untyped' })

t.create('types (stubs)')
.get('/types-requests.json')
.expectBadge({ label: 'types', message: 'stubs' })

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

0 comments on commit 94909ab

Please sign in to comment.