From c419fa414d96103b0d9bf1f5b153a13bab861617 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Fri, 12 Jul 2024 08:31:18 -0400 Subject: [PATCH] Fix various syntax issues and a jinja2 API break - Update a jinja2 import to avoid removed methods (removal in 3.1, new method appeared in 3.0 - so bump requirement to 3.0 too) - Fix a few python syntax warnings. - Update README's mention of what this repo can parse. - Fix a Practitioner typo in a comment. Fix by Kevin Wood (kwood16). --- Default/mappings.py | 2 +- README.md | 4 +--- fhirrenderer.py | 8 ++++---- fhirspec.py | 2 +- requirements.txt | 2 +- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Default/mappings.py b/Default/mappings.py index 973d96fe..dcbac0ae 100644 --- a/Default/mappings.py +++ b/Default/mappings.py @@ -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', diff --git a/README.md b/README.md index ba7dcdc5..3ab80a8e 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,7 @@ If you've come here because you want _Swift_ or _Python_ classes for FHIR data m - [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 `master` 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. diff --git a/fhirrenderer.py b/fhirrenderer.py index 5c735734..77e66c6b 100644 --- a/fhirrenderer.py +++ b/fhirrenderer.py @@ -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 @@ -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 @@ -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 @@ -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( diff --git a/fhirspec.py b/fhirspec.py index 3a9fa692..a7ec0d66 100644 --- a/fhirspec.py +++ b/fhirspec.py @@ -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) diff --git a/requirements.txt b/requirements.txt index eb82609a..182c0095 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Jinja2>=2.9.5 +Jinja2>=3.0 MarkupSafe==0.23 requests>=2.13.0 colorlog==2.10.0