Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4ae949

Browse files
committed
Change pyapi links to use a pyapi: prefix
1 parent 840d6f5 commit b4ae949

4 files changed

Lines changed: 33 additions & 36 deletions

File tree

docs/python/client.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Client
22
To submit [jobs](../jobs/jobs.md) using the Python API, you first need to create
3-
a [`Client`](hyperqueue.client.Client) that connects to a running HyperQueue cluster. You have two
3+
a [`Client`](pyapi:hyperqueue.client.Client) that connects to a running HyperQueue cluster. You have two
44
options of deploying the cluster. Once you have an instance of a `Client`, you can use it to
55
[submit](submit.md) a job.
66

@@ -21,14 +21,14 @@ the node that executes the Python code, you can simply create an instance of a `
2121
passing any parameters.
2222

2323
## Using a local cluster
24-
You can use the [`LocalCluster`](hyperqueue.cluster.LocalCluster)
24+
You can use the [`LocalCluster`](pyapi:hyperqueue.cluster.LocalCluster)
2525
class to spawn a HyperQueue server and a set of workers directly on your local machine.
2626
This functionality is primarily intended for local prototyping and debugging, but it can also be
2727
used for actual computations for simple use-cases that do not require a distributed deployment of
2828
HyperQueue.
2929

3030
When you create the cluster, it will initially only start the HyperQueue server. To connect workers
31-
to it, use the [`start_worker`](hyperqueue.cluster.LocalCluster#f_start_worker) method.
31+
to it, use the [`start_worker`](pyapi:hyperqueue.cluster.LocalCluster#f_start_worker) method.
3232

3333
```python
3434
from hyperqueue import LocalCluster

docs/python/dependencies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ workflows.
1313

1414
## Defining dependencies
1515
To define a dependency between tasks, you will first need to store the
16-
[`Task`](hyperqueue.task.task.Task) instances that you get when you create a [task](submit.md#tasks).
16+
[`Task`](pyapi:hyperqueue.task.task.Task) instances that you get when you create a [task](submit.md#tasks).
1717
You can then use the `deps` parameter when creating a new task and pass an existing task instance
1818
to define a dependency:
1919

docs/python/submit.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Submitting jobs
22
You can use the Python API to submit [jobs](../jobs/jobs.md) (directed acyclic graphs of tasks)
3-
through a [`Client`](hyperqueue.client.Client). In addition to the functionality offered by the
3+
through a [`Client`](pyapi:hyperqueue.client.Client). In addition to the functionality offered by the
44
HyperQueue CLI, you can use the Python API to add [dependencies](dependencies.md) between jobs,
55
configure each task [individually](#parametrizing-tasks) and create tasks out of
66
[Python functions](#python-functions).
77

88
## Job
9-
To build a job, you first have to create an instance of the [`Job`](hyperqueue.job.Job) class.
9+
To build a job, you first have to create an instance of the [`Job`](pyapi:hyperqueue.job.Job) class.
1010

1111
```python
1212
from hyperqueue import Job
@@ -23,19 +23,19 @@ To create complex workflows, you can also specify [dependencies](dependencies.md
2323

2424
### External programs
2525
To create a task that will execute an external program, you can use the
26-
[`program`](hyperqueue.job.Job#f_program) method of a `Job`:
26+
[`program`](pyapi:hyperqueue.job.Job#f_program) method of a `Job`:
2727

2828
```python
2929
job.program(["/bin/my-program", "foo", "bar", "--arg", "42"])
3030
```
3131

3232
You can pass the program arguments or various other [parameters](#parametrizing-tasks) to the task.
33-
The `program` method will return a [`Task`](hyperqueue.task.task.Task) object that represents the
33+
The `program` method will return a [`Task`](pyapi:hyperqueue.task.task.Task) object that represents the
3434
created task. This object can be used further e.g. for defining [dependencies](dependencies.md).
3535

3636
### Python functions
3737
If you want to execute a Python function as a task, you can use the
38-
[`function`](hyperqueue.job.Job#f_function) method of a `Job`:
38+
[`function`](pyapi:hyperqueue.job.Job#f_function) method of a `Job`:
3939

4040
```python
4141
def preprocess_data(fast, path):
@@ -57,7 +57,7 @@ Python tasks can be useful to perform e.g. various data preprocessing and organi
5757
co-locate the logic of Python tasks together with the code that defines the submitted workflow (job),
5858
without the need to write an additional external script.
5959

60-
Same as with the `program` method, `function` will return a [`Task`](hyperqueue.task.task.Task)
60+
Same as with the `program` method, `function` will return a [`Task`](pyapi:hyperqueue.task.task.Task)
6161
that can used to define [dependencies](dependencies.md).
6262

6363
!!! note
@@ -71,7 +71,7 @@ a worker - this means that it needs to have access to the correct Python version
7171
that contains the `hyperqueue` package!
7272

7373
To make sure that the function will be executed in the correct Python environment, you can use
74-
[`PythonEnv`](hyperqueue.task.function.PythonEnv) and its `prologue` argument. It lets you specify
74+
[`PythonEnv`](pyapi:hyperqueue.task.function.PythonEnv) and its `prologue` argument. It lets you specify
7575
a (shell) command that will be executed before the Python interpreter that executes your
7676
function is spawned.
7777

@@ -96,20 +96,20 @@ output paths, environment variables or HyperQueue specific parameters like
9696
the CLI, where you can only use a single set of parameters for all tasks of a job, with the Python
9797
API you can specify these parameters individually for each task.
9898

99-
You can find more details in the documentation of the [`program`](hyperqueue.job.Job#f_program) or
100-
[`function`](hyperqueue.job.Job#f_function) methods.
99+
You can find more details in the documentation of the [`program`](pyapi:hyperqueue.job.Job#f_program) or
100+
[`function`](pyapi:hyperqueue.job.Job#f_function) methods.
101101

102102
## Submitting a job
103103
Once you have added some tasks to the job, you can submit it using the `Client`'s
104-
[`submit`](hyperqueue.client.Client#f_submit) method:
104+
[`submit`](pyapi:hyperqueue.client.Client#f_submit) method:
105105

106106
```python
107107
client = Client()
108108
submitted = client.submit(job)
109109
```
110110

111111
To wait until the job has finished executing, use the
112-
[`wait_for_jobs`](hyperqueue.client.Client#f_wait_for_jobs) method:
112+
[`wait_for_jobs`](pyapi:hyperqueue.client.Client#f_wait_for_jobs) method:
113113

114114
```python
115115
client.wait_for_jobs([submitted])

scripts/docs/postprocess_nedoc.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@
2121
import nedoc.config
2222
from nedoc import core
2323

24+
# Regex to match PyAPI links like [Foo](pyapi:hyperqueue.cluster.LocalCluster)
2425
# The second group is used to avoid adding the hash fragment to the link lookup key
25-
LINK_REGEX = re.compile(r"\[`.*?`]\(((?!#)[^#]*?)(#.*?)?\)")
26+
PYAPI_LINK_REGEX = re.compile(r"\[([^\]]+)\]\(pyapi:([^#]*?)(#.*?)?\)")
2627

27-
PYTHON_API_DIR = "python/apidoc"
28+
PYTHON_API_DIR = "python/apidoc/"
2829

2930
site_url = None
3031
url_map = {}
@@ -81,25 +82,21 @@ def on_files(files, config, **kwargs):
8182
logging.warning(f"WARNING: {map_file} file is missing")
8283

8384

84-
def on_page_markdown(src: str, page, config, *args, **kwargs):
85-
global api_links
86-
87-
# TODO: use Markdown parser
88-
lines = []
89-
for line_index, line in enumerate(src.splitlines(keepends=False)):
90-
# Iterate from the end to make replacing substrings easier
91-
for match in reversed(list(LINK_REGEX.finditer(line))):
92-
link_key = match.group(1)
93-
link_url = url_map.get(link_key)
94-
if link_url:
95-
api_links += 1
96-
url = f"{site_url}/{link_url}"
97-
start, end = match.span(1)
98-
line = line[:start] + url + line[end:]
99-
else:
100-
raise Exception(f"Link key {link_key} not found in {page.file.src_path} on line {line_index}")
101-
lines.append(line)
102-
return "\n".join(lines)
85+
def on_page_markdown(markdown: str, page, config, *args, **kwargs):
86+
def replace_cli_link(match):
87+
global api_links
88+
link_text = match.group(1)
89+
pyapi_key = match.group(2)
90+
hash = match.group(3) or ""
91+
link_url = url_map.get(pyapi_key)
92+
if link_url:
93+
api_links += 1
94+
pyapi_url = f"{site_url}{link_url}"
95+
return f"[{link_text}]({pyapi_url}{hash})"
96+
else:
97+
raise Exception(f"PyAPI link key {pyapi_key} not found in {page.file.src_path}")
98+
99+
return PYAPI_LINK_REGEX.sub(replace_cli_link, markdown)
103100

104101

105102
def on_post_build(config, **kwargs):

0 commit comments

Comments
 (0)