Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to GitHub actions and cleanup syntax/API use #48

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI
on:
pull_request:
push:
branches:
- main

# The goal here is to cancel older workflows when a PR is updated (because it's pointless work)
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

jobs:
generate:
name: generate
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Test generation
run: |
echo "from Default.settings import *" > settings.py
./generate.py
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.pyc
__pycache__
env
/.idea/

# ignore mappings and settings files
/mappings.py
Expand Down
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Default/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Which class names to map to resources and elements
classmap = {
'Any': 'Resource',
'Practitioner.role': 'PractRole', # to avoid Practinioner.role and PractitionerRole generating the same class
'Practitioner.role': 'PractRole', # to avoid Practitioner.role and PractitionerRole generating the same class

'boolean': 'bool',
'integer': 'int',
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
Python FHIR Parser
==================
[![Build Status](https://travis-ci.org/palfrey/fhir-parser.svg?branch=master)](https://travis-ci.org/palfrey/fhir-parser)

A Python FHIR specification parser for model class generation.
If you've come here because you want _Swift_ or _Python_ classes for FHIR data models, look at our client libraries instead:

- [Swift-FHIR][] and [Swift-SMART][]
- Python [client-py][]

The `master` branch is currently capable of parsing _STU 3, v3.0.0_.
The `develop` branch should be capable of parsing the continuous integration build and will be merged into master on new major FHIR releases.
There may be tags for specific freezes, see [releases](https://github.com/smart-on-fhir/fhir-parser/releases).
The `main` branch is currently capable of parsing _R5_.

This work is licensed under the [APACHE license][license].
FHIR® is the registered trademark of [HL7][] and is used with the permission of HL7.
Expand All @@ -26,7 +22,7 @@ These representations are then used by [Jinja][] templates to create classes in
This script does its job for the most part, but it doesn't yet handle all FHIR peculiarities and there's no guarantee the output is correct or complete.
This repository **does not include the templates and base classes** needed for class generation, you must do this yourself in your project.
You will typically add this repo as a submodule to your framework project, create a directory that contains the necessary base classes and templates, create _settings_ and _mappings_ files and run the script.
Examples on what you would need to do for Python classes can be found in _Sample/settings.py_, _Sample/mappings.py_ and _Sample/templates*_.
Examples on what you would need to do for Python classes can be found in _Default/settings.py_, _Default/mappings.py_ and _Sample/templates*_.


Use
Expand Down
8 changes: 4 additions & 4 deletions fhirrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import textwrap

from jinja2 import Environment, PackageLoader, TemplateNotFound
from jinja2.filters import environmentfilter
from jinja2.filters import pass_environment
from logger import logger


Expand Down Expand Up @@ -202,7 +202,7 @@ def render(self):
# ignores existing linebreaks when applying the wrap:
# https://github.com/mitsuhiko/jinja2/issues/175
# Here's the workaround:
@environmentfilter
@pass_environment
def do_wordwrap(environment, s, width=79, break_long_words=True, wrapstring=None):
"""
Return a copy of the string passed to the filter wrapped after
Expand All @@ -211,7 +211,7 @@ def do_wordwrap(environment, s, width=79, break_long_words=True, wrapstring=None
split words apart if they are longer than `width`.
"""
if not s:
return s
return s

if not wrapstring:
wrapstring = environment.newline_sequence
Expand All @@ -220,7 +220,7 @@ def do_wordwrap(environment, s, width=79, break_long_words=True, wrapstring=None
# Workaround: pre-split the string on \r, \r\n and \n
for component in re.split(r"\r\n|\n|\r", s):
# textwrap will eat empty strings for breakfirst. Therefore we route them around it.
if len(component) is 0:
if len(component) == 0:
accumulator.append(component)
continue
accumulator.extend(
Expand Down
2 changes: 1 addition & 1 deletion fhirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def needed_external_classes(self):
raise Exception('There is no class "{}" for property "{}" on "{}" in {}'.format(prop_cls_name, prop.name, klass.name, self.name))
else:
prop.module_name = prop_cls.module
if not prop_cls_name in needed:
if prop_cls_name not in needed:
needed.add(prop_cls_name)
needs.append(prop_cls)

Expand Down
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Jinja2>=2.9.5
MarkupSafe==0.23
colorlog>=2.10.0
jinja2>=3.0
requests>=2.13.0
colorlog==2.10.0
Comment on lines -1 to -4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MarkupSafe didn't seem to be used anymore, so I removed it (and loosened the pins on the other requirements)