-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add [PythonVersionFromToml] shield #9516
Merged
chris48s
merged 6 commits into
badges:master
from
jNullj:feat/9410/python-versions-toml
Sep 10, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
43a171b
Add PythonVersionFromToml
jNullj 97b418d
Add tests for PythonVersionFromToml
jNullj 05702d5
Improve docs for tests regex
jNullj e2ecbf5
Improve title and description
jNullj b3de30f
replace complex regex with @renovate/pep440
jNullj 4e86c49
Merge branch 'master' into feat/9410/python-versions-toml
jNullj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import Joi from 'joi' | ||
import BaseTomlService from '../../core/base-service/base-toml.js' | ||
import { optionalUrl } from '../validators.js' | ||
|
||
const queryParamSchema = Joi.object({ | ||
tomlFilePath: optionalUrl.required(), | ||
}).required() | ||
|
||
const schema = Joi.object({ | ||
project: Joi.object({ | ||
'requires-python': Joi.string().required(), | ||
}).required(), | ||
}).required() | ||
|
||
const documentation = `Shows the required python version for a package based on the values in the requires-python field in PEP 621 compliant pyproject.toml \n | ||
a URL of the toml is required, please note that when linking to files in github or similar sites, provide URL to raw file, for example: | ||
|
||
Use https://raw.githubusercontent.com/numpy/numpy/main/pyproject.toml \n | ||
And not https://github.com/numpy/numpy/blob/main/pyproject.toml | ||
` | ||
|
||
class PythonVersionFromToml extends BaseTomlService { | ||
static category = 'platform-support' | ||
|
||
static route = { | ||
base: '', | ||
pattern: 'python/required-version-toml', | ||
queryParamSchema, | ||
} | ||
|
||
static examples = [ | ||
{ | ||
title: 'Python Version from PEP 621 TOML', | ||
namedParams: {}, | ||
queryParams: { | ||
tomlFilePath: | ||
'https://raw.githubusercontent.com/numpy/numpy/main/pyproject.toml', | ||
}, | ||
staticPreview: this.render({ requiresPythonString: '>=3.9' }), | ||
documentation, | ||
}, | ||
] | ||
|
||
static defaultBadgeData = { label: 'python' } | ||
|
||
static render({ requiresPythonString }) { | ||
// we only show requries-python as is | ||
// for more info read the following issues: | ||
// https://github.com/badges/shields/issues/9410 | ||
// https://github.com/badges/shields/issues/5551 | ||
return { | ||
message: requiresPythonString, | ||
color: 'blue', | ||
} | ||
} | ||
|
||
async handle(namedParams, { tomlFilePath }) { | ||
const tomlData = await this._requestToml({ url: tomlFilePath, schema }) | ||
const requiresPythonString = tomlData.project['requires-python'] | ||
|
||
return this.constructor.render({ requiresPythonString }) | ||
} | ||
} | ||
|
||
export { PythonVersionFromToml } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Joi from 'joi' | ||
import pep440 from '@renovate/pep440' | ||
import { createServiceTester } from '../tester.js' | ||
export const t = await createServiceTester() | ||
|
||
const validatePep440 = (value, helpers) => { | ||
if (!pep440.validRange(value)) { | ||
return helpers.error('any.invalid') | ||
} | ||
return value | ||
} | ||
|
||
const isCommaSeparatedPythonVersions = Joi.string().custom(validatePep440) | ||
|
||
t.create('python versions (valid)') | ||
.get( | ||
'/python/required-version-toml.json?tomlFilePath=https://raw.githubusercontent.com/numpy/numpy/main/pyproject.toml', | ||
) | ||
.expectBadge({ label: 'python', message: isCommaSeparatedPythonVersions }) | ||
|
||
t.create( | ||
'python versions - valid toml with missing python-requires field (invalid)', | ||
) | ||
.get( | ||
'/python/required-version-toml.json?tomlFilePath=https://raw.githubusercontent.com/django/django/main/pyproject.toml', | ||
) | ||
.expectBadge({ label: 'python', message: 'invalid response data' }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have an answer for this at the moment, but I'm wondering where this should live.
Python isn't really a "service". Neither is "pyproject.toml".
We've got a bunch of other badges knocking about under /github that just read a file on GitHub. We've talked before about converting them to work like this so you can just pass a URL in as a query param. Then they could work for files hosted elsewhere. I wonder if it makes sense to lump them together as a "service".
I need to have a think about this one. Any other maintainers got a view on what a sensible route would be for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not sure myself, i used SecurityHeaders as reference and saw it used an empty base route.
What should we do with that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it isn't really about the empty base. It is more that our URL schema assumes the first part of the route is a service, but there's no service here.
Given nobody else has chimed in on this, I think I'm going to merge this but note this as a consideration in #5343