Skip to content

Commit dc3eb88

Browse files
committed
Add support for multiple examples per client repo
In Lettuce we have multiple APIs (async, reactive, etc) and should provide examples for each API variant. To achieve it multiple changes were introduced: - Add "label" attribute in clients configs and refer to the client example by label instead of language - Remove hardcoded mapping Label -> Lang from the config.toml - Prefix copied examples with client name to allow identical naming - Add configs for Lettuce Async and Reactive APIs
1 parent 1451a6a commit dc3eb88

File tree

12 files changed

+66
-15
lines changed

12 files changed

+66
-15
lines changed

build/components/component.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
import glob
33
import os
4+
import shutil
5+
46
import semver
57
import uuid
68
from typing import Tuple
@@ -514,13 +516,20 @@ def _copy_examples(self):
514516
if not example_id:
515517
continue
516518

517-
example_metadata = {'source': f}
519+
example_metadata = {
520+
'source': f,
521+
'language': self.get('language').lower()
522+
}
523+
524+
base_path = os.path.join(dst, example_id)
525+
mkdir_p(base_path)
526+
rsync(example_metadata['source'], base_path)
518527

519-
mkdir_p(f'{dst}/{example_id}')
520-
rsync(example_metadata['source'], f'{dst}/{example_id}/')
528+
target_path = os.path.join(base_path, f'{self.get("id")}_{os.path.basename(f)}')
529+
shutil.move(os.path.join(base_path, os.path.basename(f)), target_path)
521530

522-
example_metadata['target'] = f'{dst}/{example_id}/{os.path.basename(f)}'
523-
e = Example(self.get('language'), example_metadata['target'])
531+
example_metadata['target'] = target_path
532+
e = Example(self.get('language'), target_path)
524533
example_metadata['highlight'] = e.highlight
525534
example_metadata['hidden'] = e.hidden
526535
example_metadata['named_steps'] = e.named_steps
@@ -532,7 +541,7 @@ def _copy_examples(self):
532541
examples[example_id] = {}
533542

534543
logging.info(f'Example {example_id} processed successfully.')
535-
examples[example_id][self.get('language')] = example_metadata
544+
examples[example_id][self.get('label')] = example_metadata
536545

537546
def apply(self) -> None:
538547
logging.info(f'Applying client {self._id}')

config.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ tagManagerId = "GTM-TKZ6J9R"
4545
gitHubRepo = "https://github.com/redis/docs"
4646

4747
# Display and sort order for client examples
48-
clientsExamples = ["Python", "Node.js", "Java", "Go", "C#", "RedisVL"]
48+
clientsExamples = ["Python", "Node.js", "Java Sync", "Java Async", "Java Reactive", "Go", "C#", "RedisVL"]
4949
searchService = "/convai/api/search-service"
5050
ratingsService = "/docusight/api/rate"
5151

@@ -57,12 +57,14 @@ rdi_db_types = "cassandra|mysql|oracle|postgresql|sqlserver"
5757
rdi_cli_latest = "latest"
5858

5959
[params.clientsConfig]
60-
"Python"={lang="python", quickstartSlug="python/redis-py"}
61-
"Node.js"={lang="javascript", quickstartSlug="nodejs"}
62-
"Java"={lang="java", quickstartSlug="java/jedis"}
63-
"Go"={lang="go", quickstartSlug="go"}
64-
"C#"={lang="C#", quickstartSlug="dotnet"}
65-
"RedisVL"={lang="python", quickstartSlug="python/redis-vl"}
60+
"Python"={quickstartSlug="python/redis-py"}
61+
"Node.js"={quickstartSlug="nodejs"}
62+
"Java sync"={quickstartSlug="java/jedis"}
63+
"Java async"={quickstartSlug="java/lettuce"}
64+
"Java reactive"={quickstartSlug="java/lettuce"}
65+
"Go"={quickstartSlug="go"}
66+
"C#"={quickstartSlug="dotnet"}
67+
"RedisVL"={quickstartSlug="python/redis-vl"}
6668

6769
# Markup
6870
[markup]

data/components/go_redis.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "client",
44
"name": "go-redis",
55
"language": "Go",
6+
"label": "Go",
67
"repository": {
78
"git_uri": "https://github.com/redis/go-redis"
89
},

data/components/index.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"node_redis",
1313
"redis_py",
1414
"jedis",
15+
"lettuce_async",
16+
"lettuce_reactive",
1517
"redis_vl"
1618
],
1719
"assets": [],

data/components/jedis.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "client",
44
"name": "jedis",
55
"language": "Java",
6+
"label": "Java Sync",
67
"repository": {
78
"git_uri": "https://github.com/redis/jedis"
89
},

data/components/lettuce_async.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"id": "lettuce_async",
3+
"type": "client",
4+
"name": "lettuce_async",
5+
"language": "Java",
6+
"label": "Java Async",
7+
"repository": {
8+
"git_uri": "https://github.com/redis/lettuce"
9+
},
10+
"examples": {
11+
"git_uri": "/home/imalinovskyi/playground/lettuce-src",
12+
"dev_branch": "doctests",
13+
"path": "src/test/java/io/redis/examples/async",
14+
"pattern": "*.java"
15+
}
16+
}

data/components/lettuce_reactive.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"id": "lettuce_reactive",
3+
"type": "client",
4+
"name": "lettuce_reactive",
5+
"language": "Java",
6+
"label": "Java Reactive",
7+
"repository": {
8+
"git_uri": "https://github.com/redis/lettuce"
9+
},
10+
"examples": {
11+
"git_uri": "/home/imalinovskyi/playground/lettuce-src",
12+
"dev_branch": "doctests",
13+
"path": "src/test/java/io/redis/examples/reactive",
14+
"pattern": "*.java"
15+
}
16+
}

data/components/node_redis.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "client",
44
"name": "node-redis",
55
"language": "Node.js",
6+
"label": "Node.js",
67
"repository": {
78
"git_uri": "https://github.com/redis/node-redis"
89
},

data/components/nredisstack.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "client",
44
"name": "NRedisStack",
55
"language": "C#",
6+
"label": "C#",
67
"repository": {
78
"git_uri": "https://github.com/redis/NRedisStack"
89
},

data/components/redis_py.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "client",
44
"name": "redis-py",
55
"language": "Python",
6+
"label": "Python",
67
"repository": {
78
"git_uri": "https://github.com/redis/redis-py"
89
},

0 commit comments

Comments
 (0)