mirror of
https://github.com/pyscript/pyscript.git
synced 2026-03-27 02:00:24 -04:00
lint
This commit is contained in:
@@ -2,6 +2,7 @@ import sys
|
||||
|
||||
import js as globalThis
|
||||
from polyscript import js_modules
|
||||
|
||||
from pyscript.util import NotSupported
|
||||
|
||||
RUNNING_IN_WORKER = not hasattr(globalThis, "document")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from pyodide.ffi import to_js
|
||||
|
||||
from pyscript import window
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
from textwrap import dedent
|
||||
|
||||
from pyscript import document, when, window
|
||||
from pyweb import JSProperty, js_property, pydom
|
||||
|
||||
from pyscript import document, when, window
|
||||
|
||||
# Global attributes that all elements have (this list is a subset of the official one)
|
||||
# and tries to capture the most used ones
|
||||
GLOBAL_ATTRIBUTES = [
|
||||
@@ -98,12 +99,15 @@ def _add_js_properties(cls, *attrs):
|
||||
|
||||
"""
|
||||
|
||||
|
||||
# IMPORTANT: For all HTML components defined below, we are not mapping all
|
||||
# available attributes, only the global ones
|
||||
|
||||
|
||||
class a(TextElementBase):
|
||||
tag = "a"
|
||||
|
||||
|
||||
# Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attributes
|
||||
_add_js_properties(a, "download", "href", "referrerpolicy", "rel", "target", "type")
|
||||
|
||||
@@ -111,14 +115,28 @@ _add_js_properties(a, "download", "href", "referrerpolicy", "rel", "target", "ty
|
||||
class button(TextElementBase):
|
||||
tag = "button"
|
||||
|
||||
|
||||
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attributes
|
||||
_add_js_properties(button, "autofocus", "disabled", "form", "formaction", "formenctype",
|
||||
"formmethod", "formnovalidate", "formtarget", "name", "type", "value")
|
||||
_add_js_properties(
|
||||
button,
|
||||
"autofocus",
|
||||
"disabled",
|
||||
"form",
|
||||
"formaction",
|
||||
"formenctype",
|
||||
"formmethod",
|
||||
"formnovalidate",
|
||||
"formtarget",
|
||||
"name",
|
||||
"type",
|
||||
"value",
|
||||
)
|
||||
|
||||
|
||||
class h1(TextElementBase):
|
||||
tag = "h1"
|
||||
|
||||
|
||||
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements#attributes
|
||||
# Heading elements only have global attributes
|
||||
_add_js_properties(h1)
|
||||
@@ -126,58 +144,106 @@ _add_js_properties(h1)
|
||||
|
||||
class h2(TextElementBase):
|
||||
tag = "h2"
|
||||
|
||||
|
||||
_add_js_properties(h2)
|
||||
|
||||
|
||||
class h3(TextElementBase):
|
||||
tag = "h3"
|
||||
|
||||
|
||||
_add_js_properties(h3)
|
||||
|
||||
|
||||
class h4(TextElementBase):
|
||||
tag = "h4"
|
||||
|
||||
|
||||
_add_js_properties(h4)
|
||||
|
||||
|
||||
class h5(TextElementBase):
|
||||
tag = "h5"
|
||||
|
||||
|
||||
_add_js_properties(h5)
|
||||
|
||||
|
||||
class h6(TextElementBase):
|
||||
tag = "h6"
|
||||
|
||||
|
||||
_add_js_properties(h6)
|
||||
|
||||
|
||||
class link(TextElementBase):
|
||||
tag = "link"
|
||||
|
||||
|
||||
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attributes
|
||||
_add_js_properties(link, "as", "crossorigin", "disabled", "fetchpriority", "href",
|
||||
"imagesizes", "imagesrcset", "integrity", "media", "rel",
|
||||
"referrerpolicy", "sizes", "title", "type")
|
||||
_add_js_properties(
|
||||
link,
|
||||
"as",
|
||||
"crossorigin",
|
||||
"disabled",
|
||||
"fetchpriority",
|
||||
"href",
|
||||
"imagesizes",
|
||||
"imagesrcset",
|
||||
"integrity",
|
||||
"media",
|
||||
"rel",
|
||||
"referrerpolicy",
|
||||
"sizes",
|
||||
"title",
|
||||
"type",
|
||||
)
|
||||
|
||||
|
||||
class style(TextElementBase):
|
||||
tag = "style"
|
||||
|
||||
|
||||
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style#attributes
|
||||
_add_js_properties(style, "blocking", "media", "nonce", "title")
|
||||
|
||||
|
||||
class script(TextElementBase):
|
||||
tag = "script"
|
||||
|
||||
# Let's add async manually since it's a reserved keyword in Python
|
||||
async_ = js_property("async")
|
||||
|
||||
|
||||
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attributes
|
||||
_add_js_properties(script, "blocking", "crossorigin", "defer", "fetchpriority",
|
||||
"integrity", "nomodule", "nonce", "referrerpolicy",
|
||||
"src", "type")
|
||||
_add_js_properties(
|
||||
script,
|
||||
"blocking",
|
||||
"crossorigin",
|
||||
"defer",
|
||||
"fetchpriority",
|
||||
"integrity",
|
||||
"nomodule",
|
||||
"nonce",
|
||||
"referrerpolicy",
|
||||
"src",
|
||||
"type",
|
||||
)
|
||||
|
||||
|
||||
class p(TextElementBase):
|
||||
tag = "p"
|
||||
|
||||
|
||||
# p tags only have the global attributes ones
|
||||
_add_js_properties(p)
|
||||
|
||||
|
||||
class code(TextElementBase):
|
||||
tag = "code"
|
||||
|
||||
|
||||
# code tags only have the global attributes ones
|
||||
_add_js_properties(code)
|
||||
|
||||
@@ -185,18 +251,23 @@ _add_js_properties(code)
|
||||
class pre(TextElementBase):
|
||||
tag = "pre"
|
||||
|
||||
|
||||
# pre tags only have the global attributes ones (others have been deprecated)
|
||||
_add_js_properties(pre)
|
||||
|
||||
|
||||
class strong(TextElementBase):
|
||||
tag = "strong"
|
||||
|
||||
|
||||
# strong tags only have the global attributes ones
|
||||
_add_js_properties(strong)
|
||||
|
||||
|
||||
class small(TextElementBase):
|
||||
tag = "small"
|
||||
|
||||
|
||||
# small tags only have the global attributes ones
|
||||
_add_js_properties(small)
|
||||
|
||||
@@ -204,6 +275,7 @@ _add_js_properties(small)
|
||||
class br(ElementBase):
|
||||
tag = "br"
|
||||
|
||||
|
||||
# br tags only have the global attributes ones (others have been deprecated)
|
||||
_add_js_properties(br)
|
||||
|
||||
@@ -211,6 +283,7 @@ _add_js_properties(br)
|
||||
class div(TextElementBase):
|
||||
tag = "div"
|
||||
|
||||
|
||||
# div tags only have the global attributes ones (others have been deprecated)
|
||||
_add_js_properties(div)
|
||||
|
||||
@@ -218,10 +291,22 @@ _add_js_properties(div)
|
||||
class img(ElementBase):
|
||||
tag = "img"
|
||||
|
||||
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attributes
|
||||
_add_js_properties(img, "alt", "crossorigin", "decoding", "fetchpriority", "height",
|
||||
"ismap", "loading", "referrerpolicy", "sizes", "src", "width")
|
||||
|
||||
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attributes
|
||||
_add_js_properties(
|
||||
img,
|
||||
"alt",
|
||||
"crossorigin",
|
||||
"decoding",
|
||||
"fetchpriority",
|
||||
"height",
|
||||
"ismap",
|
||||
"loading",
|
||||
"referrerpolicy",
|
||||
"sizes",
|
||||
"src",
|
||||
"width",
|
||||
)
|
||||
|
||||
|
||||
class input(ElementBase):
|
||||
@@ -244,13 +329,45 @@ class input(ElementBase):
|
||||
def __init__(self, style=None, **kwargs):
|
||||
super().__init__(style=style, **kwargs)
|
||||
|
||||
|
||||
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attributes
|
||||
_add_js_properties(input, "accept", "alt", "autofocus", "capture", "checked", "dirname",
|
||||
"disabled", "form", "formaction", "formenctype", "formmethod",
|
||||
"formnovalidate", "formtarget", "height", "list", "max", "maxlength",
|
||||
"min", "minlength", "multiple", "name", "pattern", "placeholder",
|
||||
"popovertarget", "popovertargetaction", "readonly", "required",
|
||||
"size", "src", "step", "type", "value", "width")
|
||||
_add_js_properties(
|
||||
input,
|
||||
"accept",
|
||||
"alt",
|
||||
"autofocus",
|
||||
"capture",
|
||||
"checked",
|
||||
"dirname",
|
||||
"disabled",
|
||||
"form",
|
||||
"formaction",
|
||||
"formenctype",
|
||||
"formmethod",
|
||||
"formnovalidate",
|
||||
"formtarget",
|
||||
"height",
|
||||
"list",
|
||||
"max",
|
||||
"maxlength",
|
||||
"min",
|
||||
"minlength",
|
||||
"multiple",
|
||||
"name",
|
||||
"pattern",
|
||||
"placeholder",
|
||||
"popovertarget",
|
||||
"popovertargetaction",
|
||||
"readonly",
|
||||
"required",
|
||||
"size",
|
||||
"src",
|
||||
"step",
|
||||
"type",
|
||||
"value",
|
||||
"width",
|
||||
)
|
||||
|
||||
|
||||
# Custom Elements
|
||||
class Grid(ElementBase):
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
"""Markdown module to generate web/HTML components from Markdown code"""
|
||||
from pyscript import document, window
|
||||
from pyweb import pydom
|
||||
from pyweb.ui.elements import TextElementBase, script
|
||||
|
||||
from pyscript import document, window
|
||||
|
||||
|
||||
class markdown(TextElementBase):
|
||||
"""Markdown component to render HTML from Markdown code"""
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import string
|
||||
from textwrap import dedent
|
||||
|
||||
from pyscript import document, when, window
|
||||
from pyweb import JSProperty, js_property, pydom
|
||||
from pyweb.ui import elements as el
|
||||
|
||||
from pyscript import document, when, window
|
||||
|
||||
|
||||
class ShoeBase(pydom.Element):
|
||||
tag = "div"
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from pyodide.ffi import create_proxy
|
||||
from pyscript import display, document, when, window
|
||||
from pyweb import media, pydom
|
||||
|
||||
from pyscript import display, document, when, window
|
||||
|
||||
devicesSelect = pydom["#devices"][0]
|
||||
video = pydom["video"][0]
|
||||
devices = {}
|
||||
|
||||
@@ -2,9 +2,10 @@ import random
|
||||
import time
|
||||
from datetime import datetime as dt
|
||||
|
||||
from pyscript import display, when
|
||||
from pyweb import pydom
|
||||
|
||||
from pyscript import display, when
|
||||
|
||||
|
||||
@when("click", "#just-a-button")
|
||||
def on_click():
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
print("tests starting")
|
||||
import pytest
|
||||
|
||||
from pyscript import window
|
||||
|
||||
args = window.location.search.replace("?", "").split("&")
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from pyscript import document, when
|
||||
from pyweb import pydom
|
||||
|
||||
from pyscript import document, when
|
||||
|
||||
|
||||
class TestDocument:
|
||||
def test__element(self):
|
||||
|
||||
@@ -2,13 +2,12 @@ from textwrap import dedent
|
||||
|
||||
import examples
|
||||
import styles
|
||||
from pyscript import when, window
|
||||
from pyweb import pydom
|
||||
from pyweb.ui import elements as el
|
||||
from pyweb.ui import shoelace
|
||||
from pyweb.ui.markdown import markdown
|
||||
|
||||
|
||||
from pyscript import when, window
|
||||
|
||||
MAIN_PAGE_MARKDOWN = dedent(
|
||||
"""
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from pyscript import when
|
||||
from pyweb import pydom
|
||||
from pyweb.ui import elements as el
|
||||
from pyweb.ui.shoelace import (
|
||||
@@ -13,6 +12,8 @@ from pyweb.ui.shoelace import (
|
||||
Rating,
|
||||
)
|
||||
|
||||
from pyscript import when
|
||||
|
||||
LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
|
||||
details_code = """
|
||||
LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
|
||||
|
||||
@@ -3,6 +3,7 @@ import js
|
||||
js.document.body.append("document patch ")
|
||||
|
||||
import a
|
||||
|
||||
from pyscript import RUNNING_IN_WORKER, display, sync
|
||||
|
||||
display("Hello World", target="test", append=True)
|
||||
|
||||
Reference in New Issue
Block a user