Skip to content

Commit

Permalink
fix markdown formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
geoo89 committed Jul 10, 2024
1 parent 4907ba2 commit 980ddd1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions docs/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

This toolkit consists of three components.

The first component ([](/src/rpft/parsers/common)) is RapidPro-agnostic and takes care of reader spreadsheets and converting them into internal data models and other output formats, see [](sheets.md)
The first component ([/src/rpft/parsers/common]) is RapidPro-agnostic and takes care of reader spreadsheets and converting them into internal data models and other output formats, see [sheets.md]

The second component ([](/src/rpft/parsers/creation)) defines data models for a spreadsheet format for RapidPro flows, and process spreadsheets into RapidPro flows (and back) using the first component.
The second component ([/src/rpft/parsers/creation]) defines data models for a spreadsheet format for RapidPro flows, and process spreadsheets into RapidPro flows (and back) using the first component.

The third component ([](/src/rpft/rapidpro)) defines internal representations of RapidPro flows and to read and write to a JSON format that can be import to/exported from RapidPro. It is partially entangled with the second component, as it needs to be aware of the data models of the second component to convert RapidPro flows into the spreadsheet format.
The third component ([/src/rpft/rapidpro]) defines internal representations of RapidPro flows and to read and write to a JSON format that can be import to/exported from RapidPro. It is partially entangled with the second component, as it needs to be aware of the data models of the second component to convert RapidPro flows into the spreadsheet format.

The latter two components are (poorly) documented here: [](rapidpro.md)
The latter two components are (poorly) documented here: [rapidpro.md]
11 changes: 5 additions & 6 deletions docs/models.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Models

`RowModel`s are subclasses of [`pydantic.BaseModel`]
(https://docs.pydantic.dev/latest/concepts/models/#basic-model-usage), and may
`RowModel`s are subclasses of [`pydantic.BaseModel`](https://docs.pydantic.dev/latest/concepts/models/#basic-model-usage), and may
contain basic types, lists and other models as attributes, nested arbirarily
deep. Every `Sheet` can only be parsed in the context of a given `RowModel`
(which can, however, be automatically inferred from the sheet headers, if desired).

Technically, there is no `RowModel` class, but instead it is called `ParserModel`
and is defined in [](/src/rpft/parsers/common/rowparser.py). `ParserModel` attributes have to be
and is defined in [/src/rpft/parsers/common/rowparser.py]. `ParserModel` attributes have to be
basic types, lists or `ParserModel`s.
The only addition to `pydantic.BaseModel` are the (optional) methods `header_name_to_field_name`, `field_name_to_header_name` and (for full row models) `header_name_to_field_name_with_context` that allow remapping
column header names to different model attributes.
Expand Down Expand Up @@ -46,9 +45,9 @@ How sheets and their column headers correspond to `RowModel`s is specified in

More examples can also be found in the tests:

- [](/src/rpft/parsers/common/tests/test_rowparser.py)
- [](/src/rpft/parsers/common/tests/test_full_rows.py)
- [](/src/rpft/parsers/common/tests/test_differentways.py)
- [/tests/test_rowparser.py]
- [/tests/test_full_rows.py]
- [/tests/test_differentways.py]


The `header_name_to_field_name` and related `ParserModel` methods can be used to map column headers to fields of a different name, for example:
Expand Down
4 changes: 2 additions & 2 deletions docs/rapidpro.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ There are two sheet types of particular interest
- [`DataSheet`](/src/rpft/parsers/creation/contentindexparser.py): Similar to a [`RowDataSheet`](sheets.md), however, assumed that the `RowModel` has an `ID` field, and rather than storing a list of rows, it stores an ordered dict of rows, indexed by their ID.
- [`TemplateSheet`](/src/rpft/parsers/creation/contentindexparser.py): Wrapper around `tablib.Dataset`, with template arguments.

Note: It may be worthwhile unifying the data structures used here, to be consistent with `Sheet` and `RowDataSheet` documented in [](sheets.md). Also see the discussion there why `DataSheet`s can be exported to nested JSON, while `TemplateSheet`s can only be exported to flat JSON.
Note: It may be worthwhile unifying the data structures used here, to be consistent with `Sheet` and `RowDataSheet` documented in [sheets.md]. Also see the discussion there why `DataSheet`s can be exported to nested JSON, while `TemplateSheet`s can only be exported to flat JSON.

`DataSheet`s are often used to instantiate `TemplateSheet`s, and the ContentIndexParser has mechanisms for this, see [New features documentation]. Furthermore, `DataSheet`s can also be concatenated, filtered and sorted via the `operation` column, see [here](https://docs.google.com/document/d/1Onx2RhNoWKW9BQvFrgTc5R5hcwDy1OMsLKnNB7YxQH0/edit#heading=h.c93jouk7sqq)



Relevant code: `parse_all_flows` in [](/src/rpft/parsers/creation/contentindexparser.py).
Relevant code: `parse_all_flows` in [/src/rpft/parsers/creation/contentindexparser.py].

Examples:

Expand Down
14 changes: 8 additions & 6 deletions docs/sheets.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ details of the three conversion steps below.

## Conversion between spreadsheet files and `Sheet`s

SheetReaders and `Sheet`s are defined in [](/src/rpft/parsers/sheets.py)
SheetReaders and `Sheet`s are defined in [/src/rpft/parsers/sheets.py]

The `Sheet` class wraps [`tablib.Dataset`]
(https://tablib.readthedocs.io/en/stable/api.html#dataset-object) (which is
Expand Down Expand Up @@ -95,7 +95,7 @@ instances. `RowModel`s are subclasses of [`pydantic.BaseModel`]
(https://docs.pydantic.dev/latest/concepts/models/#basic-model-usage), and may
contain basic types, lists and other models as attributes, nested arbirarily
deep. How sheets and their column headers correspond to `RowModel`s is
documented in more detail in [](models.md).
documented in more detail in [models.md].


### Forward direction
Expand Down Expand Up @@ -127,7 +127,7 @@ row into a `RowModel` instance containing the provided data.
corresponding entry of the spreadsheet in this row, and is provided
by the `SheetParser`. Column headers determine which field of the
model the column contains data for, and different ways to address fields
in the data models are supported, see [](models.md).
in the data models are supported, see [models.md].

The `RowParser` interprets the column headers and if the column contains
a non-basic type (e.g. a list or a submodel), it invokes the `CellParser`
Expand All @@ -148,7 +148,7 @@ Examples:
- `a\;b` --> 'a;b'
- `a,b|1,2` --> [['a','b'],['1','2']]

More examples can be found in [](/tests/test_cellparser.py).
More examples can be found in [/tests/test_cellparser.py].


#### Templating
Expand All @@ -160,7 +160,7 @@ With a given templating context mapping variable names to values
(e.g. {"user_name": "Chris"), such a string can be evaluated,
e.g. to `Hello Chris!`.

More examples can be found in [](/tests/test_cellparser.py).
More examples can be found in [/tests/test_cellparser.py].


##### Instantiating templated sheets
Expand Down Expand Up @@ -253,7 +253,7 @@ or a reference to an already defined model).


The CLI command `save_data_sheets` implements exporting all data sheets referenced in
a content index as (a single) nested JSON. This is implemented in `save_data_sheets` in [](/src/rpft/converters.py), using the [`ContentIndexParser`](rapidpro.md). However, it its
a content index as (a single) nested JSON. This is implemented in `save_data_sheets` in [/src/rpft/converters.py], using the [`ContentIndexParser`](rapidpro.md). However, it its
own `DataSheet` class via its `to_dict` method. It would be good to unify `DataSheet`
and `RowDataSheet`, and provide this as standalone functionality, once it's decided which meta-data describing the underlying model needs to be stored.

Expand All @@ -262,6 +262,8 @@ Below is some (untested) code outlining roughly how this could look like:

```python
from converters import create_sheet_reader
from rpft.parsers.common.model_inference import model_from_headers
import importlib

def convert_to_nested_json(input_file, sheet_format, user_data_model_module_name=None):
"""
Expand Down
1 change: 0 additions & 1 deletion src/rpft/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import shutil
from pathlib import Path

from rpft.parsers.common.model_inference import model_from_headers
from rpft.parsers.creation.contentindexparser import ContentIndexParser
from rpft.parsers.creation.tagmatcher import TagMatcher
from rpft.parsers.sheets import (
Expand Down

0 comments on commit 980ddd1

Please sign in to comment.