Skip to content

Commit 3bcf4a9

Browse files
committed
Add tests verifying sdist includes tests and examples
Add test_sdist.py for ui/sdk, dev_tools/language_server, and contrib that assert pyproject.toml [tool.flit.sdist] configuration: - tests/** is in include (sdk, lsp) or not in exclude (contrib) - examples/** is in include (sdk, contrib) - scripts/** is in include (contrib) — addresses reviewer feedback - Binary files (*.parquet, *.pkl, *.ipynb, *.png) are excluded Also add test_flit_sdist_includes_tests to ui/backend/tests/test_build.py to match the existing pattern for build/** verification. Include contrib/scripts/** in sdist per reviewer request — contains version_check.py used for release validation.
1 parent 737e57e commit 3bcf4a9

5 files changed

Lines changed: 297 additions & 0 deletions

File tree

contrib/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ include = [
7070
"DISCLAIMER",
7171
"requirements.txt",
7272
"examples/**",
73+
"scripts/**",
7374
]
7475
exclude = [
7576
".git/**",

contrib/tests/test_sdist.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
"""Tests verifying that the sdist includes examples and does not exclude tests.
19+
20+
Per Apache release policy, voters must be able to build from source
21+
and run tests to validate. Contrib tests live inside the package
22+
(hamilton/contrib/dagworks/*/test_*.py), so the key requirement is
23+
that tests/** is NOT in the exclude list. Examples are included via
24+
a symlink to ../examples/contrib/.
25+
"""
26+
27+
import sys
28+
from pathlib import Path
29+
30+
if sys.version_info >= (3, 11):
31+
import tomllib
32+
else:
33+
import tomli as tomllib
34+
35+
36+
def get_contrib_dir() -> Path:
37+
return Path(__file__).resolve().parent.parent
38+
39+
40+
def load_sdist_config() -> dict:
41+
pyproject = get_contrib_dir() / "pyproject.toml"
42+
with open(pyproject, "rb") as f:
43+
config = tomllib.load(f)
44+
return config["tool"]["flit"]["sdist"]
45+
46+
47+
class TestSdistDoesNotExcludeTests:
48+
"""Verify tests inside the package are not excluded from sdist."""
49+
50+
def test_tests_not_in_sdist_exclude(self):
51+
sdist = load_sdist_config()
52+
excludes = sdist.get("exclude", [])
53+
assert "tests/**" not in excludes, (
54+
"pyproject.toml [tool.flit.sdist] must not exclude 'tests/**'. "
55+
"Apache release policy requires tests in the source tarball. "
56+
"Contrib tests live inside the package tree."
57+
)
58+
59+
60+
class TestSdistIncludesExamples:
61+
"""Verify examples are included in the source distribution."""
62+
63+
def test_examples_in_sdist_include(self):
64+
sdist = load_sdist_config()
65+
includes = sdist.get("include", [])
66+
assert "examples/**" in includes, (
67+
"pyproject.toml [tool.flit.sdist] must include 'examples/**'. "
68+
"Examples help voters validate the package works correctly."
69+
)
70+
71+
def test_examples_not_in_sdist_exclude(self):
72+
sdist = load_sdist_config()
73+
excludes = sdist.get("exclude", [])
74+
assert "examples/**" not in excludes, (
75+
"pyproject.toml [tool.flit.sdist] must not exclude 'examples/**'."
76+
)
77+
78+
79+
class TestSdistIncludesScripts:
80+
"""Verify scripts are included in the source distribution."""
81+
82+
def test_scripts_in_sdist_include(self):
83+
sdist = load_sdist_config()
84+
includes = sdist.get("include", [])
85+
assert "scripts/**" in includes, (
86+
"pyproject.toml [tool.flit.sdist] must include 'scripts/**'. "
87+
"Scripts help voters validate the package (e.g. version_check.py)."
88+
)
89+
90+
91+
class TestSdistExcludesBinaries:
92+
"""Verify binary files are excluded to keep tarballs source-only."""
93+
94+
def test_ipynb_excluded(self):
95+
sdist = load_sdist_config()
96+
excludes = sdist.get("exclude", [])
97+
assert "**/*.ipynb" in excludes, (
98+
"pyproject.toml [tool.flit.sdist] must exclude '**/*.ipynb'. "
99+
"Notebooks should not be in source tarballs."
100+
)
101+
102+
def test_png_excluded(self):
103+
sdist = load_sdist_config()
104+
excludes = sdist.get("exclude", [])
105+
assert "**/*.png" in excludes, (
106+
"pyproject.toml [tool.flit.sdist] must exclude '**/*.png'. "
107+
"Binary files should not be in source tarballs."
108+
)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
"""Tests verifying that the sdist includes tests.
19+
20+
Per Apache release policy, voters must be able to build from source
21+
and run tests to validate. These tests ensure that pyproject.toml
22+
is configured to include tests/ in the source distribution.
23+
"""
24+
25+
import sys
26+
from pathlib import Path
27+
28+
if sys.version_info >= (3, 11):
29+
import tomllib
30+
else:
31+
import tomli as tomllib
32+
33+
34+
def get_lsp_dir() -> Path:
35+
return Path(__file__).resolve().parent.parent
36+
37+
38+
def load_sdist_config() -> dict:
39+
pyproject = get_lsp_dir() / "pyproject.toml"
40+
with open(pyproject, "rb") as f:
41+
config = tomllib.load(f)
42+
return config["tool"]["flit"]["sdist"]
43+
44+
45+
class TestSdistIncludesTests:
46+
"""Verify tests are included in the source distribution."""
47+
48+
def test_tests_in_sdist_include(self):
49+
sdist = load_sdist_config()
50+
includes = sdist.get("include", [])
51+
assert "tests/**" in includes, (
52+
"pyproject.toml [tool.flit.sdist] must include 'tests/**'. "
53+
"Apache release policy requires tests in the source tarball."
54+
)
55+
56+
def test_tests_not_in_sdist_exclude(self):
57+
sdist = load_sdist_config()
58+
excludes = sdist.get("exclude", [])
59+
assert "tests/**" not in excludes, (
60+
"pyproject.toml [tool.flit.sdist] must not exclude 'tests/**'. "
61+
"Apache release policy requires tests in the source tarball."
62+
)

ui/backend/tests/test_build.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,23 @@ def test_flit_sdist_includes_build_directory(self):
212212
"Built assets will not be packaged in the distribution."
213213
)
214214

215+
def test_flit_sdist_includes_tests(self):
216+
"""Verify that pyproject.toml includes tests/** in Flit sdist.
217+
218+
Per Apache release policy, voters must be able to build from source
219+
and run tests to validate.
220+
"""
221+
pyproject_file = get_ui_backend_dir() / "pyproject.toml"
222+
223+
with open(pyproject_file, "rb") as f:
224+
config = tomllib.load(f)
225+
226+
includes = config["tool"]["flit"]["sdist"].get("include", [])
227+
assert "tests/**" in includes, (
228+
"pyproject.toml [tool.flit.sdist] must include 'tests/**'. "
229+
"Apache release policy requires tests in the source tarball."
230+
)
231+
215232
def test_manifest_in_does_not_exist(self):
216233
"""Verify that MANIFEST.in does not exist (Flit uses pyproject.toml)."""
217234
manifest_file = get_ui_backend_dir() / "MANIFEST.in"

ui/sdk/tests/test_sdist.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
"""Tests verifying that the sdist includes tests and examples.
19+
20+
Per Apache release policy, voters must be able to build from source
21+
and run tests to validate. These tests ensure that pyproject.toml
22+
is configured to include tests/ and examples/ in the source distribution.
23+
"""
24+
25+
import sys
26+
from pathlib import Path
27+
28+
if sys.version_info >= (3, 11):
29+
import tomllib
30+
else:
31+
import tomli as tomllib
32+
33+
34+
def get_sdk_dir() -> Path:
35+
return Path(__file__).resolve().parent.parent
36+
37+
38+
def load_sdist_config() -> dict:
39+
pyproject = get_sdk_dir() / "pyproject.toml"
40+
with open(pyproject, "rb") as f:
41+
config = tomllib.load(f)
42+
return config["tool"]["flit"]["sdist"]
43+
44+
45+
class TestSdistIncludesTests:
46+
"""Verify tests are included in the source distribution."""
47+
48+
def test_tests_in_sdist_include(self):
49+
sdist = load_sdist_config()
50+
includes = sdist.get("include", [])
51+
assert "tests/**" in includes, (
52+
"pyproject.toml [tool.flit.sdist] must include 'tests/**'. "
53+
"Apache release policy requires tests in the source tarball."
54+
)
55+
56+
def test_tests_not_in_sdist_exclude(self):
57+
sdist = load_sdist_config()
58+
excludes = sdist.get("exclude", [])
59+
assert "tests/**" not in excludes, (
60+
"pyproject.toml [tool.flit.sdist] must not exclude 'tests/**'. "
61+
"Apache release policy requires tests in the source tarball."
62+
)
63+
64+
65+
class TestSdistIncludesExamples:
66+
"""Verify examples are included in the source distribution."""
67+
68+
def test_examples_in_sdist_include(self):
69+
sdist = load_sdist_config()
70+
includes = sdist.get("include", [])
71+
assert "examples/**" in includes, (
72+
"pyproject.toml [tool.flit.sdist] must include 'examples/**'. "
73+
"Examples help voters validate the package works correctly."
74+
)
75+
76+
def test_examples_not_in_sdist_exclude(self):
77+
sdist = load_sdist_config()
78+
excludes = sdist.get("exclude", [])
79+
assert "examples/**" not in excludes, (
80+
"pyproject.toml [tool.flit.sdist] must not exclude 'examples/**'."
81+
)
82+
83+
84+
class TestSdistExcludesBinaries:
85+
"""Verify binary files are excluded to keep tarballs source-only."""
86+
87+
def test_parquet_excluded(self):
88+
sdist = load_sdist_config()
89+
excludes = sdist.get("exclude", [])
90+
assert "**/*.parquet" in excludes, (
91+
"pyproject.toml [tool.flit.sdist] must exclude '**/*.parquet'. "
92+
"Binary files should not be in source tarballs."
93+
)
94+
95+
def test_pkl_excluded(self):
96+
sdist = load_sdist_config()
97+
excludes = sdist.get("exclude", [])
98+
assert "**/*.pkl" in excludes, (
99+
"pyproject.toml [tool.flit.sdist] must exclude '**/*.pkl'. "
100+
"Binary files should not be in source tarballs."
101+
)
102+
103+
def test_ipynb_excluded(self):
104+
sdist = load_sdist_config()
105+
excludes = sdist.get("exclude", [])
106+
assert "**/*.ipynb" in excludes, (
107+
"pyproject.toml [tool.flit.sdist] must exclude '**/*.ipynb'. "
108+
"Notebooks should not be in source tarballs."
109+
)

0 commit comments

Comments
 (0)