diff --git a/docs/conf.py b/docs/conf.py index c14246c..cc0df9b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- extensions = [ "jupyterlite_sphinx", diff --git a/jupyterlite_xeus_python/build.py b/jupyterlite_xeus_python/build.py index a75ead5..90b7b23 100644 --- a/jupyterlite_xeus_python/build.py +++ b/jupyterlite_xeus_python/build.py @@ -1,19 +1,17 @@ import csv import os -from pathlib import Path -import requests import shutil +from pathlib import Path from subprocess import run from tempfile import TemporaryDirectory -from typing import List +from typing import List, Optional from urllib.parse import urlparse +import requests +import typer import yaml - -from empack.pack import pack_env, DEFAULT_CONFIG_PATH from empack.file_patterns import PkgFileFilter, pkg_file_filter_from_yaml - -import typer +from empack.pack import DEFAULT_CONFIG_PATH, pack_env try: from mamba.api import create as mamba_create @@ -164,7 +162,7 @@ def _install_pip_dependencies(prefix_path, dependencies, log=None): packages_dist_info = Path(pkg_dir.name).glob("*.dist-info") for package_dist_info in packages_dist_info: - with open(package_dist_info / "RECORD", "r") as record: + with open(package_dist_info / "RECORD") as record: record_content = record.read() record_csv = csv.reader(record_content.splitlines()) all_files = [_file[0] for _file in record_csv] @@ -179,7 +177,7 @@ def _install_pip_dependencies(prefix_path, dependencies, log=None): with open(package_dist_info / "RECORD", "w") as record: record.write(fixed_record_data) - non_supported_files = [".so", ".a", ".dylib", ".lib", ".exe" ".dll"] + non_supported_files = [".so", ".a", ".dylib", ".lib", ".exe.dll"] # COPY files under `prefix_path` for _file, inside_site_packages in files: @@ -209,7 +207,7 @@ def _install_pip_dependencies(prefix_path, dependencies, log=None): def build_and_pack_emscripten_env( python_version: str = PYTHON_VERSION, xeus_python_version: str = XEUS_PYTHON_VERSION, - packages: List[str] = [], + packages: Optional[List[str]] = None, environment_file: str = "", root_prefix: str = "/tmp/xeus-python-kernel", env_name: str = "xeus-python-kernel", @@ -220,6 +218,8 @@ def build_and_pack_emscripten_env( log=None, ): """Build a conda environment for the emscripten platform and pack it with empack.""" + if packages is None: + packages = [] channels = CHANNELS specs = [ f"python={python_version}", @@ -324,7 +324,7 @@ def build_and_pack_emscripten_env( dirs_exist_ok=True, ) - with open(Path(output_path) / "worker.ts", "r") as fobj: + with open(Path(output_path) / "worker.ts") as fobj: worker = fobj.read() worker = worker.replace("XEUS_KERNEL_FILE", "'xpython_wasm.js'") diff --git a/jupyterlite_xeus_python/env_build_addon.py b/jupyterlite_xeus_python/env_build_addon.py index f185ed1..02d6d93 100644 --- a/jupyterlite_xeus_python/env_build_addon.py +++ b/jupyterlite_xeus_python/env_build_addon.py @@ -4,16 +4,15 @@ from pathlib import Path from tempfile import TemporaryDirectory -from traitlets import List, Unicode - +from jupyterlite_core.addons.federated_extensions import FederatedExtensionAddon from jupyterlite_core.constants import ( - SHARE_LABEXTENSIONS, - LAB_EXTENSIONS, + FEDERATED_EXTENSIONS, JUPYTERLITE_JSON, + LAB_EXTENSIONS, + SHARE_LABEXTENSIONS, UTF8, - FEDERATED_EXTENSIONS, ) -from jupyterlite_core.addons.federated_extensions import FederatedExtensionAddon +from traitlets import List, Unicode from .build import XEUS_PYTHON_VERSION, build_and_pack_emscripten_env @@ -54,7 +53,7 @@ class XeusPythonEnv(FederatedExtensionAddon): ) def __init__(self, *args, **kwargs): - super(XeusPythonEnv, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.cwd = TemporaryDirectory() diff --git a/tests/test_xeus_python_env.py b/tests/test_xeus_python_env.py index 65c2806..4bf32c5 100644 --- a/tests/test_xeus_python_env.py +++ b/tests/test_xeus_python_env.py @@ -1,11 +1,9 @@ """Test creating Python envs for jupyterlite-xeus-python.""" import os -from tempfile import TemporaryDirectory from pathlib import Path import pytest - from jupyterlite_core.app import LiteStatusApp from jupyterlite_xeus_python.env_build_addon import XeusPythonEnv @@ -19,7 +17,7 @@ def test_python_env(): addon = XeusPythonEnv(manager) addon.packages = ["numpy", "ipyleaflet"] - for step in addon.post_build(manager): + for _step in addon.post_build(manager): pass # Check env @@ -42,7 +40,7 @@ def test_python_env_from_file_1(): addon = XeusPythonEnv(manager) addon.environment_file = "environment-1.yml" - for step in addon.post_build(manager): + for _step in addon.post_build(manager): pass # Check env @@ -88,7 +86,7 @@ def test_python_env_from_file_3(): addon = XeusPythonEnv(manager) addon.environment_file = "test_package/environment-3.yml" - for step in addon.post_build(manager): + for _step in addon.post_build(manager): pass # Test @@ -111,5 +109,5 @@ def test_python_env_from_file_2(): addon.environment_file = "environment-2.yml" with pytest.raises(RuntimeError, match="Cannot install binary PyPI package"): - for step in addon.post_build(manager): + for _step in addon.post_build(manager): pass