Skip to content

Commit

Permalink
Expose inspect functionality as Python API
Browse files Browse the repository at this point in the history
  • Loading branch information
codethief authored and wolfgangmuender committed Jan 15, 2024
1 parent 8ab644b commit d4ea46e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ Install and update using pip:

pip install inspectortodo

Then you can run InspectorTodo:
Then you can run InspectorTodo from the command line,

inspectortodo --help

or invoke its API from your Python code (see example below).

If you installed it in a virtualenv (which is recommended), then you always have to activate the virtualenv first.

### Example
Expand All @@ -21,6 +23,16 @@ are at project root of InspectorTodo)

inspectortodo ./tests/inspectortodo/project_for_testing "IT-\d+" --version-pattern "Release-\d+" --version 2 --versions 1,2,3

Equivalent example in Python:

```python
import inspectortodo

# The inspect() function takes the same arguments as the CLI
inspectortodo.inspect(root_dir="./tests/inspectortodo/project_for_testing", issue_pattern="IT-\d+", version_pattern="Release-\d+", version="2", versions="1,2,3")
```


### Traversing the folder tree

InspectorTodo currently features two ways of traversing the folder tree of your project: iterating over all files on
Expand Down
1 change: 1 addition & 0 deletions src/inspectortodo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .main import inspect
6 changes: 6 additions & 0 deletions src/inspectortodo/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
help="Set the log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)")
def main(root_dir, issue_pattern, version_pattern, version, versions, configfile, jira_user, jira_password, jira_token,
issue_filter_field, issue_filter_values, xml, log_level):
inspect(root_dir, issue_pattern, version_pattern, version, versions, configfile, jira_user, jira_password, jira_token,
issue_filter_field, issue_filter_values, xml, log_level)


def inspect(root_dir, issue_pattern, version_pattern=None, version=None, versions=None, configfile=None, jira_user=None, jira_password=None, jira_token=None,
issue_filter_field=None, issue_filter_values=None, xml=None, log_level="INFO"):
r"""
ROOT_DIR is the directory to inspect recursively.
Expand Down
9 changes: 8 additions & 1 deletion tests/inspectortodo/test_main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import io
import os
from xml.etree import ElementTree

from inspectortodo.main import print_xml
from inspectortodo.main import print_xml, inspect
from inspectortodo.todo import Todo

XML_CONTENT = '<?xml version="1.0" encoding="UTF-8"?>\n' \
Expand Down Expand Up @@ -36,3 +37,9 @@ def test_print_xml():

root = ElementTree.fromstring(xml_content)
assert root is not None


def test_inspect():
# This is an integration test, where we only care about the inspect()
# function not throwing.
inspect(os.path.dirname(__file__) + "/project_for_testing", r"IT-\d+")

0 comments on commit d4ea46e

Please sign in to comment.