Skip to content

Commit e655f69

Browse files
authored
Fixes to get a version that runs in production (#94)
Minor changes to get this running smoothly in the wild. * Do not require clients to install the func-adl.ast package. * Fix bug in how QMetaData updates items in its dict (overriden items were ignored!) * Add a warning if there is a lambda that isn't scanned for type forwarding * Fix bug where function names were being captured during lambda resolution * Move to a single package rather than two (no more .ast). This is certianly a breaking change!
1 parent 752bc91 commit e655f69

15 files changed

+374
-279
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,30 @@ on:
55
pull_request:
66
# Run daily at 0:01 UTC
77
schedule:
8-
- cron: '1 0 * * *'
8+
- cron: "1 0 * * *"
99

1010
jobs:
1111
flake8:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v2
15-
- name: Set up Python 3.7
16-
uses: actions/setup-python@v2
17-
with:
18-
python-version: 3.7
19-
- name: Install dependencies
20-
run: |
21-
python -m pip install --upgrade pip setuptools wheel
22-
pip install --no-cache-dir -e .[complete]
23-
pip list
24-
- name: Lint with Flake8
25-
run: |
26-
flake8
27-
- name: Build the pypi package
28-
env:
29-
func_adl_version: 1.0b10
30-
run: |
31-
python setup_func_adl.py sdist bdist_wheel
32-
python setup_func_adl_ast.py sdist bdist_wheel
14+
- uses: actions/checkout@v2
15+
- name: Set up Python 3.7
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: 3.7
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip setuptools wheel
22+
pip install --no-cache-dir -e .[complete]
23+
pip list
24+
- name: Lint with Flake8
25+
run: |
26+
flake8
27+
- name: Build the pypi package
28+
env:
29+
func_adl_version: 1.0b10
30+
run: |
31+
python setup.py sdist bdist_wheel
3332
3433
test:
3534
runs-on: ${{ matrix.os }}
@@ -41,23 +40,23 @@ jobs:
4140
python-version: [3.7, 3.8, 3.9, "3.10"]
4241

4342
steps:
44-
- uses: actions/checkout@v2
45-
- name: Set up Python ${{ matrix.python-version }}
46-
uses: actions/setup-python@v2
47-
with:
48-
python-version: ${{ matrix.python-version }}
49-
- name: Install dependencies
50-
run: |
51-
python -m pip install --upgrade pip setuptools wheel
52-
pip install --no-cache-dir -e .[complete]
53-
pip list
54-
- name: Test with pytest
55-
run: |
56-
python -m pytest -r sx
57-
- name: Report coverage with Codecov
58-
if: github.event_name == 'push' && matrix.python-version == 3.9 && matrix.os == 'ubuntu-latest'
59-
uses: codecov/codecov-action@v1
60-
with:
61-
token: ${{ secrets.CODECOV_TOKEN }}
62-
file: ./coverage.xml
63-
flags: unittests
43+
- uses: actions/checkout@v2
44+
- name: Set up Python ${{ matrix.python-version }}
45+
uses: actions/setup-python@v2
46+
with:
47+
python-version: ${{ matrix.python-version }}
48+
- name: Install dependencies
49+
run: |
50+
python -m pip install --upgrade pip setuptools wheel
51+
pip install --no-cache-dir -e .[complete]
52+
pip list
53+
- name: Test with pytest
54+
run: |
55+
python -m pytest -r sx
56+
- name: Report coverage with Codecov
57+
if: github.event_name == 'push' && matrix.python-version == 3.9 && matrix.os == 'ubuntu-latest'
58+
uses: codecov/codecov-action@v1
59+
with:
60+
token: ${{ secrets.CODECOV_TOKEN }}
61+
file: ./coverage.xml
62+
flags: unittests

.github/workflows/pypi.yaml

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,23 @@ jobs:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- uses: actions/checkout@v2
13-
- name: Set up Python
14-
uses: actions/setup-python@v2
15-
with:
16-
python-version: 3.7
17-
- name: Install dependencies
18-
run: |
19-
python -m pip install --upgrade pip setuptools wheel
20-
# pip install --no-cache-dir -e .[complete]
21-
# pip list
22-
- name: Build the func_adl wheel
23-
env:
24-
func_adl_version: ${{ github.ref }}
25-
run: |
26-
python setup_func_adl.py sdist bdist_wheel
27-
- name: Publish a func_adl to PyPI
28-
uses: pypa/[email protected]
29-
with:
30-
user: __token__
31-
password: ${{ secrets.pypi_password_func_adl }}
32-
- name: Build the func_adl.ast wheel
33-
env:
34-
func_adl_version: ${{ github.ref }}
35-
run: |
36-
rm -rf dist/
37-
python setup_func_adl_ast.py sdist bdist_wheel
38-
- name: Publish a func_adl.ast to PyPI
39-
uses: pypa/[email protected]
40-
with:
41-
user: __token__
42-
password: ${{ secrets.pypi_password_func_adl_ast }}
12+
- uses: actions/checkout@v2
13+
- name: Set up Python
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: 3.7
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip setuptools wheel
20+
# pip install --no-cache-dir -e .[complete]
21+
# pip list
22+
- name: Build the func_adl wheel
23+
env:
24+
func_adl_version: ${{ github.ref }}
25+
run: |
26+
python setup.py sdist bdist_wheel
27+
- name: Publish a func_adl to PyPI
28+
uses: pypa/[email protected]
29+
with:
30+
user: __token__
31+
password: ${{ secrets.pypi_password_func_adl }}

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,6 @@
7171
"editor.codeActionsOnSave": {
7272
"source.organizeImports": true
7373
}
74-
}
74+
},
75+
"python.formatting.provider": "black"
7576
}

func_adl/ast/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from .meta_data import extract_metadata # NOQA
2-
from .call_stack import argument_stack, stack_frame # NOQA
3-
from .func_adl_ast_utils import FuncADLNodeVisitor, function_call # NOQA
41
from .aggregate_shortcuts import aggregate_node_transformer # NOQA
2+
from .call_stack import argument_stack, stack_frame # NOQA
53
from .func_adl_ast_utils import change_extension_functions_to_calls # NOQA
4+
from .func_adl_ast_utils import FuncADLNodeVisitor, function_call # NOQA
65
from .function_simplifier import simplify_chained_calls # NOQA
6+
from .meta_data import extract_metadata # NOQA

func_adl/ast/meta_data.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def extract_metadata(a: ast.AST) -> Tuple[ast.AST, List[Dict[str, str]]]:
5959

6060
def remove_empty_metadata(a: ast.AST) -> ast.AST:
6161
"""Returns a new ast with any empty `MetaData` clauses removed.
62+
The old ast is not modified.
6263
6364
Args:
6465
a (ast.AST): The AST of the query to clean up.
@@ -75,7 +76,7 @@ def visit_Call(self, node: ast.Call):
7576
if len(n.args) == 2:
7677
d = ast.literal_eval(n.args[1])
7778
if isinstance(d, dict) and len(d) == 0:
78-
return self.visit(n.args[0])
79+
return n.args[0]
7980
return n
8081

8182
return _cleaner().visit(a)
@@ -103,10 +104,14 @@ def found(self) -> Optional[Any]:
103104

104105
def generic_visit(self, node: ast.AST):
105106
q_metadata = getattr(node, "_q_metadata", None)
107+
found = False
106108
if q_metadata is not None:
107109
if metadata_name in q_metadata:
110+
found = True
108111
self._found = q_metadata[metadata_name]
109-
return super().generic_visit(node)
112+
113+
if not found:
114+
super().generic_visit(node)
110115

111116
ds_f = _finder()
112117
ds_f.visit(q.query_ast)

func_adl/object_stream.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,20 @@ def QMetaData(self, metadata: Dict[str, Any]) -> ObjectStream[T]:
199199
base_ast = self.query_ast
200200
for k, v in metadata.items():
201201
found_md = lookup_query_metadata(self, k)
202+
add_md = False
202203
if found_md is None:
204+
add_md = True
205+
elif found_md != v:
206+
logging.getLogger(__name__).info(
207+
f'Overwriting metadata "{k}" from its old value of "{found_md}" to "{v}"'
208+
)
209+
add_md = True
210+
if add_md:
203211
if first:
204212
first = False
205213
base_ast = self.MetaData({}).query_ast
206214
base_ast._q_metadata = {} # type: ignore
207215
base_ast._q_metadata[k] = v # type: ignore
208-
elif found_md != v:
209-
logging.getLogger(__name__).warning(
210-
f'Overwriting metadata "{k}" from its old value of "{found_md}" to "{v}"'
211-
)
212216

213217
return ObjectStream[T](base_ast, self.item_type)
214218

0 commit comments

Comments
 (0)