Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some sphinx documentation formatting fixes #66

Merged
merged 3 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions b2luigi/batch/processes/gbasf2.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Gbasf2Process(BatchProcess):
``B_ntuple.root``), but a collection of root files, one for each file in
the input data set, in a directory with the base name of the root
files, e.g.::

<task output directory>
├── B_ntuple.root
│   └── B_ntuple_0.root
Expand Down
94 changes: 48 additions & 46 deletions b2luigi/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,40 @@ class Task(luigi.Task):
the parameters of the task.
See :ref:`quick-start-label` on information on how to use the methods.
Example::
Example:
.. code-block:: python
class MyAverageTask(b2luigi.Task):
def requires(self):
for i in range(100):
yield self.clone(MyNumberTask, some_parameter=i)
class MyAverageTask(b2luigi.Task):
def requires(self):
for i in range(100):
yield self.clone(MyNumberTask, some_parameter=i)
def output(self):
yield self.add_to_output("average.txt")
def output(self):
yield self.add_to_output("average.txt")
def run(self):
# Build the mean
summed_numbers = 0
counter = 0
for input_file in self.get_input_file_names("output_file.txt"):
with open(input_file, "r") as f:
summed_numbers += float(f.read())
counter += 1
def run(self):
# Build the mean
summed_numbers = 0
counter = 0
for input_file in self.get_input_file_names("output_file.txt"):
with open(input_file, "r") as f:
summed_numbers += float(f.read())
counter += 1
average = summed_numbers / counter
average = summed_numbers / counter
with self.get_output_file("average.txt").open("w") as f:
f.write(f"{average}\\n")
with self.get_output_file("average.txt").open("w") as f:
f.write(f"{average}\\n")
"""
def add_to_output(self, output_file_name):
"""
Call this in your output() function to add a target to the list of files,
this task will output.
Always use in combination with `yield`.
This function will automatically add all current parameter values to
This function will automatically add all current parameter values to
the file name when used in the form
result_dir/param_1=value/param_2=value/output_file_name
This function will automatically use a ``LocalTarget``.
Expand Down Expand Up @@ -93,43 +94,44 @@ def get_input_file_names(self, key=None):
"""
return self._transform_input(self.input(), key)


def get_input_file_names_from_dict(self, requirement_key, key=None):
"""
Get a dictionary of input file names of the tasks, which are defined in our requirements.
The requirement method should return a dict whose values are generator expressions (!)
yielding required task objects.
Example:
.. code-block:: python
class TaskB(luigi.Task):
def requires(self):
return {
"a": (TaskA(5.0, i) for i in range(100)),
"b": (TaskA(1.0, i) for i in range(100)),
}
def run(self):
result_a = do_something_with_a(
self.get_input_file_names_from_dict("a")
)
result_b = do_something_with_b(
self.get_input_file_names_from_dict("b")
)
combine_a_and_b(
result_a,
result_b,
self.get_output_file_name("combined_results.txt")
)
class TaskB(luigi.Task):
def output(self):
yield self.add_to_output("combined_results.txt")
def requires(self):
return {
"a": (TaskA(5.0, i) for i in range(100)),
"b": (TaskA(1.0, i) for i in range(100)),
}
def run(self):
result_a = do_something_with_a(
self.get_input_file_names_from_dict("a")
)
result_b = do_something_with_b(
self.get_input_file_names_from_dict("b")
)
Either use the key argument or dictionary indexing with the key given to :obj:`add_to_output`
to get back a list (!) of file paths.
combine_a_and_b(
result_a,
result_b,
self.get_output_file_name("combined_results.txt")
)
def output(self):
yield self.add_to_output("combined_results.txt")
Either use the key argument or dictionary indexing with the key given to :obj:`add_to_output`
to get back a list (!) of file paths.
Args:
requirement_key (:obj:`str`): Specifies the required task expression.
Expand Down
2 changes: 1 addition & 1 deletion docs/documentation/b2luigi.basf2_helper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ b2luigi.basf2\_helper.utils module
.. automodule:: b2luigi.basf2_helper.utils
:members:
:undoc-members:
:show-inheritance:
:show-inheritance: