add support for crates.io
This commit is contained in:
parent
b9f5a1e476
commit
375fb4f14f
|
@ -5,7 +5,7 @@ logger = logging.getLogger(__name__)
|
||||||
handler_precedence = (
|
handler_precedence = (
|
||||||
'github', 'gitcafe', 'aur', 'pypi', 'archpkg', 'gems', 'pacman',
|
'github', 'gitcafe', 'aur', 'pypi', 'archpkg', 'gems', 'pacman',
|
||||||
'cmd', 'bitbucket', 'gcode_hg', 'gcode_svn', 'regex', 'manual', 'vcs',
|
'cmd', 'bitbucket', 'gcode_hg', 'gcode_svn', 'regex', 'manual', 'vcs',
|
||||||
'npm', 'hackage', 'cpan', 'gitlab', 'packagist'
|
'cratesio', 'npm', 'hackage', 'cpan', 'gitlab', 'packagist'
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_version(name, conf, callback):
|
def get_version(name, conf, callback):
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
|
||||||
|
|
||||||
|
from ..sortversion import sort_version_keys
|
||||||
|
|
||||||
|
API_URL = 'https://crates.io/api/v1/crates/%s'
|
||||||
|
|
||||||
|
def get_version(name, conf, callback):
|
||||||
|
name = conf.get('cratesio') or name
|
||||||
|
request = HTTPRequest(API_URL % name, user_agent='lilydjwg/nvchecker')
|
||||||
|
AsyncHTTPClient().fetch(
|
||||||
|
request,
|
||||||
|
callback = partial(_cratesio_done, name, callback),
|
||||||
|
)
|
||||||
|
|
||||||
|
def _cratesio_done(name, callback, res):
|
||||||
|
data = json.loads(res.body.decode('utf-8'))
|
||||||
|
version = [v['num'] for v in data['versions'] if not v['yanked']][0]
|
||||||
|
callback(name, version)
|
|
@ -0,0 +1,8 @@
|
||||||
|
from tests.helper import ExternalVersionTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class CratesIOTest(ExternalVersionTestCase):
|
||||||
|
def test_npm(self):
|
||||||
|
self.assertEqual(
|
||||||
|
self.sync_get_version("example", {"cratesio": None}),
|
||||||
|
"0.1.0")
|
Loading…
Reference in New Issue