Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTOOLS-373: Circular dependency fix #36

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions generate/fix-imports-for-access.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -eETuo pipefail

failure() {
local lineno="$1"
local msg="$2"
echo "Failed at $lineno: $msg"
}
trap 'failure ${LINENO} "$BASH_COMMAND"' ERR

file_path="$1"
import_statement="$2"
update_forward_refs="$3"

echo "$file_path"
echo "Fixing imports for Access"


# Check if the import statement is already present
if ! grep -Fxq "$import_statement" "$file_path"; then
# Append the import statement to the bottom of the file
echo "$import_statement" >> "$file_path"
echo "Import statement added to $file_path"
else
echo "Import statement is already present in $file_path"
fi

# Append the additional line if it's not already present
if ! grep -Fxq "$update_forward_refs" "$file_path"; then
# Ensure the file ends with a new line, then append the additional line at the bottom
echo -e "\n$update_forward_refs" >> "$file_path"
echo "Import statement added to $file_path"
else
echo "Import statement is already present in $file_path"
fi
17 changes: 15 additions & 2 deletions generate/templates/api_test.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{{>partial_header}}

from typing import List
from typing import List, Dict
import unittest
import json
from xeger import Xeger
Expand Down Expand Up @@ -55,7 +55,19 @@ class {{#operations}}Test{{classname}}(unittest.IsolatedAsyncioTestCase):
count = 0
while True:
count += 1
regex = r"{{{vendorExtensions.x-regex}}}"
# The regex map is required due to a limitation of Xeger library where it fails
# correctly generate the string from the regex
regex_map = {
Matt-Storey-Finbourne marked this conversation as resolved.
Show resolved Hide resolved
r'^(?=.*[a-zA-Z])[\w][\w +-]{2,100}$': "official-portfolios-read-only",
r'^[a-zA-Z0-9\\+/]*={0,3}$': "L=="
}

{{paramName}}: {{{dataType}}} = xegerObj.xeger(r"{{{vendorExtensions.x-regex}}}")

if regex in regex_map:
{{paramName}} = regex_map[regex]

if len({{paramName}}) >= minLength:
break
if count > 100:
Expand Down Expand Up @@ -93,7 +105,8 @@ class {{#operations}}Test{{classname}}(unittest.IsolatedAsyncioTestCase):
{{paramName}}: {{dataType}} = example["value"]
numExamples = len(examples)

{{paramName}} = {{dataType}}.from_dict({{paramName}})
if hasattr({{dataType}}, 'from_dict') and callable(getattr({{dataType}}, 'from_dict')):
{{paramName}} = {{dataType}}.from_dict({{paramName}})

{{/content}}
{{^content}}
Expand Down
16 changes: 15 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ generate-local FLAG="":
finbourne/lusid-sdk-gen-python:latest -- ./generate/generate.sh ./generate ./generate/.output /tmp/swagger.json .config.json
rm -f generate/.output/.openapi-generator-ignore
rm generate/templates/description.mustache

# split the README into two, and move one up a level
bash generate/split-readme.sh

# make the necessary post-generation fixes to the sdks using the 'oneOf' openapi feature
# caused by a bug in the python generator
if [ "{{APPLICATION_NAME}}" = "notifications" ] || [ "{{APPLICATION_NAME}}" = "workflow" ]; then just make-fix-for-one-of; fi

echo "Application name: $APPLICATION_NAME"

if [ "{{APPLICATION_NAME}}" = "access" ]; then just make-import-fix; fi

add-tests:
mkdir -p {{justfile_directory()}}/generate/.output/sdk/test/
rm -rf {{justfile_directory()}}/generate/.output/sdk/test/*
Expand Down Expand Up @@ -150,6 +153,8 @@ generate-cicd TARGET_DIR FLAG="":
# caused by a bug in the python generator
if [ "{{APPLICATION_NAME}}" = "notifications" ] || [ "{{APPLICATION_NAME}}" = "workflow" ]; then just make-fix-for-one-of; fi

if [ "{{APPLICATION_NAME}}" = "access" ]; then just make-import-fix; fi

# need to remove the created content before copying over the top of it.
# this prevents deleted content from hanging around indefinitely.
rm -rf {{TARGET_DIR}}/sdk/${PACKAGE_NAME}
Expand Down Expand Up @@ -203,3 +208,12 @@ generate-and-publish-cicd OUT_DIR FLAG="":
make-fix-for-one-of:
bash {{justfile_directory()}}/generate/fix-files-for-one-of.sh {{justfile_directory()}} ${PACKAGE_NAME} ${APPLICATION_NAME}

make-import-fix:
Matt-Storey-Finbourne marked this conversation as resolved.
Show resolved Hide resolved
bash {{justfile_directory()}}/generate/fix-imports-for-access.sh \
{{justfile_directory()}}/generate/.output/sdk/finbourne_access/models/policy_selector_definition.py \
"from finbourne_access.models.selector_definition import SelectorDefinition" \
"PolicySelectorDefinition.update_forward_refs()"
bash {{justfile_directory()}}/generate/fix-imports-for-access.sh \
{{justfile_directory()}}/generate/.output/sdk/finbourne_access/models/selector_definition.py \
"from finbourne_access.models.policy_selector_definition import PolicySelectorDefinition" \
"SelectorDefinition.update_forward_refs()"