Skip to content

Commit

Permalink
Merge pull request #18 from grezy-software/dev
Browse files Browse the repository at this point in the history
fix(bridge): circular imports
  • Loading branch information
grezy-software authored Oct 30, 2024
2 parents 4cf77a5 + 6b28370 commit af62d67
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

- name: Create ./backend/.envs/.development files
run: |
python -m pip install cryptography
python -m pip install cryptography ruff
python ./setup/env_file_generator.py development
- name: Start containers
Expand Down
16 changes: 10 additions & 6 deletions backend/nango/bridge/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,22 @@ def make_serializer_file(

# Build customizable user's serializer
nango_serializer_name: str = f"{model_name}{'Detail' if detail else ''}NangoSerializer"
regex = r"(?<=')(.*)(?=\.)"
match = re.search(regex, str(model))
import_path = match.group(1)
data = {
"imports": [f"from api._nango_cache.{snake_case_model_name} import {nango_serializer_name}"],
"imports": [
f"from api._nango_cache.{snake_case_model_name}.{snake_case_model_name}{"_detail" if detail else ""}"
f"_nango_serializer import {nango_serializer_name}",
f"from {import_path} import {model_name}",
],
"model_name": model_name,
"serializer_name": f"{model_name}{'Detail' if detail else ''}Serializer",
"nango_serializer": nango_serializer_name,
}
self._make_serializer(folder_path=self.api_folder_path / snake_case_model_name, data=data, detail=detail)

# Build generated Nango's serializer
regex = r"(?<=')(.*)(?=\.)"
match = re.search(regex, str(model))
import_path = match.group(1)

data = {
"imports": [
f"from {import_path} import {model_name}",
Expand Down Expand Up @@ -231,7 +234,8 @@ def make_serializer_file(
],
}
data["imports"] = [
f"from api.{dico.get('model_name')}.{from_camelcase_to_snakecase(dico.get('model_name'))}_serializer import {dico.get('serializer')}"
f"from api.{from_camelcase_to_snakecase(dico.get('model_name'))}.{from_camelcase_to_snakecase(dico.get('model_name'))}"
f"_serializer import {dico.get('serializer')}"
for dico in data["detail"]["specified_fields"]
] + data["imports"]
else:
Expand Down

0 comments on commit af62d67

Please sign in to comment.