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

chore: Python codegen runs in polymorph_code_gen and clean targets #688

Open
wants to merge 15 commits into
base: main-1.x
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .github/workflows/smithy-polymorph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ jobs:
working-directory: TestModels/SimpleTypes/SimpleString
run: make polymorph_dafny

- name: Build with all languages (smoke test for polymorph_code_gen target)
shell: bash
working-directory: TestModels/SimpleTypes/SimpleString
run: make polymorph_code_gen

- name: not-grep
if: matrix.os == 'ubuntu-latest'
uses: mattsb42-meta/[email protected]
18 changes: 9 additions & 9 deletions SmithyDafnyMakefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ _polymorph:
$(OUTPUT_JAVA_TEST) \
$(OUTPUT_DOTNET) \
$(OUTPUT_PYTHON) \
$(MODULE_NAME) \
$(if $(strip $(PYTHON_MODULE_NAME)),--python-module-name $(PYTHON_MODULE_NAME),) \
$(PYTHON_DEPENDENCY_MODULE_NAMES) \
$(OUTPUT_RUST) \
--model $(if $(DIR_STRUCTURE_V2), $(LIBRARY_ROOT)/dafny/$(SERVICE)/Model, $(SMITHY_MODEL_ROOT)) \
--dependent-model $(PROJECT_ROOT)/$(SMITHY_DEPS) \
$(patsubst %, --dependent-model $(PROJECT_ROOT)/%/Model, $($(service_deps_var))) \
$(DEPENDENCY_MODULE_NAMES) \
$(patsubst %, --namespace %, $($(namespace_var))) \
$(OUTPUT_LOCAL_SERVICE_$(SERVICE)) \
$(AWS_SDK_CMD) \
Expand All @@ -307,12 +307,12 @@ _polymorph_wrapped:
$(OUTPUT_DOTNET_WRAPPED) \
$(OUTPUT_JAVA_WRAPPED) \
$(OUTPUT_PYTHON_WRAPPED) \
$(MODULE_NAME) \
$(if $(strip $(PYTHON_MODULE_NAME)),--python-module-name $(PYTHON_MODULE_NAME),) \
$(PYTHON_DEPENDENCY_MODULE_NAMES) \
$(OUTPUT_RUST_WRAPPED) \
--model $(if $(DIR_STRUCTURE_V2),$(LIBRARY_ROOT)/dafny/$(SERVICE)/Model,$(LIBRARY_ROOT)/Model) \
--dependent-model $(PROJECT_ROOT)/$(SMITHY_DEPS) \
$(patsubst %, --dependent-model $(PROJECT_ROOT)/%/Model, $($(service_deps_var))) \
$(DEPENDENCY_MODULE_NAMES) \
--namespace $($(namespace_var)) \
--local-service-test \
$(AWS_SDK_CMD) \
Expand Down Expand Up @@ -346,6 +346,7 @@ _polymorph_code_gen: OUTPUT_DOTNET=\
$(if $(DIR_STRUCTURE_V2), --output-dotnet $(LIBRARY_ROOT)/runtimes/net/Generated/$(SERVICE)/, --output-dotnet $(LIBRARY_ROOT)/runtimes/net/Generated/)
_polymorph_code_gen: OUTPUT_JAVA=--output-java $(LIBRARY_ROOT)/runtimes/java/src/main/smithy-generated
_polymorph_code_gen: OUTPUT_JAVA_TEST=--output-java-test $(LIBRARY_ROOT)/runtimes/java/src/test/smithy-generated
_polymorph_code_gen: OUTPUT_PYTHON=--output-python $(LIBRARY_ROOT)/runtimes/python/src/$(PYTHON_MODULE_NAME)/smithygenerated
_polymorph_code_gen: _polymorph

check_polymorph_diff:
Expand Down Expand Up @@ -418,10 +419,6 @@ polymorph_python:
done

_polymorph_python: OUTPUT_PYTHON=--output-python $(LIBRARY_ROOT)/runtimes/python/src/$(PYTHON_MODULE_NAME)/smithygenerated
# Defined per-Makefile
_polymorph_python: MODULE_NAME=--library-name $(PYTHON_MODULE_NAME)
# Defined per-Makefile
_polymorph_python: DEPENDENCY_MODULE_NAMES=$(PYTHON_DEPENDENCY_MODULE_NAMES)
_polymorph_python: _polymorph

# Dependency for formatting generating Java code
Expand Down Expand Up @@ -628,6 +625,9 @@ _clean:
rm -rf $(LIBRARY_ROOT)/TestResults
rm -rf $(LIBRARY_ROOT)/runtimes/net/Generated $(LIBRARY_ROOT)/runtimes/net/bin $(LIBRARY_ROOT)/runtimes/net/obj
rm -rf $(LIBRARY_ROOT)/runtimes/net/tests/bin $(LIBRARY_ROOT)/runtimes/net/tests/obj
rm -rf $(LIBRARY_ROOT)/runtimes/python/src/**/smithygenerated
rm -rf $(LIBRARY_ROOT)/runtimes/python/src/**/internaldafny/generated
rm -rf $(LIBRARY_ROOT)/runtimes/python/test/internaldafny/generated

clean: _clean

Expand All @@ -644,7 +644,7 @@ setup_python: setup_smithy_dafny_python
setup_python:
python3 -m pip install poetry

net: polymorph_dafny transpile_python polymorph_python test_python
python: polymorph_dafny transpile_python polymorph_python test_python

# Python MUST transpile dependencies first to generate .dtr files
transpile_python: $(if $(ENABLE_EXTERN_PROCESSING), _no_extern_pre_transpile, )
Expand Down
8 changes: 4 additions & 4 deletions TestModels/Dependencies/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ clean: _clean
PYTHON_MODULE_NAME=simple_dependencies

PYTHON_DEPENDENCY_MODULE_NAMES := \
--dependency-library-name=simple.resources=simple_resources \
--dependency-library-name=simple.errors=simple_errors \
--dependency-library-name=simple.extendable.resources=simple_extendable_resources \
--dependency-library-name=simple.constraints=simple_constraints
--python-dependency-module-name=simple.resources=simple_resources \
--python-dependency-module-name=simple.errors=simple_errors \
--python-dependency-module-name=simple.extendable.resources=simple_extendable_resources \
--python-dependency-module-name=simple.constraints=simple_constraints

TRANSLATION_RECORD_PYTHON := \
--translation-record ../dafny-dependencies/StandardLibrary/runtimes/python/src/smithy_dafny_standard_library/internaldafny/generated/dafny_src-py.dtr \
Expand Down
2 changes: 1 addition & 1 deletion TestModels/MultipleModels/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ SMITHY_DEPS=dafny-dependencies/Model/traits.smithy
PYTHON_MODULE_NAME=multiple_models

PYTHON_DEPENDENCY_MODULE_NAMES := \
--dependency-library-name=simple.multiplemodels.dependencyproject=multiple_models
--python-dependency-module-name=simple.multiplemodels.dependencyproject=multiple_models

TRANSLATION_RECORD_PYTHON := \
--translation-record ../dafny-dependencies/StandardLibrary/runtimes/python/src/smithy_dafny_standard_library/internaldafny/generated/dafny_src-py.dtr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static void main(String[] args) {
.withLibraryRoot(cliArguments.libraryRoot)
.withServiceModel(serviceModel)
.withDependentModelPaths(cliArguments.dependentModelPaths)
.withDependencyLibraryNames(cliArguments.dependencyLibraryNames)
.withDependencyPythonModuleNames(cliArguments.dependencyPythonModuleNames)
.withNamespaces(cliArguments.namespaces)
.withTargetLangOutputDirs(outputDirs)
.withTargetLangTestOutputDirs(testOutputDirs)
Expand Down Expand Up @@ -156,7 +156,9 @@ public static void main(String[] args) {
cliArguments.includeDafnyFile.ifPresent(
engineBuilder::withIncludeDafnyFile
);
cliArguments.libraryName.ifPresent(engineBuilder::withLibraryName);
cliArguments.pythonModuleName.ifPresent(
engineBuilder::withPythonModuleName
);
cliArguments.patchFilesDir.ifPresent(engineBuilder::withPatchFilesDir);
final CodegenEngine engine = engineBuilder.build();
switch (cliArguments.command) {
Expand Down Expand Up @@ -199,10 +201,10 @@ private static Options getCliOptionsForBuild() {
)
.addOption(
Option
.builder("dln")
.longOpt("dependency-library-name")
.builder("pdmn")
.longOpt("python-dependency-module-name")
.desc(
"namespace-to-library-name map entry for a dependency namespace"
"<optional> if using Python, a dependency namespace-to-Python module name map entry"
)
.hasArg()
.build()
Expand All @@ -218,10 +220,10 @@ private static Options getCliOptionsForBuild() {
)
.addOption(
Option
.builder("ln")
.longOpt("library-name")
.builder("pmn")
.longOpt("python-module-name")
.desc(
"if generating for a language that uses library names (go, python), the name of the library in that language"
"<optional> if using Python, the intended Python module name for generated code"
)
.hasArg()
.build()
Expand Down Expand Up @@ -461,9 +463,9 @@ private record CliArguments(
Path libraryRoot,
Path modelPath,
Path[] dependentModelPaths,
Map<String, String> dependencyLibraryNames,
Map<String, String> dependencyPythonModuleNames,
Set<String> namespaces,
Optional<String> libraryName,
Optional<String> pythonModuleName,
Optional<Path> outputDotnetDir,
Optional<Path> outputJavaDir,
Optional<Path> testOutputJavaDir,
Expand Down Expand Up @@ -526,10 +528,10 @@ static Optional<CliArguments> parse(String[] args) throws ParseException {
// ex. `dependency-library-name=aws.cryptography.materialproviders=aws_cryptographic_materialproviders`
// maps the Smithy namespace `aws.cryptography.materialproviders` to a module name `aws_cryptographic_materialproviders`
// via a map key of "aws.cryptography.materialproviders" and a value of "aws_cryptographic_materialproviders"
final Map<String, String> dependencyNamespacesToLibraryNamesMap =
commandLine.hasOption("dependency-library-name")
final Map<String, String> dependencyNamespacesToPythonModuleNamesMap =
commandLine.hasOption("python-dependency-module-name")
? Arrays
.stream(commandLine.getOptionValues("dln"))
.stream(commandLine.getOptionValues("pdmn"))
.map(s -> s.split("="))
.collect(Collectors.toMap(i -> i[0], i -> i[1]))
: new HashMap<>();
Expand All @@ -539,8 +541,8 @@ static Optional<CliArguments> parse(String[] args) throws ParseException {
.<Set<String>>map(ns -> new HashSet<>(Arrays.asList(ns)))
.orElse(Collections.emptySet());

final Optional<String> libraryName = Optional.ofNullable(
commandLine.getOptionValue("library-name")
final Optional<String> pythonModuleName = Optional.ofNullable(
commandLine.getOptionValue("python-module-name")
);

Optional<Path> outputDafnyDir = Optional
Expand Down Expand Up @@ -628,9 +630,9 @@ static Optional<CliArguments> parse(String[] args) throws ParseException {
libraryRoot,
modelPath,
dependentModelPaths,
dependencyNamespacesToLibraryNamesMap,
dependencyNamespacesToPythonModuleNamesMap,
namespaces,
libraryName,
pythonModuleName,
outputDotnetDir,
outputJavaDir,
testOutputJavaDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1023,8 +1023,8 @@ public static class Builder {
private Path libraryRoot;
private Path patchFilesDir;
private boolean updatePatchFiles = false;
private Map<String, String> dependencyLibraryNames;
private String libraryName;
private Map<String, String> dependencyPythonModuleNames;
private String pythonModuleName;

public Builder() {}

Expand Down Expand Up @@ -1053,20 +1053,20 @@ public Builder withNamespaces(final Set<String> namespaces) {
}

/**
* Sets the directories in which to search for dependent model file(s).
* Sets the Smithy namespace-to-Python module name map.
*/
public Builder withDependencyLibraryNames(
final Map<String, String> dependencyLibraryNames
public Builder withDependencyPythonModuleNames(
final Map<String, String> dependencyPythonModuleNames
) {
this.dependencyLibraryNames = dependencyLibraryNames;
this.dependencyPythonModuleNames = dependencyPythonModuleNames;
return this;
}

/**
* Sets the Python module name for any generated Python code.
* Sets the Python module name for generated Python code.
*/
public Builder withLibraryName(final String libraryName) {
this.libraryName = libraryName;
public Builder withPythonModuleName(final String pythonModuleName) {
this.pythonModuleName = pythonModuleName;
return this;
}

Expand Down Expand Up @@ -1225,9 +1225,9 @@ public CodegenEngine build() {
: this.dependentModelPaths.clone();

final Map<String, String> dependencyLibraryNames =
this.dependencyLibraryNames == null
this.dependencyPythonModuleNames == null
? new HashMap<>()
: this.dependencyLibraryNames;
: this.dependencyPythonModuleNames;

final Map<TargetLanguage, Path> targetLangOutputDirsRaw =
Objects.requireNonNull(this.targetLangOutputDirs);
Expand Down Expand Up @@ -1283,7 +1283,7 @@ public CodegenEngine build() {
}

final Optional<String> libraryName = Optional.ofNullable(
this.libraryName
this.pythonModuleName
);

final Path libraryRoot = this.libraryRoot.toAbsolutePath().normalize();
Expand Down
Loading