Avoid duplicates in the list of built packages

This commit is contained in:
Roman Yurchak 2020-05-12 12:33:20 +02:00
parent d02a96ece4
commit 4dc422e2ab
3 changed files with 14 additions and 8 deletions

View File

@ -106,7 +106,8 @@ def make_parser(parser):
help='The path to the target Python installation') help='The path to the target Python installation')
parser.add_argument( parser.add_argument(
'--only', type=str, nargs='?', default=None, '--only', type=str, nargs='?', default=None,
help='Only build the specified packages') help=('Only build the specified packages, provided as a comma '
'separated list'))
return parser return parser

View File

@ -1,5 +1,5 @@
from pathlib import Path from pathlib import Path
from typing import Optional, List from typing import Optional, Set
ROOTDIR = Path(__file__).parents[1].resolve() / 'tools' ROOTDIR = Path(__file__).parents[1].resolve() / 'tools'
@ -27,17 +27,17 @@ def parse_package(package):
return yaml.load(fd) return yaml.load(fd)
def _parse_package_subset(query: Optional[str]) -> Optional[List[str]]: def _parse_package_subset(query: Optional[str]) -> Optional[Set[str]]:
"""Parse the list of packages specified with PYODIDE_PACKAGES env var. """Parse the list of packages specified with PYODIDE_PACKAGES env var.
Also add the list of mandatory packages: ['micropip', 'distlib'] Also add the list of mandatory packages: ['micropip', 'distlib']
Returns: Returns:
a list of package names to build or None. The list may contain duplicate a set of package names to build or None.
values.
""" """
if query is None: if query is None:
return None return None
packages = query.split(',') packages = query.split(',')
packages = [el.strip() for el in packages] packages = [el.strip() for el in packages]
return ['micropip', 'distlib'] + packages packages = ['micropip', 'distlib'] + packages
return set(packages)

View File

@ -9,6 +9,11 @@ from pyodide_build.common import _parse_package_subset # noqa
def test_parse_package_subset(): def test_parse_package_subset():
assert _parse_package_subset(None) is None assert _parse_package_subset(None) is None
# micropip is always included # micropip is always included
assert _parse_package_subset("numpy,pandas") == [ assert _parse_package_subset("numpy,pandas") == {
'micropip', 'distlib', 'numpy', 'pandas' 'micropip', 'distlib', 'numpy', 'pandas'
] }
# duplicates are removed
assert _parse_package_subset("numpy,numpy") == {
'micropip', 'distlib', 'numpy'
}