For now, only one `pyodide` can be loaded in a given global scope because we need to use a global variable for package loading. This changes `loadPyodide` so that it no longer defines `globalThis.pyodide` in favor of just returning `pyodide` from `loadPyodide`. `Module` is placed on the global object as `globalThis.__pyodide_module` for the purposes of package loading. I added documentation to explicitly state that `loadPyodide` can only be run once in each global Javascript context, an error will be thrown otherwise.

This has two advantages: 
1. The returned `pyodide` module is understandable to Typescript and other code analysis, whereas the global variable is not understandable.
2. If in the future we are able to remove the global variable, no further API change will be needed (other than relaxing the documented "pyodide must be globally-unique" constraint). I figure it's better to make this API change earlier rather than later.

It will be possible to completely remove the global variable dependence when Firefox implements support for using ES6 modules in webworkers (see https://bugzilla.mozilla.org/show_bug.cgi?id=1247687).
API Don't expose pyodide as a global variable in loadPyodide. For now, only one `pyodide` can be loaded in a given global scope because we need to use a global variable for package loading. This changes `loadPyodide` so that it no longer defines `globalThis.pyodide` in favor of just returning `pyodide` from `loadPyodide`. `Module` is placed on the global object as `globalThis.__pyodide_module` for the purposes of package loading. I added documentation to explicitly state that `loadPyodide` can only be run once in each global Javascript context, an error will be thrown otherwise.

This has two advantages: 
1. The returned `pyodide` module is understandable to Typescript and other code analysis, whereas the global variable is not understandable.
2. If in the future we are able to remove the global variable, no further API change will be needed (other than relaxing the documented "pyodide must be globally-unique" constraint). I figure it's better to make this API change earlier rather than later.

It will be possible to completely remove the global variable dependence when Firefox implements support for using ES6 modules in webworkers (see https://bugzilla.mozilla.org/show_bug.cgi?id=1247687).
import sys
from pathlib import Path

sys.path.append(str(Path(__file__).parents[2]))

from pyodide_build.common import (
    _parse_package_subset,
    get_make_flag,
    get_make_environment_vars,
)  # noqa


def test_parse_package_subset():
    assert _parse_package_subset(None) is None
    # micropip is always included
    assert _parse_package_subset("numpy,pandas") == {
        "pyparsing",
        "packaging",
        "micropip",
        "numpy",
        "pandas",
    }

    # duplicates are removed
    assert _parse_package_subset("numpy,numpy") == {
        "pyparsing",
        "packaging",
        "micropip",
        "numpy",
    }

    # no empty package name included, spaces are handled
    assert _parse_package_subset("x,  a, b, c   ,,, d,,") == {
        "pyparsing",
        "packaging",
        "micropip",
        "x",
        "a",
        "b",
        "c",
        "d",
    }


def test_get_make_flag():
    assert len(get_make_flag("SIDE_MODULE_LDFLAGS")) > 0
    assert len(get_make_flag("SIDE_MODULE_CFLAGS")) > 0
    # n.b. right now CXXFLAGS is empty so don't check length here, just check it returns
    get_make_flag("SIDE_MODULE_CXXFLAGS")


def test_get_make_environment_vars():
    vars = get_make_environment_vars()
    assert "SIDE_MODULE_LDFLAGS" in vars
    assert "SIDE_MODULE_CFLAGS" in vars
    assert "SIDE_MODULE_CXXFLAGS" in vars
    assert "TOOLSDIR" in vars

import sys
from pathlib import Path

sys.path.append(str(Path(__file__).parents[2]))

from pyodide_build.common import (
    _parse_package_subset,
    get_make_flag,
    get_make_environment_vars,
)  # noqa


def test_parse_package_subset():
    assert _parse_package_subset(None) is None
    # micropip is always included
    assert _parse_package_subset("numpy,pandas") == {
        "pyparsing",
        "packaging",
        "micropip",
        "numpy",
        "pandas",
    }

    # duplicates are removed
    assert _parse_package_subset("numpy,numpy") == {
        "pyparsing",
        "packaging",
        "micropip",
        "numpy",
    }

    # no empty package name included, spaces are handled
    assert _parse_package_subset("x,  a, b, c   ,,, d,,") == {
        "pyparsing",
        "packaging",
        "micropip",
        "x",
        "a",
        "b",
        "c",
        "d",
    }


def test_get_make_flag():
    assert len(get_make_flag("SIDE_MODULE_LDFLAGS")) > 0
    assert len(get_make_flag("SIDE_MODULE_CFLAGS")) > 0
    # n.b. right now CXXFLAGS is empty so don't check length here, just check it returns
    get_make_flag("SIDE_MODULE_CXXFLAGS")


def test_get_make_environment_vars():
    vars = get_make_environment_vars()
    assert "SIDE_MODULE_LDFLAGS" in vars
    assert "SIDE_MODULE_CFLAGS" in vars
    assert "SIDE_MODULE_CXXFLAGS" in vars
    assert "TOOLSDIR" in vars
