mozilla / django-product-details

Product and locale details for Mozilla products
https://product-details.mozilla.org/1.0/
BSD 3-Clause "New" or "Revised" License
27 stars 22 forks source link

Mozilla Product Details for Django

|GHACI| |PyPI|

Product Details is a public JSON API and a repository <https://github.com/mozilla-releng/product-details/> containing information about the latest versions, localizations, etc. of Mozilla <http://www.mozilla.org> products (most notably Firefox, Firefox for mobile, and Thunderbird).

From the original README file <https://github.com/mozilla-releng/product-details/blob/main/README.rst>__:

::

Product Details is a public JSON API which contains release information
for Firefox (desktop and mobile) and Thunderbird. The data is managed by
the Release Management team through Ship-it and exported available at
this domain:

- https://product-details.mozilla.org/

Examples of data and files provided are listed on Product-Details wiki <https://wiki.mozilla.org/Release_Management/Product_details>__.

This is a Django <http://www.djangoproject.com/>__ app allowing this data to be used in Django projects. A Django management command can be used as a cron job or called manually to keep the data in sync with Mozilla.

Why?

The data provided by this API is meant to be the source of truth for all tools needing to know specific information about a Firefox release or channel.

Historically that data was managed with direct commits into a code repository on the Mozilla SVN server. The current version 1.0 of the API is meant to be fully compatible with the version previously hosted on SVN. The data source <https://github.com/mozilla-releng/product-details/>__ of Mozilla Product Details from the git repository is published to product-details.mozilla.org.

For Django projects, this app manages updates and caching of the data, and turns the JSON data into Python objects.

Getting Started

Installing


Install this library using ``pip``:

::

    pip install django-mozilla-product-details

... or by downloading the ``product_details`` directory and dropping it
into your django project.

Add ``product_details`` to your ``INSTALLED_APPS`` to enable the
management commands.

Configuration

No configuration should be necessary. However, you can add the following settings to your settings.py file if you disagree with the defaults:

You can further decide where the JSON data should be stored by using a storage backend class. There are 2 provided in the app currently, but it should be easy to create a subclass of product_details.storage.ProductDetailsStorage and store them wherever you like. The two provided are for the filesystem (the default) and the database. To configure which backend it uses set the following:

This app uses Django's cache framework to store the product data so that the data can be updated on the site without requiring a server restart. The following settings will allow you to control how this works.

Updating the feed


To update the data, execute this:

::

    ./manage.py update_product_details

You want to run this once manually after installing the app. To
periodically pull in new data, you can make this a cron job.

**Note:** Please be considerate of the server when adding a cron job.
The data does not change often enough to warrant an update every minute
or so. Most applications will run perfectly fine if you pull new data
once a day or even less frequently. When in doubt, contact the author of
this library.

Using the data

To use the data, just import the library:

::

from product_details import product_details

The library turns all imported JSON files automatically into Python objects. The contents are perhaps best inspected using IPython <http://ipython.scipy.org/>__.

Version Compare

Product details comes with an implementation of version comparison code for Mozilla-style product versions. Use it like this:

::

>>> from product_details.version_compare import Version
>>> v1 = Version('4.0b10')
>>> v2 = Version('4.0b10pre')
>>> v1 < v2
False

The second useful part of the version compare code is generating a list of unique versions, sorted by their release date, like this:

::

>>> from product_details import product_details
>>> from product_details.version_compare import version_list
>>> version_list(product_details.firefox_history_development_releases)
['3.6.4', '3.6.3', '3.6', '3.6b5', '3.6b4', '3.6b3', '3.6b2', ... ]

Caveats / Known Issues

  1. While the management task will not overwrite existing files if the server returns bogus data (i.e., an empty document or unparseable JSON data), this library will also never delete a JSON file that was completely removed from the server. This is unlikely to happen very often, though.
  2. You don't want to import product_details in settings.py as that would cause an import loop (since product_details itself imports django.conf.settings). However, if you must, you can lazily wrap the import like this, mitigating the problem:

    ::

    from django.utils.functional import lazy

    MY_LANGUAGES = ('en-US', 'de') class LazyLangs(list): def new(self): from product_details import product_details return [(lang.lower(), product_details.languages[lang]['native']) for lang in MY_LANGUAGES] LANGUAGES = lazy(LazyLangs, list)()

  3. Using product_details before Django has finished initializing, e.g. in your app's __init__.py it may raise a django.core.exceptions.AppRegistryNotReady exception. The lazy loading example from above should help you overcome this issue.

Development

Patches are welcome.

To run tests, install tox and run tox from the project root. This will run the tests in Python 3.7, 3.8 and 3.9 against various appropriate Django versions. If you don't have tox and/or all the versions of Python available, install nose, mock, requests, responses and Django (see tox.ini's deps) and run the tests in your current Python version by running ./runtests.py.

.. |PyPI| image:: https://img.shields.io/pypi/v/django-mozilla-product-details.svg :target: https://pypi.python.org/pypi/django-mozilla-product-details

.. |GHACI| image:: https://github.com/mozilla/django-product-details/actions/workflows/ci.yml/badge.svg :target: https://github.com/mozilla/django-product-details/actions

Releasing

  1. Update the version number in product_details/__init__.py.
  2. Add an entry to the change log in the README file.
  3. Tag the commit where you changed the above with the version number: e.g. 1.0.4.
  4. Push the commit and tag to the github repo.
  5. Create a new GitHub release, selecting the tag you just pushed to specify the commit. Hit Publish.
  6. Github will build and release the package to PyPI. Monitor the progress via the Actions tab.

Note, if you need to manually build a release on your local machine, be sure to run python updatejson.py before you run python -m build . so that the JSON data files are definitely included in the artifacts you generate.

Change Log

1.0.3 - 2022-03-08


- Previous release(s) did not contain product-details data. This release does include a copy of the data.

1.0.2 - 2022-01-31

1.0.1 - 2022-01-13


- Updates to be able to handle Firefox versions over 100. Thanks robhudson!

1.0.0 - 2022-01-07

Thanks to stevejalim and tasos for these improvements.

0.14.1 - 2019-06-03


- Add back last-modified data for directory lists in the data to avoid migration failure.

0.14 - 2019-05-28

0.13.1 - 2019-03-03


- Tweak a migration to make Django 2+ under Python 3 happy. Fixes #68. Thanks peterbe!

0.13 - 2017-08-30

0.12.1 - 2016-08-18


- Add --database option to management command to allow data to be updated
  in a configured database other than "default".

0.12 - 2016-07-29

0.11.1 - 2016-04-08


- Include updated JSON data in the release. A problem with deployment in Travis resulted in 0.11
  failing to include the data.

0.11 - 2016-04-08

Thanks to jgmize for both of these improvements!

0.10 - 2016-01-25


- Use requests lib to fetch remote data for reliability and better Py3k compatibility.
- Update management command to avoid Django 1.9 deprecation warnings. Django 1.8 is now the minimum supported version.

Thanks to Osmose for both of these improvements!

0.9 - 2015-12-28

0.8.2 - 2015-12-22


- Use HTTPS by default to fetch JSON data. Thanks jvehent!
- Fix product_details.last_update property. It's been broken since 0.8. Thanks for the report diox!

0.8.1 - 2015-10-07

0.8 - 2015-09-30


- Add configurable json data file storage backends.
- Add filesystem and database backends.

0.7.1 - 2015-06-15

0.7 - 2015-05-22


-  Use the Django cache framework to store product data, allowing data to be
   updated without a server restart.
-  Add and update tests, setup tox for testing across Python and Django versions,
   and setup Travis for CI.

0.6 - 2015-05-08