|
| 1 | +Plugin architecture |
| 2 | +====================== |
| 3 | + |
| 4 | +**Project: Plugin architecture for ScanCode** |
| 5 | +--------------------------------------------- |
| 6 | + |
| 7 | +Yash D. Saraf `yashdsaraf@gmail.com <mailto:yashdsaraf@gmail.com>`_ |
| 8 | + |
| 9 | +---- |
| 10 | + |
| 11 | +This project's purpose was to create a decoupled plugin architecture for |
| 12 | +`ScanCode <https://github.com/nexB/scancode-toolkit>`_ such that it can handle plugins at different |
| 13 | +stages of a scan and can be coupled at runtime. These stages were, |
| 14 | + |
| 15 | +1. `Format <https://github.com/nexB/scancode-toolkit/issues/639>`_ : |
| 16 | +--------------------------------------------------------------------- |
| 17 | + |
| 18 | +In this stage, the plugins are supposed to run **after** the scanning is done and ``post-scan`` |
| 19 | +plugins are called. These plugins could be used for: |
| 20 | + |
| 21 | + |
| 22 | +- **converting the scanned output to the given format (say csv, json, etc.)** |
| 23 | + |
| 24 | +**HOWTO** |
| 25 | + |
| 26 | +Here, a plugin needs to add an entry in the ``scancode_output_writers`` entry point in the following |
| 27 | +format : ``'<format> = <module>:<function>'``. |
| 28 | + |
| 29 | + |
| 30 | +- ``<format>`` is the format name which will be used as the command line option name |
| 31 | + (e.g ``csv`` or ``json`` ). |
| 32 | +- ``<module>`` is a python module which implements the ``output`` hook specification. |
| 33 | +- ``<function>`` is the function to which the scan output will be passed if this plugin is called. |
| 34 | + |
| 35 | +The ``<format>`` name will be automatically added to the ``--format`` command line option and |
| 36 | +(if called) the scanned data will be passed to the plugin. |
| 37 | + |
| 38 | +2. `Post-scan <https://github.com/nexB/scancode-toolkit/issues/704>`_ : |
| 39 | +------------------------------------------------------------------------ |
| 40 | + |
| 41 | +In this stage, the plugins are supposed to run **after** the scanning is done. Some uses for these |
| 42 | +plugins were: |
| 43 | + |
| 44 | + |
| 45 | +- **summarization of scan outputs** |
| 46 | + |
| 47 | + e.g A post-scan plugin for marking ``is_source`` to true for directories with ~90% of source |
| 48 | + files. |
| 49 | + |
| 50 | +- **simplification of scan outputs** |
| 51 | + |
| 52 | + e.g The ``--only-findings`` option to return files or directories with findings for the |
| 53 | + requested scans. Files and directories without findings are omitted (not considering basic file |
| 54 | + information as findings)). |
| 55 | + |
| 56 | +This option already existed, I just ported it to a post-scan plugin. |
| 57 | + |
| 58 | +**HOWTO** |
| 59 | + |
| 60 | +Here, a plugin needs to add an entry in the ``scancode_post_scan`` entry point in the following |
| 61 | +format ``'<name> = <module>:<function>'`` |
| 62 | + |
| 63 | +- ``<name>`` is the command line option name (e.g **only-findings**). |
| 64 | +- ``<module>`` is a python module which implements the ``post_scan`` hook specification. |
| 65 | +- ``<function>`` is the function to which the scanned files will be passed if this plugin is called |
| 66 | + |
| 67 | +The command line option for this plugin will be automatically created using the ``<function>`` 's |
| 68 | +doctring as its help text and (if called) the scanned files will be passed to the plugin. |
| 69 | + |
| 70 | +3. `Pre-scan <https://github.com/nexB/scancode-toolkit/issues/719>`_ : |
| 71 | +----------------------------------------------------------------------- |
| 72 | + |
| 73 | +In this stage, the plugins are supposed to run **before** the scan starts. So the potential uses |
| 74 | +for these types of plugins were to: |
| 75 | + |
| 76 | +- **ignore files based on a given pattern (glob)** |
| 77 | +- **ignore files based on their info i.e size, type etc.** |
| 78 | +- **extract archives before scanning** |
| 79 | + |
| 80 | +**HOWTO** |
| 81 | + |
| 82 | +Here, a plugin needs to add an entry in the ``scancode_pre_scan`` entry point in the following |
| 83 | +format : ``'<name> = <module>:<class>'`` |
| 84 | + |
| 85 | + |
| 86 | +* ``<name>`` is the command line option name (e.g **ignore** ). |
| 87 | +* ``<module>`` is a python module which implements the ``pre_scan`` hook specification. |
| 88 | +* ``<class>`` is the class which is instantiated and its appropriate method is invoked if this |
| 89 | + plugin is called. This needs to extend the ``plugincode.pre_scan.PreScanPlugin`` class. |
| 90 | + |
| 91 | +The command line option for this plugin will be automatically created using the ``<class>`` 's |
| 92 | +doctring as its help text. Since there isn't a single spot where ``pre-scan`` plugins can be |
| 93 | +plugged in, more methods to ``PreScanPlugin`` class can be added which can represent different |
| 94 | +hooks, say to add or delete a scan there might be a method called ``process_scan``. |
| 95 | + |
| 96 | +If a plugin's option is passed by the user, then the ``<class>`` is instantiated with the user |
| 97 | +input and its appropriate aforementioned methods are called. |
| 98 | + |
| 99 | +4. Scan (proper): |
| 100 | +----------------- |
| 101 | + |
| 102 | +In this stage, the plugins are supposed to run **before** the scan starts and **after** the |
| 103 | +``pre-scan`` plugins are called. These plugins would have been used for |
| 104 | + |
| 105 | +- **adding or deleting scans** |
| 106 | +- **adding dependency scans (whose data could be used in other scans)** |
| 107 | + |
| 108 | +No development has been done for this stage, but it will be quite similar to ``pre-scan``. |
| 109 | + |
| 110 | +5. Other work: |
| 111 | +-------------- |
| 112 | + |
| 113 | +`Group cli options in cli help <https://github.com/nexB/scancode-toolkit/issues/709>`_ |
| 114 | + |
| 115 | +Here, the goal was to add command line options to pre-defined groups such that they are displayed |
| 116 | +in their respective groups when ``scancode -h`` or ``scancode --help`` is called. This helped to |
| 117 | +better visually represent the command line options and determine more easily what context they |
| 118 | +belong to. |
| 119 | + |
| 120 | +`Add a Resource class to hold all scanned info <https://github.com/nexB/scancode-toolkit/issues/738>`_ |
| 121 | +* ``Ongoing`` * |
| 122 | + |
| 123 | +Here, the goal was to create a ``Resource`` class, such that it holds all the scanned data for a |
| 124 | +resource (i.e a file or a directory). This class would go on to eventually encapsulate the caching |
| 125 | +logic entirely. For now, it just holds the ``info`` and ``path`` of a resource. |
| 126 | + |
| 127 | +6. What's left? |
| 128 | +--------------- |
| 129 | + |
| 130 | +- Pre-scan plugin for archive extractions |
| 131 | +- Scan (proper) plugins |
| 132 | +- More complex post-scan plugins |
| 133 | +- Support plugins written in languages other than python |
| 134 | + |
| 135 | +**Additionally, all my commits can be found** `here <https://github.com/nexB/scancode-toolkit/commits/develop?author=yashdsaraf>`_. |
0 commit comments