Skip to content
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 wheel/python-version/python-implementation/status badage for PyPI. #465

Merged
merged 4 commits into from
Jun 7, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,73 @@ cache(function(data, match, sendBadge, request) {
badgeData.colorscheme = 'blue';
}
sendBadge(format, badgeData);
} else if (info == 'wheel') {
var releases = data.releases[data.info.version];
var hasWheel = false;
for (var i in releases) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, there.

if (releases[i].packagetype == 'wheel' ||
releases[i].packagetype == 'bdist_wheel') {
hasWheel = true;
break;
}
}
badgeData.text[0] = 'wheel';
badgeData.text[1] = hasWheel ? 'yes' : 'no';
badgeData.colorscheme = hasWheel ? 'brightgreen' : 'red';
sendBadge(format, badgeData);
} else if (info == 'py_versions') {
var versions = [];
var pattern = /^Programming Language \:\: Python \:\: (\d\.\d)$/;
for (var i in data.info.classifiers) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use a regular loop here too?

var matched = pattern.exec(data.info.classifiers[i]);
if (matched && matched[1]) {
versions.push(matched[1]);
}
}
if (!versions.length) {
versions.push('not found');
}
badgeData.text[0] = 'python';
badgeData.text[1] = versions.sort().join(', ');
badgeData.colorscheme = 'blue';
sendBadge(format, badgeData);
} else if (info == 'implementation') {
var implementations = [];
var pattern = /^Programming Language \:\: Python \:\: Implementation \:\: (\S+)$/;
for (var i in data.info.classifiers) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use a regular loop here, please?

for (var i = 0; i < data.info.classifiers.length; i++) {

}

(Yes, I agree, JS is ugly compared to Python ☺.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

var matched = pattern.exec(data.info.classifiers[i]);
if (matched && matched[1]) {
implementations.push(matched[1].toLowerCase());
}
}
if (!implementations.length) {
implementations.push('cpython'); // assume CPython
}
badgeData.text[0] = 'implementation';
badgeData.text[1] = implementations.sort().join(', ');
badgeData.colorscheme = 'blue';
sendBadge(format, badgeData);
} else if (info == 'status') {
var pattern = /^Development Status \:\: ([1-7]) - (\S+)$/;
var statusColors = {
'1': 'red', '2': 'red', '3': 'red', '4': 'yellow',
'5': 'brightgreen', '6': 'brightgreen', '7': 'red'};
var statusCode = '1', statusText = 'unknown';
for (var i in data.info.classifiers) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and here as well.

var matched = pattern.exec(data.info.classifiers[i]);
if (matched && matched[1] && matched[2]) {
statusCode = matched[1];
statusText = matched[2].toLowerCase().replace('-', '--');
if (statusText == 'production/stable') {
statusText = 'stable';
}
break;
}
}
badgeData.text[0] = 'status';
badgeData.text[1] = statusText;
badgeData.colorscheme = statusColors[statusCode];
sendBadge(format, badgeData);
}
} catch(e) {
badgeData.text[1] = 'invalid';
Expand Down
16 changes: 16 additions & 0 deletions try.html
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,22 @@ <h3 id="miscellaneous"> Miscellaneous </h3>
<td><img src='/pypi/l/Django.svg' alt=''/></td>
<td><code>https://img.shields.io/pypi/l/Django.svg</code></td>
</tr>
<tr><th data-keywords='python'> PyPI: </th>
<td><img src='/pypi/wheel/Django.svg' alt=''/></td>
<td><code>https://img.shields.io/pypi/wheel/Django.svg</code></td>
</tr>
<tr><th data-keywords='python'> PyPI: </th>
<td><img src='/pypi/py_versions/Django.svg' alt=''/></td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are using pyversions above. Which do you prefer?

(I have a personal preference to pyversions, but I'm not well-versed in the python community.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry. I forgot it. It will be fixed :-)

<td><code>https://img.shields.io/pypi/py_versions/Django.svg</code></td>
</tr>
<tr><th data-keywords='python'> PyPI: </th>
<td><img src='/pypi/implementation/Django.svg' alt=''/></td>
<td><code>https://img.shields.io/pypi/implementation/Django.svg</code></td>
</tr>
<tr><th data-keywords='python'> PyPI: </th>
<td><img src='/pypi/status/Django.svg' alt=''/></td>
<td><code>https://img.shields.io/pypi/status/Django.svg</code></td>
</tr>
<tr><th> Hex.pm: </th>
<td><img src='/hexpm/l/plug.svg' alt=''/></td>
<td><code>https://img.shields.io/hexpm/l/plug.svg</code></td>
Expand Down