Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmcdonald3 committed Jul 30, 2024
1 parent 29c3fcd commit c6310d0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ protected static void writeLengthTraitMinCheckForMember(
() -> {
writer.write(
"""
raise ValueError("The size of $1L must be greater than or equal to $2L")
""",
raise ValueError("The size of $1L must be greater than or equal to $2L")
""",
memberName,
min);
});
Expand All @@ -76,8 +76,8 @@ protected static void writeLengthTraitMaxCheckForMember(
() -> {
writer.write(
"""
raise ValueError("The size of $1L must be less than or equal to $2L")
""",
raise ValueError("The size of $1L must be less than or equal to $2L")
""",
memberName,
max);
});
Expand Down Expand Up @@ -107,8 +107,8 @@ protected static void writeRangeTraitMinCheckForMember(
() -> {
writer.write(
"""
raise ValueError("$1L must be greater than or equal to $2L")
""",
raise ValueError("$1L must be greater than or equal to $2L")
""",
memberName,
min);
});
Expand Down Expand Up @@ -138,8 +138,8 @@ protected static void writeRangeTraitMaxCheckForMember(
() -> {
writer.write(
"""
raise ValueError("$1L must be less than or equal to $2L")
""",
raise ValueError("$1L must be less than or equal to $2L")
""",
memberName,
max);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ private void generateSmithyErrorToDafnyErrorBlock(
// Nothing found, we know nothing about this error. Cast as opaque
writer.write(
"""
else:
return $L.Error_Opaque(obj=e)
""",
else:
return $L.Error_Opaque(obj=e)
""",
DafnyNameResolver.getDafnyPythonTypesModuleNameForShape(serviceShape.getId(), codegenContext));
writer.addStdlibImport(DafnyNameResolver.getDafnyGeneratedPathForSmithyNamespace(serviceShape.getId().getNamespace()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private void generateNativeWrapperFunctionDefinitionForResource(

writer.addStdlibImport(SmithyNameResolver.getPythonModuleSmithygeneratedPathForSmithyNamespace(
serviceShape.getId().getNamespace(), codegenContext.settings()) + ".errors",
"_smithy_error_to_dafny_error"
"_smithy_error_to_dafny_error"
);

writer.openBlock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,26 +164,24 @@ static Optional<DafnyClientCodegenPluginSettings> fromObject(
);
}

/**
* Traverses up from the given start path,
* searching for a "smithy-build.json" file and returning its path if found.
*/
private static Optional<Path> findSmithyBuildJson(final Path start) {
if (start == null || !start.isAbsolute()) {
throw new IllegalArgumentException(
"Start path must be non-null and absolute"
);
}
Path cursor = start.normalize();
final Path root = cursor.getRoot();
// Shouldn't need to traverse more than 100 levels... but don't hang forever
for (int i = 0; !root.equals(cursor) && i < 100; i++) {
final Path config = cursor.resolve("smithy-build.json");
if (Files.exists(config)) {
return Optional.of(config);
}
cursor = cursor.getParent();
}
return Optional.empty();
/**
* Traverses up from the given start path,
* searching for a "smithy-build.json" file and returning its path if found.
*/
private static Optional<Path> findSmithyBuildJson(final Path start) {
if (start == null || !start.isAbsolute()) {
throw new IllegalArgumentException("Start path must be non-null and absolute");
}
Path cursor = start.normalize();
final Path root = cursor.getRoot();
// Shouldn't need to traverse more than 100 levels... but don't hang forever
for (int i = 0; !root.equals(cursor) && i < 100; i++) {
final Path config = cursor.resolve("smithy-build.json");
if (Files.exists(config)) {
return Optional.of(config);
}
cursor = cursor.getParent();
}
return Optional.empty();
}
}

0 comments on commit c6310d0

Please sign in to comment.