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 __getitem__(self, name):
"""Attempt to parse date arithmetic syntax and apply to run_time."""
run_time = self.job_run.run_time
time_value = tron_timeutils.DateArithmetic.parse(name, run_time)
if time_value:
return time_value
raise KeyError(name) | Attempt to parse date arithmetic syntax and apply to run_time. | __getitem__ | python | Yelp/paasta | paasta_tools/tron/tron_command_context.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/tron/tron_command_context.py | Apache-2.0 |
def delta_total_seconds(td):
"""Equivalent to timedelta.total_seconds() available in Python 2.7."""
microseconds, seconds, days = td.microseconds, td.seconds, td.days
return (microseconds + (seconds + days * 24 * 3600) * 10**6) / 10**6 | Equivalent to timedelta.total_seconds() available in Python 2.7. | delta_total_seconds | python | Yelp/paasta | paasta_tools/tron/tron_timeutils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/tron/tron_timeutils.py | Apache-2.0 |
def macro_timedelta(start_date, years=0, months=0, days=0, hours=0):
"""Since datetime doesn't provide timedeltas at the year or month level,
this function generates timedeltas of the appropriate sizes.
"""
delta = datetime.timedelta(days=days, hours=hours)
new_month = start_date.month + months
... | Since datetime doesn't provide timedeltas at the year or month level,
this function generates timedeltas of the appropriate sizes.
| macro_timedelta | python | Yelp/paasta | paasta_tools/tron/tron_timeutils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/tron/tron_timeutils.py | Apache-2.0 |
def duration(start_time, end_time=None):
"""Get a timedelta between end_time and start_time, where end_time defaults
to now().
"""
if not start_time:
return None
last_time = end_time if end_time else current_time()
return last_time - start_time | Get a timedelta between end_time and start_time, where end_time defaults
to now().
| duration | python | Yelp/paasta | paasta_tools/tron/tron_timeutils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/tron/tron_timeutils.py | Apache-2.0 |
def parse(cls, date_str, dt=None):
"""Parse a date arithmetic pattern (Ex: 'shortdate-1'). Supports
date strings: shortdate, year, month, day, unixtime, daynumber.
Supports subtraction and addition operations of integers. Time unit is
based on date format (Ex: seconds for unixtime, days ... | Parse a date arithmetic pattern (Ex: 'shortdate-1'). Supports
date strings: shortdate, year, month, day, unixtime, daynumber.
Supports subtraction and addition operations of integers. Time unit is
based on date format (Ex: seconds for unixtime, days for day).
| parse | python | Yelp/paasta | paasta_tools/tron/tron_timeutils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/tron/tron_timeutils.py | Apache-2.0 |
async def test_async_ttl_cache_dont_overwrite_new_cache_entry():
"""Make sure that we don't overwrite a new cache entry that was placed
while we were waiting to handle the result of a previously cached future
"""
range_continue_event = asyncio.Event()
update_cache_event = asyncio.Event()
return_... | Make sure that we don't overwrite a new cache entry that was placed
while we were waiting to handle the result of a previously cached future
| test_async_ttl_cache_dont_overwrite_new_cache_entry | python | Yelp/paasta | tests/test_async_utils.py | https://github.com/Yelp/paasta/blob/master/tests/test_async_utils.py | Apache-2.0 |
async def test_async_ttl_cache_recover_if_cache_entry_removed():
"""Ensure we handle the case where we encounter an exception in the cached
future but another coroutine awaiting the same future ran first and alraedy
deleted the cache entry"""
range_continue_event = asyncio.Event()
num_awaiters_await... | Ensure we handle the case where we encounter an exception in the cached
future but another coroutine awaiting the same future ran first and alraedy
deleted the cache entry | test_async_ttl_cache_recover_if_cache_entry_removed | python | Yelp/paasta | tests/test_async_utils.py | https://github.com/Yelp/paasta/blob/master/tests/test_async_utils.py | Apache-2.0 |
async def test_async_ttl_cache_for_class_members_doesnt_leak_mem():
"""Ensure that we aren't leaking memory"""
x = 42
instance_caches = defaultdict(dict)
class TestClass:
@async_ttl_cache(ttl=None, cleanup_self=True, cache=instance_caches)
async def f(self):
return x
o... | Ensure that we aren't leaking memory | test_async_ttl_cache_for_class_members_doesnt_leak_mem | python | Yelp/paasta | tests/test_async_utils.py | https://github.com/Yelp/paasta/blob/master/tests/test_async_utils.py | Apache-2.0 |
def test_brutal_bounce_no_existing_apps(self):
"""When marathon is unaware of a service, brutal bounce should try to
create a marathon app."""
new_config = {"id": "foo.bar.12345"}
happy_tasks = []
assert bounce_lib.brutal_bounce(
new_config=new_config,
ne... | When marathon is unaware of a service, brutal bounce should try to
create a marathon app. | test_brutal_bounce_no_existing_apps | 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_brutal_bounce_done(self):
"""When marathon has the desired app, and there are no other copies of
the service running, brutal 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, brutal bounce should neither start nor stop
anything. | test_brutal_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_brutal_bounce_mid_bounce(self):
"""When marathon has the desired app, but there are other copies of
the service running, brutal bounce should stop the old ones."""
new_config = {"id": "foo.bar.12345", "instances": 5}
happy_tasks = [mock.Mock() for _ in range(5)]
old_app... | When marathon has the desired app, but there are other copies of
the service running, brutal bounce should stop the old ones. | test_brutal_bounce_mid_bounce | 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_brutal_bounce_old_but_no_new(self):
"""When marathon does not have the desired app, but there are other copies of
the service running, brutal bounce should stop the old ones and start
the new one."""
new_config = {"id": "foo.bar.12345", "instances": 5}
old_app_live_happ... | When marathon does not have the desired app, but there are other copies of
the service running, brutal bounce should stop the old ones and start
the new one. | test_brutal_bounce_old_but_no_new | 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_upthendown_bounce_no_existing_apps(self):
"""When marathon is unaware of a service, upthendown bounce should try to
create a marathon app."""
new_config = {"id": "foo.bar.12345"}
happy_tasks = []
assert bounce_lib.upthendown_bounce(
new_config=new_config,
... | When marathon is unaware of a service, upthendown bounce should try to
create a marathon app. | test_upthendown_bounce_no_existing_apps | 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_upthendown_bounce_old_but_no_new(self):
"""When marathon has the desired app, but there are other copies of
the service running, upthendown bounce should start the new one. but
not stop the old one yet."""
new_config = {"id": "foo.bar.12345", "instances": 5}
old_app_liv... | When marathon has the desired app, but there are other copies of
the service running, upthendown bounce should start the new one. but
not stop the old one yet. | test_upthendown_bounce_old_but_no_new | 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_upthendown_bounce_mid_bounce(self):
"""When marathon has the desired app, and there are other copies of
the service running, but the new app is not fully up, upthendown bounce
should not stop the old ones."""
new_config = {"id": "foo.bar.12345", "instances": 5}
happy_ta... | When marathon has the desired app, and there are other copies of
the service running, but the new app is not fully up, upthendown bounce
should not stop the old ones. | test_upthendown_bounce_mid_bounce | 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_upthendown_bounce_cleanup(self):
"""When marathon has the desired app, and there are other copies of
the service running, and the new app is fully up, upthendown bounce
should stop the old ones."""
new_config = {"id": "foo.bar.12345", "instances": 5}
happy_tasks = [mock... | When marathon has the desired app, and there are other copies of
the service running, and the new app is fully up, upthendown bounce
should stop the old ones. | test_upthendown_bounce_cleanup | 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_upthendown_bounce_done(self):
"""When marathon has the desired app, and there are no other copies of
the service running, upthendown bounce should neither start nor stop
anything."""
new_config = {"id": "foo.bar.12345", "instances": 5}
happy_tasks = [mock.Mock() for _ i... | When marathon has the desired app, and there are no other copies of
the service running, upthendown bounce should neither start nor stop
anything. | test_upthendown_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_crossover_bounce_no_existing_apps(self):
"""When marathon is unaware of a service, crossover bounce should try to
create a marathon app."""
new_config = {"id": "foo.bar.12345", "instances": 5}
happy_tasks = []
old_app_live_happy_tasks = []
old_app_live_unhappy_ta... | When marathon is unaware of a service, crossover bounce should try to
create a marathon app. | test_crossover_bounce_no_existing_apps | 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_crossover_bounce_old_but_no_new(self):
"""When marathon only has old apps for this service, crossover bounce should start the new one, but not kill any
old tasks yet."""
new_config = {"id": "foo.bar.12345", "instances": 5}
happy_tasks = []
old_app_live_happy_tasks = [mo... | When marathon only has old apps for this service, crossover bounce should start the new one, but not kill any
old tasks yet. | test_crossover_bounce_old_but_no_new | 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_crossover_bounce_old_app_is_happy_but_no_new_app_happy_tasks(self):
"""When marathon only has old apps for this service and margin_factor != 1,
crossover bounce should start the new app and kill some old tasks."""
new_config = {"id": "foo.bar.12345", "instances": 100}
happy_tas... | When marathon only has old apps for this service and margin_factor != 1,
crossover bounce should start the new app and kill some old tasks. | test_crossover_bounce_old_app_is_happy_but_no_new_app_happy_tasks | 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_crossover_bounce_some_unhappy_old_some_happy_old_no_new(self):
"""When marathon only has old apps for this service, and some of them are unhappy (maybe they've been recently
started), the crossover bounce should start a new app and prefer killing the unhappy tasks over the happy ones.
"... | When marathon only has old apps for this service, and some of them are unhappy (maybe they've been recently
started), the crossover bounce should start a new app and prefer killing the unhappy tasks over the happy ones.
| test_crossover_bounce_some_unhappy_old_some_happy_old_no_new | 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_crossover_bounce_some_unhappy_old_no_happy_old_no_new_tasks_no_excess(
self,
):
"""When marathon only has old apps for this service, and all of their tasks are unhappy, and there are no excess
tasks, the crossover bounce should start a new app and not kill any old tasks.
"""... | When marathon only has old apps for this service, and all of their tasks are unhappy, and there are no excess
tasks, the crossover bounce should start a new app and not kill any old tasks.
| test_crossover_bounce_some_unhappy_old_no_happy_old_no_new_tasks_no_excess | 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_crossover_bounce_lots_of_unhappy_old_no_happy_old_no_new(self):
"""When marathon has a new app and multiple old apps, no new tasks are up, all old tasks are unhappy, and there
are too many tasks running, the crossover bounce should kill some (but not all) of the old
tasks.
This... | When marathon has a new app and multiple old apps, no new tasks are up, all old tasks are unhappy, and there
are too many tasks running, the crossover bounce should kill some (but not all) of the old
tasks.
This represents a situation where
| test_crossover_bounce_lots_of_unhappy_old_no_happy_old_no_new | 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_crossover_bounce_lots_of_unhappy_old_some_happy_old_new_app_exists_no_new_tasks(
self,
):
"""When marathon has a new app and multiple old apps, no new tasks are up, one of the old apps is healthy and
the other is not, only unhealthy tasks should get killed.
"""
new_... | When marathon has a new app and multiple old apps, no new tasks are up, one of the old apps is healthy and
the other is not, only unhealthy tasks should get killed.
| test_crossover_bounce_lots_of_unhappy_old_some_happy_old_new_app_exists_no_new_tasks | 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_crossover_bounce_mid_bounce(self):
"""When marathon has the desired app, and there are other copies of the service running, but the new app is not
fully up, crossover bounce should only stop a few of the old instances."""
new_config = {"id": "foo.bar.12345", "instances": 5}
hap... | When marathon has the desired app, and there are other copies of the service running, but the new app is not
fully up, crossover bounce should only stop a few of the old instances. | test_crossover_bounce_mid_bounce | 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_crossover_bounce_mid_bounce_some_happy_old_some_unhappy_old(self):
"""When marathon has the desired app, and there are other copies of the service running, and some of those
older tasks are unhappy, we should prefer killing the unhappy tasks."""
new_config = {"id": "foo.bar.12345", "in... | When marathon has the desired app, and there are other copies of the service running, and some of those
older tasks are unhappy, we should prefer killing the unhappy tasks. | test_crossover_bounce_mid_bounce_some_happy_old_some_unhappy_old | 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_crossover_bounce_mid_bounce_some_happy_old_lots_of_unhappy_old(self):
"""When marathon has the desired app, and there are other copies of the service running, and there are more
unhappy old tasks than excess tasks, we should only kill unhappy tasks.
"""
new_config = {"id": "foo... | When marathon has the desired app, and there are other copies of the service running, and there are more
unhappy old tasks than excess tasks, we should only kill unhappy tasks.
| test_crossover_bounce_mid_bounce_some_happy_old_lots_of_unhappy_old | 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_crossover_bounce_mid_bounce_no_happy_old_lots_of_unhappy_old(self):
"""When marathon has the desired app, and there are other copies of the service running, but none of the old
tasks are happy, and there are excess tasks, we should kill some (but not all) unhappy old tasks."""
new_confi... | When marathon has the desired app, and there are other copies of the service running, but none of the old
tasks are happy, and there are excess tasks, we should kill some (but not all) unhappy old tasks. | test_crossover_bounce_mid_bounce_no_happy_old_lots_of_unhappy_old | 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_crossover_bounce_done(self):
"""When marathon has the desired app, and there are no other copies of
the service running, crossover bounce should neither start nor stop
anything."""
new_config = {"id": "foo.bar.12345", "instances": 5}
happy_tasks = [mock.Mock() for _ in ... | When marathon has the desired app, and there are no other copies of
the service running, crossover bounce should neither start nor stop
anything. | test_crossover_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_downthenup_bounce_no_existing_apps(self):
"""When marathon is unaware of a service, downthenup bounce should try to
create a marathon app."""
new_config = {"id": "foo.bar.12345", "instances": 5}
happy_tasks = []
old_app_live_happy_tasks = []
old_app_live_unhappy_... | When marathon is unaware of a service, downthenup bounce should try to
create a marathon app. | test_downthenup_bounce_no_existing_apps | 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_downthenup_bounce_old_but_no_new(self):
"""When marathon has only old copies of the service, downthenup_bounce should kill them and not start a new one
yet."""
new_config = {"id": "foo.bar.12345", "instances": 5}
happy_tasks = []
old_app_live_happy_tasks = [mock.Mock() f... | When marathon has only old copies of the service, downthenup_bounce should kill them and not start a new one
yet. | test_downthenup_bounce_old_but_no_new | 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_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 |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves Python code examples from Django repository that contain 'django' in the code, which helps identify Django-specific code snippets but provides limited analytical insights beyond basic filtering.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.