-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Act and Edit are no-ops on inactive maps (#155) * resolves #145 * Improvements to the map.stderr/stdout API (#149) * Add htmap-exec Docker image and change default image to it (#153) * move test infrastructure into tests dir * add htmap-exec image * updates docs * Transferring Arbitrary Output Files (#151)
- Loading branch information
1 parent
1af6a5d
commit ac280bd
Showing
34 changed files
with
1,001 additions
and
582 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
DELIVERY_METHOD = "assume" | ||
|
||
[MAP_OPTIONS] | ||
REQUEST_DISK = "100MB" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
.. py:currentmodule:: htmap | ||
Output Files | ||
------------ | ||
|
||
If the "output" of your map function is a file, HTMap's | ||
basic functionality will not be sufficient for you. | ||
As a toy example, consider a function which takes a string and a number, and | ||
writes out a file containing that string repeated that number of times, with | ||
a space between each repetition. | ||
The file itself will be the output artifact of our function. | ||
|
||
.. code-block:: python | ||
import htmap | ||
import itertools | ||
from pathlib import Path | ||
@htmap.mapped | ||
def repeat(string, number): | ||
output_path = Path('repeated.txt') | ||
with output_path.open(mode = 'w') as f: | ||
f.write(' '.join(itertools.repeat(string, number))) | ||
This would work great locally, producing a file named ``repeated.txt`` in | ||
the directory we ran the code from. | ||
If this same code runs execute-side, the file will still be produced, but | ||
HTMap won't know that we care about the file. | ||
In fact, the map will appear to be spectacularly useless: | ||
|
||
.. code-block:: python | ||
with repeat.build_map() as mb: | ||
mb('foo', 5) | ||
mb('wiz', 3) | ||
mb('bam', 2) | ||
repeated = mb.map | ||
print(list(repeated)) | ||
# [None, None, None] | ||
A function with no ``return`` statement implicitly returns ``None``. | ||
There's no sign of our output file. | ||
|
||
We need to tell HTMap that we are producing an output file. | ||
We can do this by adding a call to an HTMap hook function in our mapped function: | ||
|
||
.. code-block:: python | ||
import htmap | ||
import itertools | ||
from pathlib import Path | ||
@htmap.mapped | ||
def repeat(string, number): | ||
output_path = Path('repeated.txt') | ||
with output_path.open(mode = 'w') as f: | ||
f.write(' '.join(itertools.repeat(string, number))) | ||
htmap.transfer_output_files(output_path) # identical, except for this line | ||
The :func:`htmap.transfer_output_files` function tells HTMap to move the files | ||
at the given paths back for us. | ||
We can then access those files using the :attr:`Map.output_files` attribute, | ||
which behaves like a sequence indexed by component numbers. | ||
The elements of the sequence are :class:`pathlib.Path` pointing to the | ||
directories containing the output files from each component, like so: | ||
|
||
.. code-block:: python | ||
with repeat.build_map() as mb: | ||
mb('foo', 5) | ||
mb('wiz', 3) | ||
mb('bam', 2) | ||
repeated = mb.map | ||
for component, base in enumerate(repeated.output_files): | ||
path = base / 'repeated.txt' | ||
print(component, path.read_text()) | ||
# 0 foo foo foo foo foo | ||
# 1 wiz wiz wiz | ||
# 2 bam bam | ||
Oops, something went wrong.