Skip to content

TST: simplify pep518 test setup #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 24 additions & 46 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def in_git_repo_context(path=os.path.curdir):
path = os.path.abspath(path)
shutil.rmtree(os.path.join(path, '.git'), ignore_errors=True)
try:
subprocess.check_call(['git', 'init', '-b', 'main', path])
subprocess.check_call(['git', 'config', 'user.email', '[email protected]'], cwd=path)
subprocess.check_call(['git', 'config', 'user.name', 'A U Thor'], cwd=path)
subprocess.check_call(['git', 'add', '*'], cwd=path)
subprocess.check_call(['git', 'commit', '-q', '-m', 'Test'], cwd=path)
subprocess.run(['git', 'init', '-b', 'main', path], check=True)
subprocess.run(['git', 'config', 'user.email', '[email protected]'], cwd=path, check=True)
subprocess.run(['git', 'config', 'user.name', 'A U Thor'], cwd=path, check=True)
subprocess.run(['git', 'add', '*'], cwd=path, check=True)
subprocess.run(['git', 'commit', '-q', '-m', 'Test'], cwd=path, check=True)
yield
finally:
# PermissionError raised on Windows.
Expand Down Expand Up @@ -123,50 +123,28 @@ def fixture(tmp_dir_session):
globals()[f'wheel_{normalized}'] = generate_wheel_fixture(package)


@pytest.fixture(autouse=True, scope='session')
def disable_pip_version_check():
# Cannot use the 'monkeypatch' fixture because of scope mismatch.
mpatch = pytest.MonkeyPatch()
yield mpatch.setenv('PIP_DISABLE_PIP_VERSION_CHECK', '1')
mpatch.undo()


@pytest.fixture(scope='session')
def pep518_wheelhouse(tmpdir_factory):
wheelhouse = tmpdir_factory.mktemp('wheelhouse')
dist = tmpdir_factory.mktemp('dist')
subprocess.run(
[sys.executable, '-m', 'build', '--wheel', '--outdir', str(dist)],
cwd=str(package_dir.parent.parent),
check=True,
)
(wheel_path,) = dist.visit('*.whl')
subprocess.run(
[
sys.executable,
'-m',
'pip',
'download',
'-q',
'-d',
str(wheelhouse),
str(wheel_path),
],
check=True,
)
subprocess.run(
[
sys.executable,
'-m',
'pip',
'download',
'-q',
'-d',
str(wheelhouse),
'build',
'colorama',
'meson',
'ninja',
'patchelf',
'pyproject-metadata',
'tomli',
'typing-extensions',
'wheel',
],
check=True,
)
meson_python = str(package_dir.parent.parent)
# Populate wheelhouse with wheel for the following packages and
# their dependencies. Wheels are downloaded from PyPI or built
# from the source distribution as needed. Sources or wheels in
Copy link
Contributor

@henryiii henryiii Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, it's building ninja from source on Cygwin here, that's why it's passing below. In my version, it was also building ninja from source in order to build meson, but it wasn't putting it into the wheelhouse.

# the pip cache are used when available.
packages = [
meson_python,
'build',
'wheel',
]
subprocess.run([sys.executable, '-m', 'pip', 'wheel', '--wheel-dir', str(wheelhouse), *packages], check=True)
return str(wheelhouse)


Expand Down
12 changes: 6 additions & 6 deletions tests/docs/examples/test_spam.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def test_build_and_import(venv, tmp_dir_session):
else:
wheel = build_project_wheel(package=examples_dir / 'spam', outdir=tmp_dir_session)

subprocess.check_call([
venv.executable, '-m', 'pip', '--disable-pip-version-check', 'install', wheel
])
output = subprocess.check_output([
venv.executable, '-c', 'import spam; print(spam.add(1, 2))'
])
subprocess.run(
[venv.executable, '-m', 'pip', 'install', wheel],
check=True)
output = subprocess.run(
[venv.executable, '-c', 'import spam; print(spam.add(1, 2))'],
check=True, stdout=subprocess.PIPE).stdout

assert int(output) == 3
5 changes: 2 additions & 3 deletions tests/test_pep518.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
@pytest.mark.parametrize(
'build_arg', ['', '--wheel'], ids=['sdist_to_wheel', 'wheel_directly']
)
@pytest.mark.xfail(sys.platform.startswith('cygwin'), reason='ninja pip package not available on cygwin', strict=True)
Copy link
Contributor

@henryiii henryiii Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed? The point of the test is to test that this breaks - that is, ninja's not available from PyPI on cygwin. So if this passes on Cygwin before #175 goes in, the test doesn't work. That's why it was a strict xfail.

I'm not completely sure what changed to make this pass, as this looks similar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, now I know why it's passing. That's okay, I think - then we can delete ninja from the wheelhouse manually for #175. The only think that lightly bothers me is the check_call change, then.

Copy link
Member Author

@dnicolodi dnicolodi Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if we remove ninja from meson-python's dependencies list it will not be put in the wheelhouse anymore. But the documentation is not crystal clear on this. I'll have to check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm that once ninja is removed from meson-python's dependencies it is not added to the wheelhouse anymore.

def test_pep518(pep518, package, build_arg, tmp_path):
dist = tmp_path / 'dist'

with cd_package(package) as package_dir, in_git_repo_context():
with cd_package(package), in_git_repo_context():
build_args = [build_arg] if build_arg else []
subprocess.run([sys.executable, '-m', 'build', f'--outdir={dist}', *build_args], cwd=package_dir, check=True)
subprocess.run([sys.executable, '-m', 'build', '--outdir', str(dist), *build_args], check=True)
2 changes: 1 addition & 1 deletion tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def last_two_meson_args():

# create the build directory ourselves because Project._meson is mocked
builddir = str(tmp_dir_session / 'build')
subprocess.check_call(['meson', 'setup', '.', builddir])
subprocess.run(['meson', 'setup', '.', builddir], check=True)

config_settings = {
'builddir': builddir, # use the build directory we created
Expand Down
14 changes: 8 additions & 6 deletions tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@ def test_configure_data(wheel_configure_data):

@pytest.mark.skipif(platform.system() != 'Linux', reason='Unsupported on this platform for now')
def test_local_lib(venv, wheel_link_against_local_lib):
subprocess.check_call([
venv.executable, '-m', 'pip', '--disable-pip-version-check', 'install', wheel_link_against_local_lib
])
assert subprocess.check_output([
venv.executable, '-c', 'import example; print(example.example_sum(1, 2))'
]).decode().strip() == '3'
subprocess.run(
[venv.executable, '-m', 'pip', 'install', wheel_link_against_local_lib],
check=True)
output = subprocess.run(
[venv.executable, '-c', 'import example; print(example.example_sum(1, 2))'],
stdout=subprocess.PIPE,
check=True).stdout
assert int(output) == 3


def test_contents_license_file(wheel_license_file):
Expand Down