Skip to content

Commit 3a485ca

Browse files
committed
Fix example_pkg to use bleaching during build
See https://python-packaging.readthedocs.io/en/latest/non-code-files.html to understand the include_package_data part. It is needed because in CI, we install the package and run tests on the installed package.
1 parent 6c49c1d commit 3a485ca

7 files changed

Lines changed: 26 additions & 11 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Add any project-specific files here:
2+
asyncbleach/_tests/example_pkg/build/
23

34
bench/results/
45
bench/env/

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ include README.rst CHEATSHEET.rst LICENSE* CODE_OF_CONDUCT* CONTRIBUTING*
22
include .coveragerc .style.yapf
33
include test-requirements.txt
44
recursive-include docs *
5+
recursive-include asyncbleach/_tests/example_pkg *
56
prune docs/build

asyncbleach/_tests/example_pkg/setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
author_email="[email protected]",
1010
description="A package used to test asyncbleach",
1111
url="https://github.com/pypa/sampleproject",
12-
packages=setuptools.find_packages(),
13-
cmdclass={'build_py': bleach_build_py},
14-
package_dir={'': 'src'},
12+
packages=['example_pkg', 'example_pkg._async'],
13+
cmdclass={'build_py': bleach_build_py},
14+
package_dir={'': 'src'},
1515
)
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
name = "example_pkg"
2-
3-
4-
async def f():
5-
return await 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
async def f():
2+
return await 1

asyncbleach/_tests/test_asyncbleach.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import shutil
23
import tempfile
34

45
from setuptools import sandbox
@@ -12,7 +13,6 @@ def test_asyncbleach():
1213
with open(os.path.join(tmpdir1, "source.py"), 'w') as f:
1314
f.write("async def f(): return await 1 \n")
1415

15-
1616
asyncbleach.bleach(
1717
os.path.join(tmpdir1, "source.py"), fromdir=tmpdir1, todir=tmpdir2
1818
)
@@ -23,7 +23,21 @@ def test_asyncbleach():
2323
assert bleached_code == "def f(): return 1 \n"
2424

2525

26-
2726
def test_bleach_build_py():
28-
path_to_setup_py = os.path.join(os.path.dirname(os.path.abspath(__file__)), './example_pkg/setup.py')
29-
sandbox.run_setup(path_to_setup_py, ['build'])
27+
with tempfile.TemporaryDirectory() as tmpdir:
28+
source_pkg_dir = os.path.join(
29+
os.path.dirname(os.path.abspath(__file__)), 'example_pkg'
30+
)
31+
pkg_dir = os.path.join(tmpdir, 'example_pkg')
32+
shutil.copytree(source_pkg_dir, pkg_dir)
33+
34+
pkg_dir = os.path.join(tmpdir, 'example_pkg')
35+
path_to_setup_py = os.path.join(pkg_dir, 'setup.py')
36+
sandbox.run_setup(path_to_setup_py, ['build'])
37+
38+
bleached = os.path.join(
39+
pkg_dir, 'build/lib/example_pkg/_sync/__init__.py'
40+
)
41+
with open(bleached) as f:
42+
bleached_code = f.read()
43+
assert bleached_code == "def f():\n return 1\n"

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
author="Ratan Kulshreshtha",
1414
author_email="[email protected]",
1515
license="MIT -or- Apache License 2.0",
16+
include_package_data=True,
1617
packages=find_packages(),
1718
install_requires=[
1819
"trio",

0 commit comments

Comments
 (0)