|
1 | 1 | # masterdata-parser-example |
2 | | -An example parser and masterdata definitions for openBIS. |
| 2 | + |
| 3 | +An example parser for openBIS using the bam-masterdata interface. |
| 4 | + |
| 5 | +This repository is intended to be used as a template or example to be forked to generate new parsers in openBIS |
| 6 | +integrated with the `openbis-upload-helper`. |
| 7 | + |
| 8 | + |
| 9 | +## 1. Create a new parser repository |
| 10 | + |
| 11 | +You can either [fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) or [use this repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template) as a template. |
| 12 | + |
| 13 | +Click on the button **Use this template** and choose **Create a new repository**: |
| 14 | + |
| 15 | +<!--Image use this template--> |
| 16 | + |
| 17 | +You will be prompted to create a new repository. Choose: |
| 18 | +- Place to host the repository (organization or your own profile). In our case, we selected _BAMResearch_ |
| 19 | +- Give a name. We named our repository _masterdata-parser-nerxiv_ |
| 20 | +- Write a short description. |
| 21 | +- Choose _Public_ visibility. |
| 22 | + |
| 23 | +<!-- Image of create a new repository --> |
| 24 | + |
| 25 | + |
| 26 | +## 2. Define your parser entry point |
| 27 | + |
| 28 | +With your new repository created, clone it locally: |
| 29 | +```bash |
| 30 | +git clone https://github.com/BAMresearch/masterdata-parser-example.git |
| 31 | +``` |
| 32 | + |
| 33 | +**Note**: we will be using our example with this repository to showcase the commands. Please, change the corresponding |
| 34 | +paths to your own repository naming conventions. |
| 35 | + |
| 36 | +We have now a new folder, `masterdata-parser-example`, containing the following structure: |
| 37 | +```sh |
| 38 | +masterdata-parser-example |
| 39 | +├── LICENSE |
| 40 | +├── pyproject.toml |
| 41 | +├── README.md |
| 42 | +├── src |
| 43 | +│ ├── masterdata_parser_example |
| 44 | +│ ├── __init__.py |
| 45 | +│ ├── parser.py |
| 46 | +│ └── _version.py |
| 47 | +└── tests |
| 48 | + ├── __init__.py |
| 49 | + ├── conftest.py |
| 50 | + └── test_parser.py |
| 51 | +``` |
| 52 | + |
| 53 | +Below you can find an explanation of each file. You can also change the name of the package from `masterdata_parser_example` to your preferred package name `<pkg-name>`. |
| 54 | + |
| 55 | +In order to create your new parser, you have to: |
| 56 | +1. Define a new class in `src/<pck-name>/parser.py` instead of `MasterdataParserExample`. We recommend naming it `PckName`. |
| 57 | +2. Modify `src/<pck-name>/__init__.py` entry point variables: |
| 58 | +```python |
| 59 | +from .parser import PckName |
| 60 | + |
| 61 | +# Add more metadata if needed |
| 62 | +<pck_name>_entry_point = { |
| 63 | + "name": "PckName", |
| 64 | + "description": "A new parser for masterdata.", |
| 65 | + "parser_class": PckName, |
| 66 | +} |
| 67 | +``` |
| 68 | +3. Modify the `pyproject.toml` line `[project.entry-points."bam.parsers"]` to the new entry point: |
| 69 | +```toml |
| 70 | +<pck-name>_entry_point = "<pck-name>:<pck_name>_entry_point" |
| 71 | +``` |
| 72 | +4. Modify all other parts in `pyproject.toml` where the `<pck-name>` is `masterdata_parser_example` to your package name. |
| 73 | + |
| 74 | +### Explanation of the files |
| 75 | + |
| 76 | +_To be added!_ |
| 77 | + |
| 78 | +## 3. Work in your parser |
| 79 | + |
| 80 | +With the new structure, you can work in your parser to map data from your files into openBIS by modifying `src/<pck-name>/parser.py` and the testing |
| 81 | +module `tests/test_parser.py`. |
| 82 | + |
| 83 | +## 4. Add new parser to `openbis-upload-helper` |
| 84 | + |
| 85 | +Once your new parser has been developed and tested, you can add it to the registry of parsers in the `openbis-upload-helper`. We recommend you contacting the maintainers of the application with a link to your parser repository. |
0 commit comments