From c3242a8282dc01ef6caa39067fc173af761fb958 Mon Sep 17 00:00:00 2001 From: anders-albert Date: Tue, 13 Aug 2024 09:55:59 +0200 Subject: [PATCH 1/3] refactor: replace cognite --- cognite/pygen/_core/models/data_classes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cognite/pygen/_core/models/data_classes.py b/cognite/pygen/_core/models/data_classes.py index 9bd165d24..3079800e3 100644 --- a/cognite/pygen/_core/models/data_classes.py +++ b/cognite/pygen/_core/models/data_classes.py @@ -91,8 +91,8 @@ def from_view( variable_name = create_name(base_name, data_class.variable) variable_list = create_name(base_name, data_class.variable_list) - doc_name = to_words(base_name, singularize=True) - doc_list_name = to_words(base_name, pluralize=True) + doc_name = to_words(base_name, singularize=True).replace("cognite", "Cognite") + doc_list_name = to_words(base_name, pluralize=True).replace("cognite", "Cognite") if variable_name == variable_list: variable_list = f"{variable_list}_list" raw_file_name = create_name(base_name, data_class.file) From 48f49ad735e5ed33f633916fed92dd97a499a333 Mon Sep 17 00:00:00 2001 From: anders-albert Date: Tue, 13 Aug 2024 09:58:49 +0200 Subject: [PATCH 2/3] style: exception in to words --- cognite/pygen/_core/models/data_classes.py | 4 ++-- cognite/pygen/utils/text.py | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cognite/pygen/_core/models/data_classes.py b/cognite/pygen/_core/models/data_classes.py index 3079800e3..9bd165d24 100644 --- a/cognite/pygen/_core/models/data_classes.py +++ b/cognite/pygen/_core/models/data_classes.py @@ -91,8 +91,8 @@ def from_view( variable_name = create_name(base_name, data_class.variable) variable_list = create_name(base_name, data_class.variable_list) - doc_name = to_words(base_name, singularize=True).replace("cognite", "Cognite") - doc_list_name = to_words(base_name, pluralize=True).replace("cognite", "Cognite") + doc_name = to_words(base_name, singularize=True) + doc_list_name = to_words(base_name, pluralize=True) if variable_name == variable_list: variable_list = f"{variable_list}_list" raw_file_name = create_name(base_name, data_class.file) diff --git a/cognite/pygen/utils/text.py b/cognite/pygen/utils/text.py index 3eb64c345..14cfabeb0 100644 --- a/cognite/pygen/utils/text.py +++ b/cognite/pygen/utils/text.py @@ -210,9 +210,17 @@ def to_words(string: str, pluralize: bool = False, singularize: bool = False): >>> to_words('APM_Activities', singularize=True) 'apm activity' """ - return to_snake(string, pluralize, singularize).replace("_", " ") + words = to_snake(string, pluralize, singularize).replace("_", " ") + for word, fix in _SPECIAL_WORD_FIXES.items(): + words = words.replace(word, fix) + return words +_SPECIAL_WORD_FIXES = { + "cognite": "Cognite", + " 3 d ": " 3D ", +} + # These are words which are not pluralized as we want to by inflect # Fox example, "person" becomes "people" instead of "persons", which is more grammatically correct, however, # "persons" is more consistent with the rest of the API. From 49c747ef6ee09064a73cf690f3baf54f2c72d9b6 Mon Sep 17 00:00:00 2001 From: anders-albert Date: Tue, 13 Aug 2024 10:02:28 +0200 Subject: [PATCH 3/3] style: removed extra --- .../_core/templates/typed_classes.py.jinja | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/cognite/pygen/_core/templates/typed_classes.py.jinja b/cognite/pygen/_core/templates/typed_classes.py.jinja index 50fe318f4..652b03056 100644 --- a/cognite/pygen/_core/templates/typed_classes.py.jinja +++ b/cognite/pygen/_core/templates/typed_classes.py.jinja @@ -25,10 +25,9 @@ class {{ cls.typed_properties_name }}:{% for field in cls.container_fields_sort class {{ cls.read_name }}Apply({{ cls.typed_properties_name }}, {{ cls.typed_write_bases_classes }}): """This represents the writing format of {{ cls.doc_name }}. - It is used to when data is written to CDF.{% if cls.description %} - + It is used to when data is written to CDF. +{% if cls.description %} {{ cls.description }}{% endif %} - Args: space: The space where the node is located. external_id: The external id of the {{ cls.doc_name }}.{% for field in cls.container_fields_sorted() %} @@ -58,10 +57,9 @@ class {{ cls.read_name }}Apply({{ cls.typed_properties_name }}, {{ cls.typed_wri class {{ cls.read_name }}({{ cls.typed_properties_name }}, {{ cls.typed_read_bases_classes }}): """This represents the reading format of {{ cls.doc_name }}. - It is used to when data is read from CDF.{% if cls.description %} - + It is used to when data is read from CDF. +{% if cls.description %} {{ cls.description }}{% endif %} - Args: space: The space where the node is located. external_id: The external id of the {{ cls.doc_name }}. @@ -112,10 +110,9 @@ class {{ cls.typed_properties_name }}:{% for field in cls.container_fields_sort class {{ cls.read_name }}Apply({{ cls.typed_properties_name }}, {{ cls.typed_write_bases_classes }}): """This represents the writing format of {{ cls.doc_name }}. - It is used to when data is written to CDF.{% if cls.description %} - + It is used to when data is written to CDF. +{% if cls.description %} {{ cls.description }}{% endif %} - Args: space: The space where the node is located. external_id: The external id of the {{ cls.doc_name }}. @@ -150,10 +147,9 @@ class {{ cls.read_name }}Apply({{ cls.typed_properties_name }}, {{ cls.typed_wri class {{ cls.read_name }}({{ cls.typed_properties_name }}, {{ cls.typed_read_bases_classes }}): """This represents the reading format of {{ cls.doc_name }}. - It is used to when data is read from CDF.{% if cls.description %} - + It is used to when data is read from CDF. +{% if cls.description %} {{ cls.description }}{% endif %} - Args: space: The space where the node is located. external_id: The external id of the {{ cls.doc_name }}.