From a44780c941aec577d32352291b1d745917ec4ce3 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sat, 27 Apr 2024 15:13:35 -0400 Subject: [PATCH] feat: integrate pyodide helper (#206) Signed-off-by: Henry Schreiner --- docs/webapp.js | 3 --- pyproject.toml | 6 ++++-- src/repo_review/ghpath.py | 8 +++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/webapp.js b/docs/webapp.js index 91a4bd2..d4545bd 100644 --- a/docs/webapp.js +++ b/docs/webapp.js @@ -229,12 +229,9 @@ class App extends React.Component { var families_checks; try { families_checks = pyodide.runPython(` - from pyodide.http import open_url from repo_review.processor import process, md_as_html from repo_review.ghpath import GHPath - GHPath.open_url = staticmethod(open_url) - package = GHPath(repo="${state.repo}", branch="${state.branch}") result = process(package) diff --git a/pyproject.toml b/pyproject.toml index 41a2954..1981c8a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -113,8 +113,9 @@ disallow_untyped_defs = true [tool.pylint] -master.py-version = "3.10" -master.ignore-paths= ["src/repo_review/_version.py"] +py-version = "3.10" +ignore-paths = ["src/repo_review/_version.py"] +ignored-modules = ["pyodide"] reports.output-format = "colorized" similarities.ignore-imports = "yes" messages_control.disable = [ @@ -131,6 +132,7 @@ messages_control.disable = [ "no-member", # better handled by mypy, etc. "used-before-assignment", # False positive on conditional import "unnecessary-ellipsis", # Not correct for typing + "import-outside-toplevel", # better handled elsewhere ] diff --git a/src/repo_review/ghpath.py b/src/repo_review/ghpath.py index ef9c9db..ec3ac34 100644 --- a/src/repo_review/ghpath.py +++ b/src/repo_review/ghpath.py @@ -7,6 +7,7 @@ import dataclasses import io import json +import sys import typing from collections.abc import Iterator from typing import Literal @@ -47,7 +48,12 @@ class GHPath(Traversable): @staticmethod def open_url(url: str) -> io.StringIO: - "This method can be overridden for pyodide with pyodide.open_url" + "This method can be overridden manually for WASM. Supports pyodide currently." + if sys.platform == "emscripten": + import pyodide.http + + return pyodide.http.open_url(url) + import urllib.request # pylint: disable=import-outside-toplevel with urllib.request.urlopen(url) as response: