code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def test_downthenup_bounce_done(self):
"""When marathon has the desired app, and there are no other copies of the service running, downthenup bounce
should neither start nor stop anything."""
new_config = {"id": "foo.bar.12345", "instances": 5}
happy_tasks = [mock.Mock() for _ in range(... | When marathon has the desired app, and there are no other copies of the service running, downthenup bounce
should neither start nor stop anything. | test_downthenup_bounce_done | python | Yelp/paasta | tests/test_bounce_lib.py | https://github.com/Yelp/paasta/blob/master/tests/test_bounce_lib.py | Apache-2.0 |
def test_service_group_chain_name(service_group):
"""The chain name must be stable, unique, and short."""
assert service_group.chain_name == "PAASTA.my_cool_se.f031797563"
assert len(service_group.chain_name) <= 28 | The chain name must be stable, unique, and short. | test_service_group_chain_name | python | Yelp/paasta | tests/test_firewall.py | https://github.com/Yelp/paasta/blob/master/tests/test_firewall.py | Apache-2.0 |
def test_service_group_rules_empty_when_service_is_deleted(
service_group, mock_service_config
):
"""A deleted service which still has running containers shouldn't cause exceptions."""
with mock.patch.object(
firewall, "get_instance_config", side_effect=NoConfigurationForServiceError()
):
... | A deleted service which still has running containers shouldn't cause exceptions. | test_service_group_rules_empty_when_service_is_deleted | python | Yelp/paasta | tests/test_firewall.py | https://github.com/Yelp/paasta/blob/master/tests/test_firewall.py | Apache-2.0 |
def test_get_sidecar_resource_requirements_default_requirements(self):
"""When request is unspecified, it should default to the 0.1, 1024Mi, 256Mi."""
try:
del self.deployment.config_dict["sidecar_resource_requirements"]
except KeyError:
pass
system_paasta_config... | When request is unspecified, it should default to the 0.1, 1024Mi, 256Mi. | test_get_sidecar_resource_requirements_default_requirements | python | Yelp/paasta | tests/test_kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/tests/test_kubernetes_tools.py | Apache-2.0 |
def test_get_node_affinity_no_reqs_with_global_override(self):
"""
Given global node affinity overrides and no deployment specific requirements, the globals should be used
"""
assert self.deployment.get_node_affinity(
{"default": {"topology.kubernetes.io/zone": ["us-west-1a",... |
Given global node affinity overrides and no deployment specific requirements, the globals should be used
| test_get_node_affinity_no_reqs_with_global_override | python | Yelp/paasta | tests/test_kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/tests/test_kubernetes_tools.py | Apache-2.0 |
def test_get_node_affinity_no_reqs_with_global_override_and_deployment_config(self):
"""
Given global node affinity overrides and deployment specific requirements, globals should be ignored
"""
deployment = KubernetesDeploymentConfig(
service="kurupt",
instance="f... |
Given global node affinity overrides and deployment specific requirements, globals should be ignored
| test_get_node_affinity_no_reqs_with_global_override_and_deployment_config | python | Yelp/paasta | tests/test_kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/tests/test_kubernetes_tools.py | Apache-2.0 |
def test_get_node_affinity_no_reqs_with_global_override_and_deployment_config_habitat(
self,
):
"""
Given global node affinity overrides and deployment specific zone selector, globals should be ignored
"""
deployment = KubernetesDeploymentConfig(
service="kurupt",... |
Given global node affinity overrides and deployment specific zone selector, globals should be ignored
| test_get_node_affinity_no_reqs_with_global_override_and_deployment_config_habitat | python | Yelp/paasta | tests/test_kubernetes_tools.py | https://github.com/Yelp/paasta/blob/master/tests/test_kubernetes_tools.py | Apache-2.0 |
def gen_mesos_cli_fobj(file_path, file_lines):
"""mesos.cli.cluster.files (0.1.5),
returns a list of mesos.cli.mesos_file.File
`File` is an iterator-like object.
"""
async def _readlines_reverse():
for line in reversed(file_lines):
yield line
... | mesos.cli.cluster.files (0.1.5),
returns a list of mesos.cli.mesos_file.File
`File` is an iterator-like object.
| gen_mesos_cli_fobj | python | Yelp/paasta | tests/test_mesos_tools.py | https://github.com/Yelp/paasta/blob/master/tests/test_mesos_tools.py | Apache-2.0 |
def kubernetes_cluster_config():
"""Return a sample dict to mock paasta_tools.utils.load_service_instance_configs"""
return {
"main": {
"instances": 3,
"deploy_group": "{cluster}.non_canary",
"cpus": 0.1,
"mem": 1000,
},
"canary": {
... | Return a sample dict to mock paasta_tools.utils.load_service_instance_configs | kubernetes_cluster_config | python | Yelp/paasta | tests/test_paasta_service_config_loader.py | https://github.com/Yelp/paasta/blob/master/tests/test_paasta_service_config_loader.py | Apache-2.0 |
def test_get_action_config(
self,
mock_load_deployments,
action_service,
action_deploy,
cluster,
expected_cluster,
):
"""Check resulting action config with various overrides from the action."""
action_dict = {"command": "echo first"}
if action_... | Check resulting action config with various overrides from the action. | test_get_action_config | python | Yelp/paasta | tests/test_tron_tools.py | https://github.com/Yelp/paasta/blob/master/tests/test_tron_tools.py | Apache-2.0 |
def test_format_path(self):
"""Test the path formatting for FileLogWriter"""
fw = utils.FileLogWriter(
"/logs/{service}/{component}/{level}/{cluster}/{instance}"
)
expected = "/logs/a/b/c/d/e"
assert expected == fw.format_path("a", "b", "c", "d", "e") | Test the path formatting for FileLogWriter | test_format_path | python | Yelp/paasta | tests/test_utils.py | https://github.com/Yelp/paasta/blob/master/tests/test_utils.py | Apache-2.0 |
def test_maybe_flock(self):
"""Make sure we flock and unflock when flock=True"""
with mock.patch("paasta_tools.utils.fcntl", autospec=True) as mock_fcntl:
fw = utils.FileLogWriter("/dev/null", flock=True)
mock_file = mock.Mock()
with fw.maybe_flock(mock_file):
... | Make sure we flock and unflock when flock=True | test_maybe_flock | python | Yelp/paasta | tests/test_utils.py | https://github.com/Yelp/paasta/blob/master/tests/test_utils.py | Apache-2.0 |
def test_maybe_flock_flock_false(self):
"""Make sure we don't flock/unflock when flock=False"""
with mock.patch("paasta_tools.utils.fcntl", autospec=True) as mock_fcntl:
fw = utils.FileLogWriter("/dev/null", flock=False)
mock_file = mock.Mock()
with fw.maybe_flock(moc... | Make sure we don't flock/unflock when flock=False | test_maybe_flock_flock_false | python | Yelp/paasta | tests/test_utils.py | https://github.com/Yelp/paasta/blob/master/tests/test_utils.py | Apache-2.0 |
def test_log_makes_exactly_one_write_call(self):
"""We want to make sure that log() makes exactly one call to write, since that's how we ensure atomicity."""
fake_file = mock.Mock()
fake_contextmgr = mock.Mock(
__enter__=lambda _self: fake_file, __exit__=lambda _self, t, v, tb: None
... | We want to make sure that log() makes exactly one call to write, since that's how we ensure atomicity. | test_log_makes_exactly_one_write_call | python | Yelp/paasta | tests/test_utils.py | https://github.com/Yelp/paasta/blob/master/tests/test_utils.py | Apache-2.0 |
def create_mock_instance_config(instance_type, namespace):
"""
Creates a mock InstanceConfig with specified instance_type and namespace.
:param instance_type: The type of the instance (e.g., "kubernetes", "paasta-native").
:param namespace: The namespace associated with the instance.
:return: A moc... |
Creates a mock InstanceConfig with specified instance_type and namespace.
:param instance_type: The type of the instance (e.g., "kubernetes", "paasta-native").
:param namespace: The namespace associated with the instance.
:return: A mock InstanceConfig object.
| create_mock_instance_config | python | Yelp/paasta | tests/cli/test_cmds_list_namespaces.py | https://github.com/Yelp/paasta/blob/master/tests/cli/test_cmds_list_namespaces.py | Apache-2.0 |
def reraise_keyboardinterrupt():
"""If it's not caught, this kills pytest :'("""
try:
yield
except FakeKeyboardInterrupt: # pragma: no cover (error case only)
raise AssertionError("library failed to catch KeyboardInterrupt") | If it's not caught, this kills pytest :'( | reraise_keyboardinterrupt | python | Yelp/paasta | tests/cli/test_cmds_logs.py | https://github.com/Yelp/paasta/blob/master/tests/cli/test_cmds_logs.py | Apache-2.0 |
def test_jira_ticket_parameter(
mock_get_smart_paasta_instance_name,
mock_configure_and_run_docker_container,
mock_spark_conf_builder,
mock_parse_user_spark_args,
mock_get_spark_app_name,
mock_get_docker_image,
mock_get_aws_credentials,
mock_get_instance_config,
mock_load_system_paas... | Test that the jira_ticket parameter is correctly passed to SparkConfBuilder. | test_jira_ticket_parameter | python | Yelp/paasta | tests/cli/test_cmds_spark_run.py | https://github.com/Yelp/paasta/blob/master/tests/cli/test_cmds_spark_run.py | Apache-2.0 |
def _formatted_table_to_dict(formatted_table):
"""Convert a single-row table with header to a dictionary"""
headers = [
header.strip() for header in formatted_table[0].split(" ") if len(header) > 0
]
fields = [
field.strip() for field in formatted_table[1].split(" ") if len(field) > 0
... | Convert a single-row table with header to a dictionary | _formatted_table_to_dict | python | Yelp/paasta | tests/cli/test_cmds_status.py | https://github.com/Yelp/paasta/blob/master/tests/cli/test_cmds_status.py | Apache-2.0 |
def test_suggest_smartstack_proxy_port_too_many_services(
self, mock_read_etc_services
):
"""If all the ports are taken, we should raise an error"""
yelpsoa_config_root = "fake_yelpsoa_config_root"
walk_return = [
("fake_root1", "fake_dir1", ["smartstack.yaml"]),
... | If all the ports are taken, we should raise an error | test_suggest_smartstack_proxy_port_too_many_services | python | Yelp/paasta | tests/cli/fsm/test_autosuggest.py | https://github.com/Yelp/paasta/blob/master/tests/cli/fsm/test_autosuggest.py | Apache-2.0 |
def process_queue(self, timeout=1):
"""
Called only by the internal thread.
Takes updates from the input queue and returns them. If
updates clash on (key, prop_name), only the first is returned,
and the rest are saved in `self.ui_updates` to be processed on
subsequent ru... |
Called only by the internal thread.
Takes updates from the input queue and returns them. If
updates clash on (key, prop_name), only the first is returned,
and the rest are saved in `self.ui_updates` to be processed on
subsequent runs.
| process_queue | python | hyperdiv/hyperdiv | hyperdiv/app_runner.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/app_runner.py | Apache-2.0 |
def run_user_app(self, frame):
"""
Called only by the internal thread.
Runs the user app function in the context of `frame` and
returns the resulting root container.
"""
if frame.prev_frame_mutations:
self.cache.eject_entries_for_mutated_props(frame.prev_fra... |
Called only by the internal thread.
Runs the user app function in the context of `frame` and
returns the resulting root container.
| run_user_app | python | hyperdiv/hyperdiv | hyperdiv/app_runner.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/app_runner.py | Apache-2.0 |
def apply_ui_updates(self, ui_updates):
"""
Called only by the internal thread.
Applies the given `ui_updates` to the application state, and
returns the mutations caused by these updates, separating
normal mutations from event mutations.
"""
with UIUpdatesFrame(... |
Called only by the internal thread.
Applies the given `ui_updates` to the application state, and
returns the mutations caused by these updates, separating
normal mutations from event mutations.
| apply_ui_updates | python | hyperdiv/hyperdiv | hyperdiv/app_runner.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/app_runner.py | Apache-2.0 |
def render_and_reply(self, frame, root_container=None, diff=None):
"""
Called only by the internal thread.
Given a root container or a diff, render that root container
or diff and send a reply on the websocket. The reply will
contain any pending commands and changed singletons.
... |
Called only by the internal thread.
Given a root container or a diff, render that root container
or diff and send a reply on the websocket. The reply will
contain any pending commands and changed singletons.
Even if there is no relevant container or diff to send, but
t... | render_and_reply | python | hyperdiv/hyperdiv | hyperdiv/app_runner.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/app_runner.py | Apache-2.0 |
def diff_and_reply(self, frame, root_container):
"""
Called only by the internal thread.
Sends a reply with the given root container (or a diff if a
previous container exists to diff against).
"""
dom = None
dom_diff = None
if self.previous_root_containe... |
Called only by the internal thread.
Sends a reply with the given root container (or a diff if a
previous container exists to diff against).
| diff_and_reply | python | hyperdiv/hyperdiv | hyperdiv/app_runner.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/app_runner.py | Apache-2.0 |
def run(self, mutations, event_mutations=None):
"""
Called only by the internal thread.
Runs the user app if necessary, and sends a reply to the browser
if necessary.
`mutations` is a set of mutations from a prior frame. Using
these `mutations`, we determine if the user... |
Called only by the internal thread.
Runs the user app if necessary, and sends a reply to the browser
if necessary.
`mutations` is a set of mutations from a prior frame. Using
these `mutations`, we determine if the user function is
"dirty" and needs to run again.
... | run | python | hyperdiv/hyperdiv | hyperdiv/app_runner.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/app_runner.py | Apache-2.0 |
def run_loop(self):
"""
Called only by the internal thread.
The long-running thread that runs the application function in
response to state updates. This thread is alive if and only if
the corresponding websocket is connected. When the websocket
closes, it calls `AppRunn... |
Called only by the internal thread.
The long-running thread that runs the application function in
response to state updates. This thread is alive if and only if
the corresponding websocket is connected. When the websocket
closes, it calls `AppRunner.stop()`, causing the run loo... | run_loop | python | hyperdiv/hyperdiv | hyperdiv/app_runner.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/app_runner.py | Apache-2.0 |
def run_loop_wrapper(self):
"""
The entrypoint to the main loop thread. Whereas `run_loop` raises
unhandled exceptions, `run_loop_wrapper` catches those
exceptions, prints a stacktrace, and gracefully exits the
thread.
"""
try:
self.run_loop()
... |
The entrypoint to the main loop thread. Whereas `run_loop` raises
unhandled exceptions, `run_loop_wrapper` catches those
exceptions, prints a stacktrace, and gracefully exits the
thread.
| run_loop_wrapper | python | hyperdiv/hyperdiv | hyperdiv/app_runner.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/app_runner.py | Apache-2.0 |
def _internal_sync(self):
"""
Only used in tests.
Blocks until the app runner becomes idle -- input queue is empty
and the task runner is idle.
This method is only used in tests and assumes that while this
method is running, no other user threads are adding items to
... |
Only used in tests.
Blocks until the app runner becomes idle -- input queue is empty
and the task runner is idle.
This method is only used in tests and assumes that while this
method is running, no other user threads are adding items to
the input queue. While flushing,... | _internal_sync | python | hyperdiv/hyperdiv | hyperdiv/app_runner.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/app_runner.py | Apache-2.0 |
def enqueue_ui_updates(self, ui_updates):
"""
Enqueue a batch of "ui updates". These are typically events
generated by users in the browser and enqueued by
`hyperdiv.connection.Connection`.
They can also be simulated UI events, triggered by user code
via `self.trigger_ev... |
Enqueue a batch of "ui updates". These are typically events
generated by users in the browser and enqueued by
`hyperdiv.connection.Connection`.
They can also be simulated UI events, triggered by user code
via `self.trigger_event`.
| enqueue_ui_updates | python | hyperdiv/hyperdiv | hyperdiv/app_runner.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/app_runner.py | Apache-2.0 |
def trigger_event(self, prop, value):
"""
Simulates a UI event. Usually called by `Component.trigger_event
"""
if not prop.is_event_prop:
raise Exception(f"Cannot trigger event for non event prop {prop.name}")
self.enqueue_ui_updates([(prop.key, prop.name, value)]) |
Simulates a UI event. Usually called by `Component.trigger_event
| trigger_event | python | hyperdiv/hyperdiv | hyperdiv/app_runner.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/app_runner.py | Apache-2.0 |
def cached(fn):
"""
To help improve performance when building large, modular apps,
Hyperdiv functions that generate UI components can be wrapped in
`@cached` to avoid re-running those function calls if their read
dependencies have not changed.
For example:
```py
@hd.cached
def my_c... |
To help improve performance when building large, modular apps,
Hyperdiv functions that generate UI components can be wrapped in
`@cached` to avoid re-running those function calls if their read
dependencies have not changed.
For example:
```py
@hd.cached
def my_counter(label):
s... | cached | python | hyperdiv/hyperdiv | hyperdiv/cache.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/cache.py | Apache-2.0 |
def cached_app(app_fn):
"""
Works like @cached but only for the top-level app function. Unlike
@cached, it does not use a component key to generate the cache
key, enabling the addition of helper functions `is_dirty`, `deps`,
and `get_dirty_deps` which help AppRuntime decide when to re-run
the us... |
Works like @cached but only for the top-level app function. Unlike
@cached, it does not use a component key to generate the cache
key, enabling the addition of helper functions `is_dirty`, `deps`,
and `get_dirty_deps` which help AppRuntime decide when to re-run
the user app, as well as print useful... | cached_app | python | hyperdiv/hyperdiv | hyperdiv/cache.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/cache.py | Apache-2.0 |
def current(self):
"""`current()` is a semi-public interface and can be used by
components to introspect the parent component in which they're
being collected. It skips ShadowCollectors which are internal
collectors used by the cache.
"""
top_index = -1
while isin... | `current()` is a semi-public interface and can be used by
components to introspect the parent component in which they're
being collected. It skips ShadowCollectors which are internal
collectors used by the cache.
| current | python | hyperdiv/hyperdiv | hyperdiv/collector.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/collector.py | Apache-2.0 |
def collect(self):
"""
Called when the component is collected into the dom. If the
component was constructed with `collect=False`, this method has
to be called by the user code. Otherwise it is called
automatically when the component is constructed.
"""
if self._c... |
Called when the component is collected into the dom. If the
component was constructed with `collect=False`, this method has
to be called by the user code. Otherwise it is called
automatically when the component is constructed.
| collect | python | hyperdiv/hyperdiv | hyperdiv/component_base.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/component_base.py | Apache-2.0 |
def children(self):
"""
Returns the list of children of this component, if this
component can have children. If the component cannot have
children, accessing this property raises `ValueError`.
"""
if self._has_children:
return self._children
raise Val... |
Returns the list of children of this component, if this
component can have children. If the component cannot have
children, accessing this property raises `ValueError`.
| children | python | hyperdiv/hyperdiv | hyperdiv/component_base.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/component_base.py | Apache-2.0 |
def set_prop_delayed(self, prop_name, prop_value, delay=1):
"""
Sets the prop with `prop_name` to the value `prop_value` after a
delay of `delay` seconds.
This may be useful for auto-closing an ephemeral alert, dropdown,
or dialog, after being shown for some duration of time.
... |
Sets the prop with `prop_name` to the value `prop_value` after a
delay of `delay` seconds.
This may be useful for auto-closing an ephemeral alert, dropdown,
or dialog, after being shown for some duration of time.
| set_prop_delayed | python | hyperdiv/hyperdiv | hyperdiv/component_base.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/component_base.py | Apache-2.0 |
def reset_prop_delayed(self, prop_name, delay=1):
"""
Like `set_prop_delayed` but instead of mutating the prop it resets
it to its initial value.
"""
from .components.task import run_asynchronously
async def reset_delayed():
await asyncio.sleep(delay)
... |
Like `set_prop_delayed` but instead of mutating the prop it resets
it to its initial value.
| reset_prop_delayed | python | hyperdiv/hyperdiv | hyperdiv/component_base.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/component_base.py | Apache-2.0 |
def reset_component_delayed(self, delay=1):
"""
Like `reset_prop_delayed` but resets all component props.
"""
from .components.task import run_asynchronously
async def reset_delayed():
await asyncio.sleep(delay)
self.reset_component()
def cb(res... |
Like `reset_prop_delayed` but resets all component props.
| reset_component_delayed | python | hyperdiv/hyperdiv | hyperdiv/component_base.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/component_base.py | Apache-2.0 |
def global_state(klass):
"""
`global_state` is a decorator that can be be used to define a
state component class such that all instances of that class share
the same underlying state.
This can be handy when a state component is used by many
functions, and you want to avoid explicitly passing th... |
`global_state` is a decorator that can be be used to define a
state component class such that all instances of that class share
the same underlying state.
This can be handy when a state component is used by many
functions, and you want to avoid explicitly passing the state
component into all t... | global_state | python | hyperdiv/hyperdiv | hyperdiv/global_state.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/global_state.py | Apache-2.0 |
def index_page(
title="Hyperdiv",
description=None,
keywords=None,
url=None,
image=None,
twitter_card_type="summary_large_image",
favicon="/hd-logo-white.svg",
favicon_16=None,
favicon_32=None,
apple_touch_icon=None,
css_assets=(),
js_assets=(),
raw_head_content="",
)... |
This function generates the app's HTML index page that is served
to the browser when users load the app's URL. It generates SEO meta
tags as well as Twitter (`twitter:`) and Meta OpenGraph (`og:`)
tags, so Twitter/Meta will generate nice-looking preview cards
when the app is shared on these platfor... | index_page | python | hyperdiv/hyperdiv | hyperdiv/index_page.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/index_page.py | Apache-2.0 |
def run(app_function, task_threads=10, executor=None, index_page=None):
"""
The entrypoint into Hyperdiv.
When calling `run(app_function)`, Hyperdiv will start a web server
ready to serve the app defined by `app_function`, on a local
port. A user can connect a web browser to this port to interact
... |
The entrypoint into Hyperdiv.
When calling `run(app_function)`, Hyperdiv will start a web server
ready to serve the app defined by `app_function`, on a local
port. A user can connect a web browser to this port to interact
with the app. The call to `run` will block until Hyperdiv exits.
Hyperd... | run | python | hyperdiv/hyperdiv | hyperdiv/main.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/main.py | Apache-2.0 |
def render(self):
"""
The JSON-rendered form of the plugin that is sent to the browser.
"""
klass = type(self)
plugin_name = getattr(klass, "_name", None) or klass.__name__
plugin_config = PluginAssetsCollector.plugin_assets.get(plugin_name, {})
assets_root = pl... |
The JSON-rendered form of the plugin that is sent to the browser.
| render | python | hyperdiv/hyperdiv | hyperdiv/plugin.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/plugin.py | Apache-2.0 |
def __get__(self, component, objtype):
"""Called when the prop attribute is read."""
if component is None:
return self
return StateAccessFrame.current().get_state(component._key, self.name) | Called when the prop attribute is read. | __get__ | python | hyperdiv/hyperdiv | hyperdiv/prop.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/prop.py | Apache-2.0 |
def __init__(self, key, prop):
"""`key` is the key of the component to which this prop is
attached. The other args come from `Prop`. See `create()`
below.
"""
self.key = key
self.prop = prop
self.name = prop.name
self.ui_name = prop.ui_name
self.c... | `key` is the key of the component to which this prop is
attached. The other args come from `Prop`. See `create()`
below.
| __init__ | python | hyperdiv/hyperdiv | hyperdiv/prop.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/prop.py | Apache-2.0 |
def dict_factory(cursor, row):
"""Row factory that returns dicts mapping column name to column value,
as opposed to the default factory, which returns tuples.
"""
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d | Row factory that returns dicts mapping column name to column value,
as opposed to the default factory, which returns tuples.
| dict_factory | python | hyperdiv/hyperdiv | hyperdiv/sqlite.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/sqlite.py | Apache-2.0 |
def migrate(db_path, migrations):
"""A migration is a function that takes a cursor and uses it to modify
the db in some way. `migrations` is a list of such functions.
"""
with sqlite_tx(db_path) as (_, cursor):
# If the _Migration table doesn't exist, create it.
try:
cursor.e... | A migration is a function that takes a cursor and uses it to modify
the db in some way. `migrations` is a list of such functions.
| migrate | python | hyperdiv/hyperdiv | hyperdiv/sqlite.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/sqlite.py | Apache-2.0 |
def code(code_block, language="python", **kwargs):
"""
Calls @component(markdown) to render the given code block.
`**kwargs` are passed down to @component(markdown).
`language` can be the short name of any lexer supported by
[Pygments](https://pygments.org/docs/lexers/).
```py
hd.code(
... |
Calls @component(markdown) to render the given code block.
`**kwargs` are passed down to @component(markdown).
`language` can be the short name of any lexer supported by
[Pygments](https://pygments.org/docs/lexers/).
```py
hd.code(
'''
def f(x, y):
return x + y
... | code | python | hyperdiv/hyperdiv | hyperdiv/components/code.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/code.py | Apache-2.0 |
def __init__(self, disabled=False, gap=1, **kwargs):
"""
If `disabled` is `True`, all the form inputs will be rendered
disabled, overriding the individual `disabled` kwargs passed
to each input. If you mutated the `disabled` prop on any of
the form inputs, that mutated value will... |
If `disabled` is `True`, all the form inputs will be rendered
disabled, overriding the individual `disabled` kwargs passed
to each input. If you mutated the `disabled` prop on any of
the form inputs, that mutated value will take precedence.
The rest of the kwargs are passed to ... | __init__ | python | hyperdiv/hyperdiv | hyperdiv/components/form.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/form.py | Apache-2.0 |
def checkbox(self, *label, wrapper_style=None, **kwargs):
"""
Adds a @component(checkbox) component to the form.
The `wrapper_style` argument can be a @component(style)
instance to control the style style of the internal container
that wraps the form input + the validation error... |
Adds a @component(checkbox) component to the form.
The `wrapper_style` argument can be a @component(style)
instance to control the style style of the internal container
that wraps the form input + the validation error message.
The `**kwargs` are passed on to the @component(che... | checkbox | python | hyperdiv/hyperdiv | hyperdiv/components/form.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/form.py | Apache-2.0 |
def color_picker(self, wrapper_style=None, **kwargs):
"""Adds a @component(color_picker) component to the form."""
return self._form_control(
color_picker, has_label=False, wrapper_style=wrapper_style, **kwargs
) | Adds a @component(color_picker) component to the form. | color_picker | python | hyperdiv/hyperdiv | hyperdiv/components/form.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/form.py | Apache-2.0 |
def text_input(self, *label, wrapper_style=None, **kwargs):
"""Adds a @component(text_input) component to the form."""
return self._form_control(
text_input, *label, wrapper_style=wrapper_style, **kwargs
) | Adds a @component(text_input) component to the form. | text_input | python | hyperdiv/hyperdiv | hyperdiv/components/form.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/form.py | Apache-2.0 |
def textarea(self, *label, wrapper_style=None, **kwargs):
"""Adds a @component(textarea) component to the form."""
return self._form_control(
textarea, *label, wrapper_style=wrapper_style, **kwargs
) | Adds a @component(textarea) component to the form. | textarea | python | hyperdiv/hyperdiv | hyperdiv/components/form.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/form.py | Apache-2.0 |
def radio_group(self, *label, wrapper_style=None, **kwargs):
"""Adds a @component(radio_group) component to the form."""
return self._form_control(
radio_group, *label, wrapper_style=wrapper_style, **kwargs
) | Adds a @component(radio_group) component to the form. | radio_group | python | hyperdiv/hyperdiv | hyperdiv/components/form.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/form.py | Apache-2.0 |
def reset(self):
"""
A way to programmatically reset the form.
"""
if self._being_submitted:
logger.warn("Cannot reset a form while it is submitting.")
return
for fc in self.form_controls:
fc.reset() |
A way to programmatically reset the form.
| reset | python | hyperdiv/hyperdiv | hyperdiv/components/form.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/form.py | Apache-2.0 |
def ui_read(target, command, args):
"""Invoke a UI read command. A read will send the command to the UI
and return a result object in `running` state. Calling this read
again on subsequent frames will *not* re-send the read call to the
UI. It will remain in `done` state and return the same value over
... | Invoke a UI read command. A read will send the command to the UI
and return a result object in `running` state. Calling this read
again on subsequent frames will *not* re-send the read call to the
UI. It will remain in `done` state and return the same value over
and over.
To trigger a re-read, you ... | ui_read | python | hyperdiv/hyperdiv | hyperdiv/components/local_storage.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/local_storage.py | Apache-2.0 |
def ui_write(target, command, args):
"""Invoke a UI write command. Unlike a read, a write call will send
the command to the UI on every call. Intuitively, writes should
not be called on every frame, but rather only in response to
events like `clicked`.
Writes still return a `async_command` object t... | Invoke a UI write command. Unlike a read, a write call will send
the command to the UI on every call. Intuitively, writes should
not be called on every frame, but rather only in response to
events like `clicked`.
Writes still return a `async_command` object that can be inspected to
determine the st... | ui_write | python | hyperdiv/hyperdiv | hyperdiv/components/local_storage.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/local_storage.py | Apache-2.0 |
def get_item(key):
"""
Calls the browser's `window.localStorage.getItem(key)`.
"""
result, sent = ui_read("localStorage", "getItem", [key])
if sent:
local_storage._cache_result(key, result)
return result |
Calls the browser's `window.localStorage.getItem(key)`.
| get_item | python | hyperdiv/hyperdiv | hyperdiv/components/local_storage.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/local_storage.py | Apache-2.0 |
def has_item(key):
"""
Tests if a key exists in the browser's localStorage. The returned
@component(async_command)'s `result` prop is set to `True` if the
given key exists in the browser's localStorage, or `False`
otherwise.
"""
result, sent = ui_read("localStorag... |
Tests if a key exists in the browser's localStorage. The returned
@component(async_command)'s `result` prop is set to `True` if the
given key exists in the browser's localStorage, or `False`
otherwise.
| has_item | python | hyperdiv/hyperdiv | hyperdiv/components/local_storage.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/local_storage.py | Apache-2.0 |
def set_item(key, value):
"""
Calls the browser's `window.localStorage.setItem(key, value)`.
"""
if not isinstance(value, str):
raise ValueError("local_storage.set_item can only store strings.")
result = ui_write("localStorage", "setItem", [key, value])
loc... |
Calls the browser's `window.localStorage.setItem(key, value)`.
| set_item | python | hyperdiv/hyperdiv | hyperdiv/components/local_storage.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/local_storage.py | Apache-2.0 |
def remove_item(key):
"""
Calls the browser's `window.localStorage.removeItem(key)`.
"""
result = ui_write("localStorage", "removeItem", [key])
local_storage._clear_cache_at_key(key)
return result |
Calls the browser's `window.localStorage.removeItem(key)`.
| remove_item | python | hyperdiv/hyperdiv | hyperdiv/components/local_storage.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/local_storage.py | Apache-2.0 |
def clear():
"""
Calls the browser's `window.localStorage.clear()`, removing all the
keys from localStorage.
"""
result = ui_write("localStorage", "clear", [])
local_storage._clear_cache()
return result |
Calls the browser's `window.localStorage.clear()`, removing all the
keys from localStorage.
| clear | python | hyperdiv/hyperdiv | hyperdiv/components/local_storage.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/local_storage.py | Apache-2.0 |
def go(self, path, query_args="", hash_arg=""):
"""
Change the browser location bar by simultaneously mutating all
three props. For example, `go(path="/foo", hash_arg="bar")` will
set the location to `"/foo#bar"`. If `query_args` is currently
set to a value, if will be set to `""... |
Change the browser location bar by simultaneously mutating all
three props. For example, `go(path="/foo", hash_arg="bar")` will
set the location to `"/foo#bar"`. If `query_args` is currently
set to a value, if will be set to `""`.
If you need to programmatically mutate the loca... | go | python | hyperdiv/hyperdiv | hyperdiv/components/location.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/location.py | Apache-2.0 |
def to_string(self):
"""
Returns a string of the full location, suitable for pasting into
the browser's location bar.
"""
string = f"{self.protocol}//{self.host}{self.path}"
if self.query_args:
string += f"?{self.query_args}"
if self.hash_arg:
... |
Returns a string of the full location, suitable for pasting into
the browser's location bar.
| to_string | python | hyperdiv/hyperdiv | hyperdiv/components/location.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/location.py | Apache-2.0 |
def scope(scope_id):
"""
When creating components in loops, you will encounter this error:
```py
for i in range(3):
hd.button("Button", i)
```
To fix it, you wrap the loop body in `hd.scope(i)`, where `i`
uniquely identifies each iteration:
```py
for i in range(3):
... |
When creating components in loops, you will encounter this error:
```py
for i in range(3):
hd.button("Button", i)
```
To fix it, you wrap the loop body in `hd.scope(i)`, where `i`
uniquely identifies each iteration:
```py
for i in range(3):
with hd.scope(i):
... | scope | python | hyperdiv/hyperdiv | hyperdiv/components/scope.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/scope.py | Apache-2.0 |
def __init__(
self,
*label,
options=None,
name=None,
prefix_icon=None,
clear_icon=None,
expand_icon=None,
**kwargs,
):
"""
If `options` is given as an iterable of option labels,
@component(option) components will be automaticall... |
If `options` is given as an iterable of option labels,
@component(option) components will be automatically created
for each given option.
| __init__ | python | hyperdiv/hyperdiv | hyperdiv/components/select_.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/select_.py | Apache-2.0 |
def run(self, fn, *args, **kwargs):
"""
Run `fn(*args, **kwargs)` on a separate thread (or ioloop if the
function is `async`).
"""
run_number = self._run_number
def result_callback(result=None, error=None):
if self._run_number != run_number:
... |
Run `fn(*args, **kwargs)` on a separate thread (or ioloop if the
function is `async`).
| run | python | hyperdiv/hyperdiv | hyperdiv/components/task.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/task.py | Apache-2.0 |
def rerun(self, fn, *args, **kwargs):
"""Just like `run` but calls `self.clear()` before running."""
self.clear()
self.run(fn, *args, **kwargs) | Just like `run` but calls `self.clear()` before running. | rerun | python | hyperdiv/hyperdiv | hyperdiv/components/task.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/task.py | Apache-2.0 |
def clear(self):
"""
Resets the props of the task to initial values. If the task is
`done`, clearing it will allow it to run again. Note that if
an instance of the task is running at the time `clear()` is
called, that instance will be ignored, but it will still run
to com... |
Resets the props of the task to initial values. If the task is
`done`, clearing it will allow it to run again. Note that if
an instance of the task is running at the time `clear()` is
called, that instance will be ignored, but it will still run
to completion.
Note that ... | clear | python | hyperdiv/hyperdiv | hyperdiv/components/task.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/task.py | Apache-2.0 |
def __init__(self, *content, **kwargs):
"""
The chunks passed in `*content` will be joined by `" "` and used
to initialize the `content` prop.
```py
x = 2
hd.text("I have", x, "chickens.")
# is equivalent to
hd.text(content=f"I have {x} chickens.")
... |
The chunks passed in `*content` will be joined by `" "` and used
to initialize the `content` prop.
```py
x = 2
hd.text("I have", x, "chickens.")
# is equivalent to
hd.text(content=f"I have {x} chickens.")
```
| __init__ | python | hyperdiv/hyperdiv | hyperdiv/components/text.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/text.py | Apache-2.0 |
def __init__(
self,
*label,
name=None,
prefix_icon=None,
suffix_icon=None,
clear_icon=None,
show_password_icon=None,
hide_password_icon=None,
**kwargs,
):
"""
The `*label` argument sets the text input's label.
The kwarg... |
The `*label` argument sets the text input's label.
The kwargs suffixed by `_icon` each take an icon name and slot
that icon into the respective slot.
| __init__ | python | hyperdiv/hyperdiv | hyperdiv/components/text_input.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/text_input.py | Apache-2.0 |
def is_light(self):
"""
Returns `True` if the theme is in light mode, and `False` if the
theme is in dark mode, regardless of whether the theme mode is
set by the user or follows system.
"""
if self.mode == "system":
return self.system_mode == "light"
... |
Returns `True` if the theme is in light mode, and `False` if the
theme is in dark mode, regardless of whether the theme mode is
set by the user or follows system.
| is_light | python | hyperdiv/hyperdiv | hyperdiv/components/theme.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/theme.py | Apache-2.0 |
def __init__(self, *content, **kwargs):
"""
If `*content` is passed, it will be joined by `" "` and used to
initialize the `content` prop.
"""
if content:
kwargs["content"] = concat_text(content)
super().__init__(**kwargs) |
If `*content` is passed, it will be joined by `" "` and used to
initialize the `content` prop.
| __init__ | python | hyperdiv/hyperdiv | hyperdiv/components/tooltip.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/tooltip.py | Apache-2.0 |
def __init__(
self,
expand_icon_name=None,
collapse_icon_name=None,
**kwargs,
):
"""
@component(icon) names can be passed in `expand_icon_name` or
`collapse_icon_name` to customize the expand and collapse
icons of all expandable tree nodes. The icons w... |
@component(icon) names can be passed in `expand_icon_name` or
`collapse_icon_name` to customize the expand and collapse
icons of all expandable tree nodes. The icons will
automatically placed in their respective slots.
The rest of `**kwargs` are passed to `Component`.
| __init__ | python | hyperdiv/hyperdiv | hyperdiv/components/tree.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/tree.py | Apache-2.0 |
def selected_items(self):
"""
Returns the complete list of the @component(tree_item) children
that are currently selected.
"""
children = []
def collect_children(node):
for c in node.children:
if isinstance(c, tree_item):
... |
Returns the complete list of the @component(tree_item) children
that are currently selected.
| selected_items | python | hyperdiv/hyperdiv | hyperdiv/components/tree.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/tree.py | Apache-2.0 |
def __init__(
self,
*label,
expand_icon_name=None,
collapse_icon_name=None,
**kwargs,
):
"""
@component(icon) names can be passed in `expand_icon_name` or
`collapse_icon_name` to customize the expand and collapse
icons of this specific three no... |
@component(icon) names can be passed in `expand_icon_name` or
`collapse_icon_name` to customize the expand and collapse
icons of this specific three node. The icons will
automatically placed in their respective slots.
These icons override icons set in the parent @component(tree... | __init__ | python | hyperdiv/hyperdiv | hyperdiv/components/tree_item.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/tree_item.py | Apache-2.0 |
def bar_chart(
*datasets,
labels=None,
colors=None,
grid_color="neutral-100",
x_axis="linear",
y_axis="linear",
hide_legend=False,
show_x_tick_labels=True,
show_y_tick_labels=True,
y_min=None,
y_max=None,
**kwargs,
):
"""
A @component(cartesian_chart) that renders... |
A @component(cartesian_chart) that renders datasets as bars.
```py
hd.bar_chart(
(1, 18, 4),
(4, 2, 28),
labels=("Jim", "Mary")
)
```
| bar_chart | python | hyperdiv/hyperdiv | hyperdiv/components/charts/bar_chart.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/charts/bar_chart.py | Apache-2.0 |
def bubble_chart(
*datasets,
labels=None,
colors=None,
grid_color="neutral-100",
x_axis="linear",
y_axis="linear",
hide_legend=False,
show_x_tick_labels=True,
show_y_tick_labels=True,
y_min=None,
y_max=None,
**kwargs,
):
"""
A @component(cartesian_chart) that rend... |
A @component(cartesian_chart) that renders datasets as bubble
points. It works like @component(scatter_chart), but you can
specify the visual size of the points by providing an extra `r`
component for each point, which specifies the radius of the
bubble in pixels.
```py
hd.bubble_chart(
... | bubble_chart | python | hyperdiv/hyperdiv | hyperdiv/components/charts/bubble_chart.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/charts/bubble_chart.py | Apache-2.0 |
def cartesian_chart(
chart_type,
*datasets,
labels=None,
colors=None,
grid_color="neutral-100",
x_axis="linear",
y_axis="linear",
hide_legend=False,
show_x_tick_labels=True,
show_y_tick_labels=True,
y_min=None,
y_max=None,
**kwargs,
):
"""
## Introduction
... |
## Introduction
`cartesian_chart` is the base chart constructor used by
@component(line_chart), @component(bar_chart),
@component(scatter_chart), and @component(bubble_chart). All these
charts work fundamentally similarly in that they render `x`/`y`
data on a grid. They only differ in how the ... | cartesian_chart | python | hyperdiv/hyperdiv | hyperdiv/components/charts/cartesian_chart.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/charts/cartesian_chart.py | Apache-2.0 |
def line_chart(
*datasets,
labels=None,
colors=None,
grid_color="neutral-100",
x_axis="linear",
y_axis="linear",
hide_legend=False,
show_x_tick_labels=True,
show_y_tick_labels=True,
y_min=None,
y_max=None,
**kwargs,
):
"""
A @component(cartesian_chart) that render... |
A @component(cartesian_chart) that renders datasets as points
connected by lines.
```py
hd.line_chart(
(1, 18, 4),
(4, 2, 28),
labels=("Jim", "Mary")
)
```
| line_chart | python | hyperdiv/hyperdiv | hyperdiv/components/charts/line_chart.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/charts/line_chart.py | Apache-2.0 |
def pie_chart(
dataset,
labels=None,
colors=None,
hide_legend=False,
doughnut=True,
**kwargs,
):
"""
A good ol pie chart. `dataset` holds the numeric sizes of the
slices.
```py
hd.pie_chart((1, 3, 12, 8))
```
`labels` gives names to the pie slices, order. And `color... |
A good ol pie chart. `dataset` holds the numeric sizes of the
slices.
```py
hd.pie_chart((1, 3, 12, 8))
```
`labels` gives names to the pie slices, order. And `colors`
specifies custom colors, in the same order. When you set `labels`,
the clickable legend will automatically be rendere... | pie_chart | python | hyperdiv/hyperdiv | hyperdiv/components/charts/pie_chart.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/charts/pie_chart.py | Apache-2.0 |
def polar_chart(
dataset,
labels=None,
colors=None,
grid_color="neutral-100",
hide_legend=False,
show_tick_labels=True,
r_min=None,
r_max=None,
**kwargs,
):
"""
A polar chart component. This works like @component(pie_chart) but
unlike a pie chart, which shows dataset diff... |
A polar chart component. This works like @component(pie_chart) but
unlike a pie chart, which shows dataset differences in the
*angles* of the slices, the polar chart keeps the angles identical
and emphasizes difference in the slice "lengths".
The `labels` argument specifies the name of each slice,... | polar_chart | python | hyperdiv/hyperdiv | hyperdiv/components/charts/polar_chart.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/charts/polar_chart.py | Apache-2.0 |
def scatter_chart(
*datasets,
labels=None,
colors=None,
grid_color="neutral-100",
x_axis="linear",
y_axis="linear",
hide_legend=False,
show_x_tick_labels=True,
show_y_tick_labels=True,
y_min=None,
y_max=None,
**kwargs,
):
"""
A @component(cartesian_chart) that ren... |
A @component(cartesian_chart) that renders datasets as points.
```py
hd.scatter_chart(
(1, 18, 4),
(4, 2, 28),
labels=("Jim", "Mary")
)
```
| scatter_chart | python | hyperdiv/hyperdiv | hyperdiv/components/charts/scatter_chart.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/charts/scatter_chart.py | Apache-2.0 |
def __init__(self, *label, **kwargs):
"""
If `*label` is provided, it will be concatenated by spaces and
stored as a `text` or `plaintext` component in the component's
body.
If `*label` is not provided, it is assumed the caller will
store the label explicitly.
`... |
If `*label` is provided, it will be concatenated by spaces and
stored as a `text` or `plaintext` component in the component's
body.
If `*label` is not provided, it is assumed the caller will
store the label explicitly.
`**kwargs` are passed up to @component(Component).... | __init__ | python | hyperdiv/hyperdiv | hyperdiv/components/common/label_component.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/common/label_component.py | Apache-2.0 |
def label(self):
"""
Reads/writes the label.
If the label slot has been manually populated by the user with
something other than a text or plaintext component, reading
this property returns `None`, and writing it does nothing.
"""
item = self._find_plaintext_chil... |
Reads/writes the label.
If the label slot has been manually populated by the user with
something other than a text or plaintext component, reading
this property returns `None`, and writing it does nothing.
| label | python | hyperdiv/hyperdiv | hyperdiv/components/common/label_component.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/common/label_component.py | Apache-2.0 |
def __init__(self, src=None, **kwargs):
"""
`src` is a local or remote path to an audio file.
If `src` is provided, a @component(media_source) will
automatically be created.
"""
super().__init__(**kwargs)
if src:
with self:
media_sourc... |
`src` is a local or remote path to an audio file.
If `src` is provided, a @component(media_source) will
automatically be created.
| __init__ | python | hyperdiv/hyperdiv | hyperdiv/components/common/media_base.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/components/common/media_base.py | Apache-2.0 |
def __init__(
self,
data,
id_column_name=None,
show_id_column=True,
rows_per_page=10,
show_pagination=True,
row_actions=None,
show_select_column=False,
vertical_scroll=False,
**kwargs,
):
"""
Parameters:
* `data... |
Parameters:
* `data`: The data dictionary to be rendered in the table. It
maps column names to the row value of each column.
* `id_column_name`: Specifies a column name, from `data`,
which identifies each row uniquely. You need to specify this
argument if you use... | __init__ | python | hyperdiv/hyperdiv | hyperdiv/ext/data_table.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/ext/data_table.py | Apache-2.0 |
def __init__(
self,
icon_name,
name,
href,
responsive_threshold=650,
font_size="small",
font_color="neutral-700",
border_radius="medium",
hover_background_color="neutral-100",
direction="horizontal",
align="center",
gap=0.5,... |
Parameters:
* `icon_name`: The icon to render in the link.
* `name`: The rendered name of the link.
* `href`: The linked URL or path.
* `responsive_threshold`: The window width, in pixels, below
which the link name is rendered in a tooltip, instead of
being ... | __init__ | python | hyperdiv/hyperdiv | hyperdiv/ext/icon_link.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/ext/icon_link.py | Apache-2.0 |
def link_group(links, drawer=None):
"""
Renders a group of links. This is usually the whole menu, in flat
menus, or the link group within a menu section, in hierarchical
menus.
If an optional `drawer` is passed, the drawer is closed when a
link is clicked.
"""
active_route = get_active_... |
Renders a group of links. This is usually the whole menu, in flat
menus, or the link group within a menu section, in hierarchical
menus.
If an optional `drawer` is passed, the drawer is closed when a
link is clicked.
| link_group | python | hyperdiv/hyperdiv | hyperdiv/ext/navigation_menu.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/ext/navigation_menu.py | Apache-2.0 |
def nav_section(name, links, drawer=None, expanded=False):
"""
Renders a collapsible section, including the section title and
expand/collapse logic.
"""
state = hd.state(expanded=expanded)
active_route = get_active_route(links)
if active_route:
state.expanded = True
with hd.box... |
Renders a collapsible section, including the section title and
expand/collapse logic.
| nav_section | python | hyperdiv/hyperdiv | hyperdiv/ext/navigation_menu.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/ext/navigation_menu.py | Apache-2.0 |
def navigation_menu(link_dict, drawer=None, expanded=False):
"""
Renders a navigation menu component. The menu is wrapped in a
@component(nav) and uses @component(link) for each link.
`link_dict` is a dictionary specifying the menu, which can be
either a flat menu, or a two-level hierarchical menu.... |
Renders a navigation menu component. The menu is wrapped in a
@component(nav) and uses @component(link) for each link.
`link_dict` is a dictionary specifying the menu, which can be
either a flat menu, or a two-level hierarchical menu.
`drawer` is an optional @component(drawer). If a drawer is pas... | navigation_menu | python | hyperdiv/hyperdiv | hyperdiv/ext/navigation_menu.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/ext/navigation_menu.py | Apache-2.0 |
def route(self, path, redirect_from=None):
"""The main decorator for defining routes:
```py-nodemo
@router.route("/foo")
def foo():
hd.text("The foo page.")
```
`redirect_from` can be a tuple of paths, such that if the user
navigates to any those pat... | The main decorator for defining routes:
```py-nodemo
@router.route("/foo")
def foo():
hd.text("The foo page.")
```
`redirect_from` can be a tuple of paths, such that if the user
navigates to any those paths, they will be redirected to this
route.
... | route | python | hyperdiv/hyperdiv | hyperdiv/ext/router.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/ext/router.py | Apache-2.0 |
def not_found(self):
"""
A decorator for defining a custom "Not Found" page, to be rendered
when a user navigates to an undefined path.
```py-nodemo
@router.not_found
def my_custom_not_found_page():
with hd.box(gap=1):
hd.markdown("# Not Found... |
A decorator for defining a custom "Not Found" page, to be rendered
when a user navigates to an undefined path.
```py-nodemo
@router.not_found
def my_custom_not_found_page():
with hd.box(gap=1):
hd.markdown("# Not Found")
hd.text("Ther... | not_found | python | hyperdiv/hyperdiv | hyperdiv/ext/router.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/ext/router.py | Apache-2.0 |
def render_not_found(self):
"""
This method can be used to programmatically invoke the `not_found` route.
```py-nodemo
@router("/users/{user_id}")
def user(user_id):
u = get_user(user_id)
if not u:
router.render_not_found()
els... |
This method can be used to programmatically invoke the `not_found` route.
```py-nodemo
@router("/users/{user_id}")
def user(user_id):
u = get_user(user_id)
if not u:
router.render_not_found()
else:
hd.text(u.name)
... | render_not_found | python | hyperdiv/hyperdiv | hyperdiv/ext/router.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/ext/router.py | Apache-2.0 |
def run(self):
"""
Calls the correct route function based on the current
@component(location) path. If there is no route corresponding
to the current path, it renders the `not_found` route.
"""
loc = hd.location()
fn = self.routes.get(loc.path)
if fn:
... |
Calls the correct route function based on the current
@component(location) path. If there is no route corresponding
to the current path, it renders the `not_found` route.
| run | python | hyperdiv/hyperdiv | hyperdiv/ext/router.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/ext/router.py | Apache-2.0 |
def __init__(
self,
logo=None,
title=None,
sidebar=True,
theme_switcher=True,
responsive_threshold=1000,
responsive_topbar_links_threshold=600,
):
"""
Parameters:
* `logo`: The path to a logo image,
e.g. `/assets/logo.svg`. T... |
Parameters:
* `logo`: The path to a logo image,
e.g. `/assets/logo.svg`. The logo will be rendered in the
top-left corner of the app.
* `title`: The title of the app, rendered in the top-left
next to the logo.
* `sidebar`: Whether to render a sidebar.
... | __init__ | python | hyperdiv/hyperdiv | hyperdiv/ext/template.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/ext/template.py | Apache-2.0 |
def add_sidebar_menu(self, link_dict, expanded=False):
"""
Adds a @component(navigation_menu) to the sidebar. `link_dict` is
passed to @component(navigation_menu) to construct the menu
and add it to the sidebar container.
The template's `drawer` property is passed into the navig... |
Adds a @component(navigation_menu) to the sidebar. `link_dict` is
passed to @component(navigation_menu) to construct the menu
and add it to the sidebar container.
The template's `drawer` property is passed into the navigation
menu as its `drawer` kwarg, so the drawer is auto-cl... | add_sidebar_menu | python | hyperdiv/hyperdiv | hyperdiv/ext/template.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/ext/template.py | Apache-2.0 |
def add_topbar_link(self, icon, name, href):
"""
Adds a @component(icon_link) component to the `topbar_links`
container. The `icon`, `name`, and `href` components are
passed to the @component(icon_link) constructor.
The app template's `responsive_topbar_links_threshold` setting
... |
Adds a @component(icon_link) component to the `topbar_links`
container. The `icon`, `name`, and `href` components are
passed to the @component(icon_link) constructor.
The app template's `responsive_topbar_links_threshold` setting
is passed down as @component(icon_link)'s
... | add_topbar_link | python | hyperdiv/hyperdiv | hyperdiv/ext/template.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/ext/template.py | Apache-2.0 |
def add_topbar_links(self, link_dict):
"""
Adds multiple @component(icon_link) components to the
`topbar_links` container in one shot.
The `link_dict` syntax is the same as the `linked_dict` passed
to @component(navigation_menu), but only flat menus are
supported in this... |
Adds multiple @component(icon_link) components to the
`topbar_links` container in one shot.
The `link_dict` syntax is the same as the `linked_dict` passed
to @component(navigation_menu), but only flat menus are
supported in this case.
| add_topbar_links | python | hyperdiv/hyperdiv | hyperdiv/ext/template.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/ext/template.py | Apache-2.0 |
def theme_switcher(icon_font_size="medium"):
"""
Renders a theme switcher inline icon and dropdown menu. When the
icon is clicked, the dropdown menu opens with Dark/Light/System
choices. The icon is a "moon" icon in dark mode and a "sun" icon
in light mode.
This menu remembers the user's settin... |
Renders a theme switcher inline icon and dropdown menu. When the
icon is clicked, the dropdown menu opens with Dark/Light/System
choices. The icon is a "moon" icon in dark mode and a "sun" icon
in light mode.
This menu remembers the user's setting in browser local storage,
so if a user chooses... | theme_switcher | python | hyperdiv/hyperdiv | hyperdiv/ext/theme_switcher.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/ext/theme_switcher.py | Apache-2.0 |
def render(self, value):
"""Specialized render function for floats.
We need this because `json` will render float('inf') and
float('-inf') as special constants that don't correspond to
anything in JS. The strings "+Infinity" and "-Infinity" behave
correctly when coerced to numbe... | Specialized render function for floats.
We need this because `json` will render float('inf') and
float('-inf') as special constants that don't correspond to
anything in JS. The strings "+Infinity" and "-Infinity" behave
correctly when coerced to numbers on the JS side.
| render | python | hyperdiv/hyperdiv | hyperdiv/prop_types/float_type.py | https://github.com/hyperdiv/hyperdiv/blob/master/hyperdiv/prop_types/float_type.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.