Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
Fix some ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Oct 5, 2023
1 parent cab5384 commit 1cbc4b2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

extensions = [
"jupyterlite_sphinx",
Expand Down
22 changes: 11 additions & 11 deletions jupyterlite_xeus_python/build.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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:
Expand Down Expand Up @@ -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",
Expand All @@ -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}",
Expand Down Expand Up @@ -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'")
Expand Down
13 changes: 6 additions & 7 deletions jupyterlite_xeus_python/env_build_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()

Expand Down
10 changes: 4 additions & 6 deletions tests/test_xeus_python_env.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit 1cbc4b2

Please sign in to comment.