Skip to content

Commit

Permalink
[PYG-269] 🥴Deal with CHIFOS (#352)
Browse files Browse the repository at this point in the history
* tests: added a failing test

* fix: to_pascal case

* build: changelog

* build: bump
  • Loading branch information
doctrino authored Nov 10, 2024
1 parent ebda032 commit c3dfd1c
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cognite/pygen/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.99.45"
__version__ = "0.99.46"
8 changes: 6 additions & 2 deletions cognite/pygen/utils/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/quickstart/cdf_streamlit.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/cognite_core/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions examples/equipment_unit/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions examples/omni/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions examples/omni_multi/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions examples/omni_sub/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions examples/scenario_instance/client/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions examples/windmill/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
Expand Down
17 changes: 16 additions & 1 deletion tests/test_unit/test_utils/test_text.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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):
Expand All @@ -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",
[
Expand Down

0 comments on commit c3dfd1c

Please sign in to comment.