ENH Use dist-info + `importlib.metadata` to store and retrieve package metadata. This switches to using the file system to store the information about packages
and using `importlib.metadata` to retrieve it.
This has two related benefits:

1. We don't have to separately maintain our own separate state about what
we've installed.

2. We are guaranteed to agree with the Python stdlib about whether or not a
package is installed, and if so which version is installed. Since the state is 
maintained in only one place, there is no chance of it diverging.

According to the packaging specs, if the package is from a url we should put 
that into a file here:
https://packaging.python.org/en/latest/specifications/direct-url/#direct-url
Other than that, we should set the `INSTALLER` to `pyodide.loadPackage` 
if the package was loaded with `pyodide.loadPackage` either directly or 
indirectly via `micropip`. Otherwise set `INSTALLER` to `micropip`. That
way we can maintain the current behavior of `micropip.list`:
1. if `direct_url.json` is present, then `source` is the url in `direct_url.json`
2. otherwise, set `source` to `pyodide` if `INSTALLER` is `pyodide.loadPackage`
and set it to `micropip` if `INSTALLER` is `micropip`.

Oddly enough, the packaging specs suggest no place to put the source
index, so it seems that according to the specs if a package was installed
by name from some custom index, this info should not be recorded.

### Checklists

- [x] Add a [CHANGELOG](https://github.com/pyodide/pyodide/blob/main/docs/project/changelog.md) entry
- [x] Add / update tests

import pytest


def test_optlang(selenium):
    selenium.load_package("optlang")
    selenium.run(
        """
        from optlang import Model, Variable, Constraint, Objective

        # All the (symbolic) variables are declared, with a name and optionally a lower and/or upper bound.
        x1 = Variable('x1', lb=0)
        x2 = Variable('x2', lb=0)
        x3 = Variable('x3', lb=0)

        # A constraint is constructed from an expression of variables and a lower and/or upper bound (lb and ub).
        c1 = Constraint(x1 + x2 + x3, ub=100)
        c2 = Constraint(10 * x1 + 4 * x2 + 5 * x3, ub=600)
        c3 = Constraint(2 * x1 + 2 * x2 + 6 * x3, ub=300)

        # An objective can be formulated
        obj = Objective(10 * x1 + 6 * x2 + 4 * x3, direction='max')

        # Variables, constraints and objective are combined in a Model object, which can subsequently be optimized.
        model = Model(name='Simple model')
        model.objective = obj
        model.add([c1, c2, c3])

        status = model.optimize()
        """
    )
    result = selenium.run("model.status")
    assert result == "optimal"
    result = selenium.run("model.objective.value")
    assert result == pytest.approx(733.3333, abs=1e-4)
    result = selenium.run("model.variables['x1'].primal")
    assert result == pytest.approx(33.3333, abs=1e-4)
    result = selenium.run("model.variables['x2'].primal")
    assert result == pytest.approx(66.6667, abs=1e-4)
    result = selenium.run("model.variables['x3'].primal")
    assert result == pytest.approx(0.0000, abs=1e-4)

import pytest


def test_optlang(selenium):
    selenium.load_package("optlang")
    selenium.run(
        """
        from optlang import Model, Variable, Constraint, Objective

        # All the (symbolic) variables are declared, with a name and optionally a lower and/or upper bound.
        x1 = Variable('x1', lb=0)
        x2 = Variable('x2', lb=0)
        x3 = Variable('x3', lb=0)

        # A constraint is constructed from an expression of variables and a lower and/or upper bound (lb and ub).
        c1 = Constraint(x1 + x2 + x3, ub=100)
        c2 = Constraint(10 * x1 + 4 * x2 + 5 * x3, ub=600)
        c3 = Constraint(2 * x1 + 2 * x2 + 6 * x3, ub=300)

        # An objective can be formulated
        obj = Objective(10 * x1 + 6 * x2 + 4 * x3, direction='max')

        # Variables, constraints and objective are combined in a Model object, which can subsequently be optimized.
        model = Model(name='Simple model')
        model.objective = obj
        model.add([c1, c2, c3])

        status = model.optimize()
        """
    )
    result = selenium.run("model.status")
    assert result == "optimal"
    result = selenium.run("model.objective.value")
    assert result == pytest.approx(733.3333, abs=1e-4)
    result = selenium.run("model.variables['x1'].primal")
    assert result == pytest.approx(33.3333, abs=1e-4)
    result = selenium.run("model.variables['x2'].primal")
    assert result == pytest.approx(66.6667, abs=1e-4)
    result = selenium.run("model.variables['x3'].primal")
    assert result == pytest.approx(0.0000, abs=1e-4)
