Skip to content

Commit

Permalink
fix setup.py in Python SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
dphuang2 committed Nov 1, 2023
1 parent 9e80a93 commit 4e37fae
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import io.swagger.v3.oas.models.tags.Tag;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.commons.text.StringEscapeUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.CodegenDiscriminator.MappedModel;
Expand All @@ -43,10 +45,7 @@
import org.openapitools.codegen.meta.GeneratorMetadata;
import org.openapitools.codegen.meta.Stability;
import org.openapitools.codegen.meta.features.*;
import org.openapitools.codegen.model.ModelMap;
import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.model.OperationMap;
import org.openapitools.codegen.model.OperationsMap;
import org.openapitools.codegen.model.*;
import org.openapitools.codegen.templating.CommonTemplateContentLocator;
import org.openapitools.codegen.templating.GeneratorTemplateContentLocator;
import org.openapitools.codegen.templating.HandlebarsEngineAdapter;
Expand Down Expand Up @@ -183,6 +182,25 @@ public PythonClientCodegen() {
// default HIDE_GENERATION_TIMESTAMP to true
hideGenerationTimestamp = Boolean.TRUE;

ArrayList<PythonDependency> dependencies = new ArrayList<>();
dependencies.add(new PythonDependency("certifi", "2023.7.22", ">=", ">="));
dependencies.add(new PythonDependency("python-dateutil", "2.8.2", "~=", "^"));
dependencies.add(new PythonDependency("typing_extensions", "4.3.0", "~=", "^"));
dependencies.add(new PythonDependency("urllib3", "1.26.18", "~=", "^"));
dependencies.add(new PythonDependency("frozendict", "2.3.4", "~=", "^"));
dependencies.add(new PythonDependency("aiohttp", "3.8.4", "~=", "^"));
dependencies.add(new PythonDependency("pydantic", "2.4.2", "~=", "^"));
ArrayList<PythonDependency> poetryDependencies = new ArrayList<>();
poetryDependencies.add(new PythonDependency("python", "3.7", "N/A", "^"));
poetryDependencies.addAll(dependencies);


// join dependencies with newline
additionalProperties.put("poetryDependencies", String.join("\n", poetryDependencies.stream().map(PythonDependency::poetry).collect(Collectors.toList())));

// join dependencies with ",\n"
additionalProperties.put("setupRequirements", String.join(",\n ", dependencies.stream().map(PythonDependency::setupPy).collect(Collectors.toList())));

// from https://docs.python.org/3/reference/lexical_analysis.html#keywords
setReservedWordsLowerCase(
Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.openapitools.codegen.model;

public class PythonDependency {
String name;
String version;
String setupPyModifier;
String poetryModifier;

public PythonDependency(String name, String version, String setupPyModifier, String poetryModifier) {
this.name = name;
this.version = version;
this.setupPyModifier = setupPyModifier;
this.poetryModifier = poetryModifier;
}

// example: certifi = ">=2023.7.22"
public String poetry() {
return name + " = " + "\"" + poetryModifier + version + "\"";
}

// example: certifi = ">=2023.7.22"
public String setupPy() {
return "\"" + name + " " + setupPyModifier + " " + version + "\"";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ readme = "README.md"
packages = [{include = "{{packageName}}"}]

[tool.poetry.dependencies]
python = "^3.7"
certifi = ">=2023.7.22"
python-dateutil = "^2.8.2"
typing_extensions = "^4.3.0"
urllib3 = "^1.26.18"
frozendict = "^2.3.4"
aiohttp = "^3.8.4"
pydantic = "^2.4.2"
{{{poetryDependencies}}}

[tool.poetry.group.dev.dependencies]
setuptools = "^65.5.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text()

REQUIRES = [
{{> required_libraries quoted=true }}
{{{setupRequirements}}}
]

setup(
Expand Down

0 comments on commit 4e37fae

Please sign in to comment.