From f02e6e2c3175e41152691bbed4a01f32423770d8 Mon Sep 17 00:00:00 2001 From: Felix Yan Date: Thu, 3 Dec 2015 11:19:58 +0800 Subject: [PATCH] Add support for Packagist (Composer) --- README.rst | 8 ++++++++ nvchecker/get_version.py | 2 +- nvchecker/source/packagist.py | 15 +++++++++++++++ tests/test_packagist.py | 6 ++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 nvchecker/source/packagist.py create mode 100644 tests/test_packagist.py diff --git a/README.rst b/README.rst index 40a8773..272cd2e 100644 --- a/README.rst +++ b/README.rst @@ -31,6 +31,7 @@ Contents * `Check NPM Registry <#check-npm-registry>`_ * `Check Hackage <#check-hackage>`_ * `Check CPAN <#check-cpan>`_ + * `Check Packagist <#check-packagist>`_ * `Check Local Pacman Database <#check-local-pacman-database>`_ * `Check Arch Linux official packages <#check-arch-linux-official-packages>`_ * `Check Google Code (hg repository) <#check-google-code-hg-repository>`_ @@ -258,6 +259,13 @@ Check `MetaCPAN `_ for updates. cpan The name used on CPAN, e.g. ``YAML``. +Check Packagist +-------------- +Check `Packagist `_ for updates. + +packagist + The name used on Packagist, e.g. ``monolog/monolog``. + Check Local Pacman Database --------------------------- This is used when you run ``nvchecker`` on an Arch Linux system and the program always keeps up with a package in your configured repositories for `Pacman`_. diff --git a/nvchecker/get_version.py b/nvchecker/get_version.py index c403d8e..ef7a859 100644 --- a/nvchecker/get_version.py +++ b/nvchecker/get_version.py @@ -5,7 +5,7 @@ logger = logging.getLogger(__name__) handler_precedence = ( 'github', 'gitcafe', 'aur', 'pypi', 'archpkg', 'gems', 'pacman', 'cmd', 'bitbucket', 'gcode_hg', 'gcode_svn', 'regex', 'manual', 'vcs', - 'npm', 'hackage', 'cpan', 'gitlab', + 'npm', 'hackage', 'cpan', 'gitlab', 'packagist' ) def get_version(name, conf, callback): diff --git a/nvchecker/source/packagist.py b/nvchecker/source/packagist.py new file mode 100644 index 0000000..2abe89a --- /dev/null +++ b/nvchecker/source/packagist.py @@ -0,0 +1,15 @@ +from .simple_json import simple_json + +PACKAGIST_URL = 'https://packagist.org/packages/%s.json' + +def _version_from_json(data): + data = {version: details for version, details in data["package"]['versions'].items() if version != "dev-master"} + + if len(data): + return max(data, key=lambda version: data[version]["time"]) + +get_version = simple_json( + PACKAGIST_URL, + 'packagist', + _version_from_json, +) diff --git a/tests/test_packagist.py b/tests/test_packagist.py new file mode 100644 index 0000000..9145fd3 --- /dev/null +++ b/tests/test_packagist.py @@ -0,0 +1,6 @@ +from tests.helper import ExternalVersionTestCase + + +class PackagistTest(ExternalVersionTestCase): + def test_packagist(self): + self.assertEqual(self.sync_get_version("butterfly/example-web-application", {"packagist": None}), "1.2.0")