datasette-enrichments-slow 0.1__tar.gz → 0.3a0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: datasette-enrichments-slow
3
- Version: 0.1
3
+ Version: 0.3a0
4
4
  Summary: An enrichment on a slow loop to help debug progress bars
5
5
  Author: Simon Willison
6
6
  License: Apache-2.0
@@ -14,7 +14,7 @@ Requires-Python: >=3.9
14
14
  Description-Content-Type: text/markdown
15
15
  License-File: LICENSE
16
16
  Requires-Dist: datasette
17
- Requires-Dist: datasette-enrichments
17
+ Requires-Dist: datasette-enrichments>=0.5a1
18
18
  Provides-Extra: test
19
19
  Requires-Dist: pytest; extra == "test"
20
20
  Requires-Dist: pytest-asyncio; extra == "test"
@@ -0,0 +1,65 @@
1
+ import asyncio
2
+ from datasette_enrichments import Enrichment
3
+ from datasette import hookimpl
4
+ from wtforms import Form, FloatField
5
+ import random
6
+
7
+
8
+ @hookimpl
9
+ def register_enrichments():
10
+ return [SlowEnrichment()]
11
+
12
+
13
+ class SlowEnrichment(Enrichment):
14
+ name = "Slow"
15
+ slug = "slow"
16
+ description = "An enrichment on a slow loop to help debug progress bars"
17
+ batch_size = 1
18
+
19
+ async def initialize(self, datasette, db, table, config):
20
+ pass
21
+
22
+ async def get_config_form(self, db, table):
23
+ class ConfigForm(Form):
24
+ delay = FloatField(
25
+ "Delay (seconds)",
26
+ description="How many seconds to delay for each row",
27
+ default=0.1,
28
+ )
29
+ error_rate = FloatField(
30
+ "Error rate",
31
+ description="What portion of rows should be errors? Between 0 and 1.0",
32
+ default=0,
33
+ )
34
+ pause_rate = FloatField(
35
+ "Pause rate",
36
+ description="Chance an item should pause the run, 0 to 1.0",
37
+ default=0,
38
+ )
39
+ cancel_rate = FloatField(
40
+ "Cancel rate",
41
+ description="Chance an item should cancel the run, 0 to 1.0",
42
+ default=0,
43
+ )
44
+
45
+ return ConfigForm
46
+
47
+ async def enrich_batch(
48
+ self,
49
+ db,
50
+ table,
51
+ rows,
52
+ pks,
53
+ config,
54
+ ):
55
+ error_rate = config.get("error_rate") or 0
56
+ cancel_rate = config.get("cancel_rate") or 0
57
+ pause_rate = config.get("pause_rate") or 0
58
+ for row in rows:
59
+ if error_rate and random.random() < error_rate:
60
+ raise ValueError("Error rate")
61
+ if cancel_rate and random.random() < cancel_rate:
62
+ raise self.Cancel()
63
+ if pause_rate and random.random() < pause_rate:
64
+ raise self.Pause()
65
+ await asyncio.sleep(config["delay"])
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: datasette-enrichments-slow
3
- Version: 0.1
3
+ Version: 0.3a0
4
4
  Summary: An enrichment on a slow loop to help debug progress bars
5
5
  Author: Simon Willison
6
6
  License: Apache-2.0
@@ -14,7 +14,7 @@ Requires-Python: >=3.9
14
14
  Description-Content-Type: text/markdown
15
15
  License-File: LICENSE
16
16
  Requires-Dist: datasette
17
- Requires-Dist: datasette-enrichments
17
+ Requires-Dist: datasette-enrichments>=0.5a1
18
18
  Provides-Extra: test
19
19
  Requires-Dist: pytest; extra == "test"
20
20
  Requires-Dist: pytest-asyncio; extra == "test"
@@ -1,5 +1,5 @@
1
1
  datasette
2
- datasette-enrichments
2
+ datasette-enrichments>=0.5a1
3
3
 
4
4
  [test]
5
5
  pytest
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "datasette-enrichments-slow"
3
- version = "0.1"
3
+ version = "0.3a0"
4
4
  description = "An enrichment on a slow loop to help debug progress bars"
5
5
  readme = "README.md"
6
6
  authors = [{name = "Simon Willison"}]
@@ -12,7 +12,7 @@ classifiers=[
12
12
  requires-python = ">=3.9"
13
13
  dependencies = [
14
14
  "datasette",
15
- "datasette-enrichments",
15
+ "datasette-enrichments>=0.5a1",
16
16
  ]
17
17
 
18
18
  [build-system]
@@ -1,40 +0,0 @@
1
- import asyncio
2
- from datasette_enrichments import Enrichment
3
- from datasette import hookimpl
4
- from wtforms import Form, FloatField
5
-
6
-
7
- @hookimpl
8
- def register_enrichments():
9
- return [SlowEnrichment()]
10
-
11
-
12
- class SlowEnrichment(Enrichment):
13
- name = "Slow"
14
- slug = "slow"
15
- description = "An enrichment on a slow loop to help debug progress bars"
16
- batch_size = 1
17
-
18
- async def initialize(self, datasette, db, table, config):
19
- pass
20
-
21
- async def get_config_form(self, db, table):
22
- class ConfigForm(Form):
23
- delay = FloatField(
24
- "Delay (seconds)",
25
- description="How many seconds to delay for each row",
26
- default=0.1,
27
- )
28
-
29
- return ConfigForm
30
-
31
- async def enrich_batch(
32
- self,
33
- db,
34
- table,
35
- rows,
36
- pks,
37
- config,
38
- ):
39
- for row in rows:
40
- await asyncio.sleep(config["delay"])