@darabonba/python-generator 1.2.15 → 1.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ChangeLog.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # ChangeLog
2
2
 
3
+ ## 1.2.16 - 2023-09-13
4
+ * Feat: support importing additional package
5
+
3
6
  ## 1.2.15 - 2022-12-26
4
7
  * Fix: array assign and access with variables name
5
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darabonba/python-generator",
3
- "version": "1.2.15",
3
+ "version": "1.2.16",
4
4
  "description": "The darabonba generator for Python",
5
5
  "main": "src/generator.js",
6
6
  "directories": {
package/src/generator.js CHANGED
@@ -15,12 +15,14 @@ class Generator {
15
15
  }
16
16
  this.lang = lang;
17
17
  this.typedef = meta[lang] && meta[lang].typedef ? meta[lang].typedef : {};
18
+ this.additionalPackage = meta[lang] && meta[lang].additionalPackage ? meta[lang].additionalPackage : [];
18
19
  this.initConfig(meta);
19
20
  }
20
21
 
21
22
  visit(ast) {
22
23
  this.imports = this.resolveImports(ast);
23
24
  this.imports.typedef = this.typedef;
25
+ this.imports.additionalPackage = this.additionalPackage;
24
26
  Object.keys(this.typedef).forEach((def) => {
25
27
  if (this.typedef[def].package && !this.imports.requirePackage.includes(this.typedef[def].package)) {
26
28
  this.imports.requirePackage.push(this.typedef[def].package);
@@ -38,6 +38,7 @@ class BaseCombinator {
38
38
  this.thirdPackageModel = imports.thirdPackageModel;
39
39
  this.typedef = imports.typedef;
40
40
  this.importsTypedef = imports.importsTypedef;
41
+ this.additionalPackage = imports.additionalPackage;
41
42
 
42
43
  _config(this.config);
43
44
  }
@@ -1234,7 +1234,8 @@ class Combinator extends CombinatorBase {
1234
1234
  let list = this.includeList.filter(node => node.from && !node.alias);
1235
1235
 
1236
1236
  let from = {};
1237
- let fromList = [];
1237
+ let fromList = [];
1238
+ fromList = fromList.concat(this.additionalPackage);
1238
1239
 
1239
1240
  list.forEach(item => {
1240
1241
  if (!from[item.from]) {
@@ -25,7 +25,7 @@ from setuptools import setup, find_packages
25
25
  """
26
26
  setup module for tea_python_tests.
27
27
 
28
- Created on 24/12/2022
28
+ Created on 13/09/2023
29
29
 
30
30
  @author: Alibaba
31
31
  """
@@ -24,7 +24,7 @@ from setuptools import setup, find_packages
24
24
  """
25
25
  setup module for tea_python_tests.
26
26
 
27
- Created on 24/12/2022
27
+ Created on 13/09/2023
28
28
 
29
29
  @author: Alibaba
30
30
  """
@@ -1,5 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # This file is auto-generated, don't edit it. Thanks.
3
+ from __future__ import annotations
3
4
  from Source.source_client import SourceClient
4
5
  from typing import List
5
6
 
@@ -1,5 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # This file is auto-generated, don't edit it. Thanks.
3
+ from __future__ import annotations
4
+
5
+
3
6
  class Client:
4
7
  def __init__(self):
5
8
  pass
@@ -1,5 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # This file is auto-generated, don't edit it. Thanks.
3
+ from __future__ import annotations
3
4
  from Tea.model import TeaModel
4
5
  from typing import List, Dict, Any, BinaryIO
5
6
 
@@ -170,7 +170,13 @@ describe('Python Generator', function () {
170
170
  github: 'https://github.com/',
171
171
  author: 'Alibaba',
172
172
  email: 'sdk-team@alibabacloud.com'
173
- }
173
+ },
174
+ additionalPackage: [
175
+ {
176
+ from: '__future__',
177
+ import: 'annotations'
178
+ }
179
+ ]
174
180
  }
175
181
  });
176
182
  });
@@ -195,7 +201,13 @@ describe('Python Generator', function () {
195
201
  {
196
202
  python: {
197
203
  package: 'tea_python_tests',
198
- clientName: 'client'
204
+ clientName: 'client',
205
+ additionalPackage: [
206
+ {
207
+ from: '__future__',
208
+ import: 'annotations'
209
+ }
210
+ ]
199
211
  }
200
212
  });
201
213
  });