Skip to content

Commit ae97100

Browse files
committed
Add a draft for the custom pipelines documentation #237
Signed-off-by: Thomas Druez <tdruez@nexb.com>
1 parent 46b8489 commit ae97100

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

docs/custom-pipelines.rst

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
.. _custom_pipelines:
2+
3+
Custom Pipelines
4+
================
5+
6+
A pipeline always inherits from the ``Pipeline`` base class :ref:`pipeline_base_class`
7+
It define steps using the ``steps`` class method.
8+
9+
Pipeline registration
10+
---------------------
11+
12+
Built-in pipelines are located in scanpipe/pipelines/ and registered during the
13+
ScanCode.io installation.
14+
15+
Custom pipelines can be added as python files in the TBD/ directory and will be
16+
automatically registered at runtime.
17+
18+
Create a Pipeline
19+
-----------------
20+
21+
Create a new Python file ``my_pipeline.py`` in the TBD/ directory.
22+
23+
.. code-block:: python
24+
25+
from scanpipe.pipelines import Pipeline
26+
27+
class MyPipeline(Pipeline):
28+
29+
@classmethod
30+
def steps(cls):
31+
return (
32+
cls.step1,
33+
cls.step2,
34+
)
35+
36+
def step1(self):
37+
pass
38+
39+
def step2(self):
40+
pass
41+
42+
43+
.. tip::
44+
Have a look in the scanpipe/pipelines/ directory for more pipeline examples.
45+
46+
Modify existing Pipelines
47+
-------------------------
48+
49+
Any existing pipeline can be reused as a base and customized.
50+
You may want to override existing steps, add new ones, and remove some.
51+
52+
.. code-block:: python
53+
54+
from scanpipe.pipelines.scan_codebase import ScanCodebase
55+
56+
class MyCustomScan(ScanCodebase):
57+
58+
@classmethod
59+
def steps(cls):
60+
return (
61+
# Original steps from the ScanCodebase pipeline
62+
cls.copy_inputs_to_codebase_directory,
63+
cls.run_extractcode,
64+
cls.run_scancode,
65+
cls.build_inventory_from_scan,
66+
67+
# Commented-out as I'm not interested in a csv output
68+
# cls.csv_output,
69+
70+
# My extra steps
71+
cls.extra_step1,
72+
cls.extra_step2,
73+
)
74+
75+
def extra_step1(self):
76+
pass
77+
78+
def extra_step2(self):
79+
pass

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ you’ll find information on:
3232

3333
scanpipe-concepts
3434
scanpipe-pipelines
35+
custom-pipelines
3536
scanpipe-pipes
3637
scanpipe-output
3738
scanpipe-command-line

docs/scanpipe-pipelines.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Pipelines
44
=========
55

6+
.. _pipeline_base_class:
7+
68
Pipeline Base Class
79
-------------------
810
.. autoclass:: scanpipe.pipelines.Pipeline()

0 commit comments

Comments
 (0)