diff --git a/cognite/pygen/_version.py b/cognite/pygen/_version.py index 085bda964..5f290e986 100644 --- a/cognite/pygen/_version.py +++ b/cognite/pygen/_version.py @@ -1 +1 @@ -__version__ = "0.99.45" +__version__ = "0.99.46" diff --git a/cognite/pygen/utils/text.py b/cognite/pygen/utils/text.py index 7073e1c19..2f84210c3 100644 --- a/cognite/pygen/utils/text.py +++ b/cognite/pygen/utils/text.py @@ -73,9 +73,13 @@ def to_camel(string: str, pluralize: bool = False, singularize: bool = False) -> # Ensure pascal string = string[0].upper() + string[1:] pascal_splits = [string] - string_split = [] + string_split: list[str] = [] for part in pascal_splits: - string_split.extend(re.findall(r"[A-Z][a-z0-9]*", part)) + # Split on capital letters to maintain the capital letters from the original string + # The extra filter is to remove empty strings + # This can happen if the string starts with a capital letter + string_split.extend(sub for sub in re.split(r"(?=[A-Z])", part) if sub) + if not string_split: string_split = [string] if pluralize and singularize: diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4ef7e1be7..258cbff9c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -13,7 +13,12 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. -## TBD +## [0.99.46] - 24-11-11 +### Fixed +- Views with external ids on the formate `UPPERCASE_LETTERS_NUMBERS` no longer raise a NameConflict error when + generating the SDK. This was caused by a bug in `to_pascal` method used to create the data class names. + +## [0.99.45] - 24-11-10 ### Improved - When calling `generate_sdk` or `generate_sdk_notebook` you now get an improved formatting of warnings. In addition, irrelevant warnings are no longer shown. diff --git a/docs/quickstart/cdf_streamlit.md b/docs/quickstart/cdf_streamlit.md index be44349de..16b37b4c1 100644 --- a/docs/quickstart/cdf_streamlit.md +++ b/docs/quickstart/cdf_streamlit.md @@ -13,7 +13,7 @@ adding `cognite-pygen` to the installed packages under `settings`. pyodide-http==0.2.1 cognite-sdk==7.64.8 pydantic==1.10.7 -cognite-pygen==0.99.45 +cognite-pygen==0.99.46 ``` Note that we also set `pydantic` to a specific version. This is because `pygen` supports both `pydantic` `v1` and `v2`, but diff --git a/examples/cognite_core/_api_client.py b/examples/cognite_core/_api_client.py index 9be636a77..1d7de58b6 100644 --- a/examples/cognite_core/_api_client.py +++ b/examples/cognite_core/_api_client.py @@ -50,7 +50,7 @@ class CogniteCoreClient: CogniteCoreClient Generated with: - pygen = 0.99.45 + pygen = 0.99.46 cognite-sdk = 7.64.8 pydantic = 2.9.2 @@ -68,7 +68,7 @@ def __init__(self, config_or_client: CogniteClient | ClientConfig): else: raise ValueError(f"Expected CogniteClient or ClientConfig, got {type(config_or_client)}") # The client name is used for aggregated logging of Pygen Usage - client.config.client_name = "CognitePygen:0.99.45" + client.config.client_name = "CognitePygen:0.99.46" self._client = client diff --git a/examples/equipment_unit/_api_client.py b/examples/equipment_unit/_api_client.py index d90ecc020..644d34598 100644 --- a/examples/equipment_unit/_api_client.py +++ b/examples/equipment_unit/_api_client.py @@ -23,7 +23,7 @@ class EquipmentUnitClient: EquipmentUnitClient Generated with: - pygen = 0.99.45 + pygen = 0.99.46 cognite-sdk = 7.64.8 pydantic = 2.9.2 @@ -41,7 +41,7 @@ def __init__(self, config_or_client: CogniteClient | ClientConfig): else: raise ValueError(f"Expected CogniteClient or ClientConfig, got {type(config_or_client)}") # The client name is used for aggregated logging of Pygen Usage - client.config.client_name = "CognitePygen:0.99.45" + client.config.client_name = "CognitePygen:0.99.46" self._client = client diff --git a/examples/omni/_api_client.py b/examples/omni/_api_client.py index 263414beb..f506d9e60 100644 --- a/examples/omni/_api_client.py +++ b/examples/omni/_api_client.py @@ -41,7 +41,7 @@ class OmniClient: OmniClient Generated with: - pygen = 0.99.45 + pygen = 0.99.46 cognite-sdk = 7.64.8 pydantic = 2.9.2 @@ -59,7 +59,7 @@ def __init__(self, config_or_client: CogniteClient | ClientConfig): else: raise ValueError(f"Expected CogniteClient or ClientConfig, got {type(config_or_client)}") # The client name is used for aggregated logging of Pygen Usage - client.config.client_name = "CognitePygen:0.99.45" + client.config.client_name = "CognitePygen:0.99.46" self._client = client diff --git a/examples/omni_multi/_api_client.py b/examples/omni_multi/_api_client.py index dee9a2454..6b373567c 100644 --- a/examples/omni_multi/_api_client.py +++ b/examples/omni_multi/_api_client.py @@ -111,7 +111,7 @@ class OmniMultiClient: OmniMultiClient Generated with: - pygen = 0.99.45 + pygen = 0.99.46 cognite-sdk = 7.64.8 pydantic = 2.9.2 @@ -125,7 +125,7 @@ def __init__(self, config_or_client: CogniteClient | ClientConfig): else: raise ValueError(f"Expected CogniteClient or ClientConfig, got {type(config_or_client)}") # The client name is used for aggregated logging of Pygen Usage - client.config.client_name = "CognitePygen:0.99.45" + client.config.client_name = "CognitePygen:0.99.46" self.omni_multi_a = OmniMultiAAPIs(client) self.omni_multi_b = OmniMultiBAPIs(client) diff --git a/examples/omni_sub/_api_client.py b/examples/omni_sub/_api_client.py index b9f980be8..c3162413a 100644 --- a/examples/omni_sub/_api_client.py +++ b/examples/omni_sub/_api_client.py @@ -23,7 +23,7 @@ class OmniSubClient: OmniSubClient Generated with: - pygen = 0.99.45 + pygen = 0.99.46 cognite-sdk = 7.64.8 pydantic = 2.9.2 @@ -41,7 +41,7 @@ def __init__(self, config_or_client: CogniteClient | ClientConfig): else: raise ValueError(f"Expected CogniteClient or ClientConfig, got {type(config_or_client)}") # The client name is used for aggregated logging of Pygen Usage - client.config.client_name = "CognitePygen:0.99.45" + client.config.client_name = "CognitePygen:0.99.46" self._client = client diff --git a/examples/scenario_instance/client/_api_client.py b/examples/scenario_instance/client/_api_client.py index 2cf232d19..0d6bf8376 100644 --- a/examples/scenario_instance/client/_api_client.py +++ b/examples/scenario_instance/client/_api_client.py @@ -21,7 +21,7 @@ class ScenarioInstanceClient: ScenarioInstanceClient Generated with: - pygen = 0.99.45 + pygen = 0.99.46 cognite-sdk = 7.64.8 pydantic = 2.9.2 @@ -39,7 +39,7 @@ def __init__(self, config_or_client: CogniteClient | ClientConfig): else: raise ValueError(f"Expected CogniteClient or ClientConfig, got {type(config_or_client)}") # The client name is used for aggregated logging of Pygen Usage - client.config.client_name = "CognitePygen:0.99.45" + client.config.client_name = "CognitePygen:0.99.46" self._client = client diff --git a/examples/windmill/_api_client.py b/examples/windmill/_api_client.py index 3f618990d..65f586b3f 100644 --- a/examples/windmill/_api_client.py +++ b/examples/windmill/_api_client.py @@ -31,7 +31,7 @@ class WindmillClient: WindmillClient Generated with: - pygen = 0.99.45 + pygen = 0.99.46 cognite-sdk = 7.64.8 pydantic = 2.9.2 @@ -49,7 +49,7 @@ def __init__(self, config_or_client: CogniteClient | ClientConfig): else: raise ValueError(f"Expected CogniteClient or ClientConfig, got {type(config_or_client)}") # The client name is used for aggregated logging of Pygen Usage - client.config.client_name = "CognitePygen:0.99.45" + client.config.client_name = "CognitePygen:0.99.46" self._client = client diff --git a/pyproject.toml b/pyproject.toml index d39117d40..430dd604c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cognite-pygen" -version = "0.99.45" +version = "0.99.46" description = "Cognite Python SDK Generator" readme = "README.md" authors = ["Cognite "] diff --git a/tests/test_unit/test_utils/test_text.py b/tests/test_unit/test_utils/test_text.py index d2c5ee5ef..9053f2bff 100644 --- a/tests/test_unit/test_utils/test_text.py +++ b/tests/test_unit/test_utils/test_text.py @@ -1,6 +1,6 @@ import pytest -from cognite.pygen.utils.text import to_pascal, to_snake +from cognite.pygen.utils.text import to_camel, to_pascal, to_snake @pytest.mark.parametrize( @@ -17,6 +17,7 @@ ("pygen_model-power", False, False, "PygenModelPower"), ("pygen-model_power", False, False, "PygenModelPower"), ("1", False, False, "1"), + ("CFIHOS_00000001", False, False, "CFIHOS00000001"), ], ) def test_to_pascal(word: str, singularize: bool, pluralize: bool, expected: str): @@ -27,6 +28,20 @@ def test_to_pascal(word: str, singularize: bool, pluralize: bool, expected: str) assert actual == expected +@pytest.mark.parametrize( + "word, singularize, pluralize, expected", + [ + ("a_b", False, False, "aB"), + ], +) +def test_to_camel(word: str, singularize: bool, pluralize: bool, expected: str): + # Act + actual = to_camel(word, singularize=singularize, pluralize=pluralize) + + # Assert + assert actual == expected + + @pytest.mark.parametrize( "word, singularize, pluralize, expected", [