Skip to content
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

Add support for building wheels #30

Merged
merged 1 commit into from
Jul 22, 2023
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
17 changes: 16 additions & 1 deletion files/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import dataclasses
import json
import os
import pathlib
import re
import shutil
import subprocess
import tempfile
import typing as t
import urllib.request

Expand Down Expand Up @@ -49,7 +51,6 @@ class Pip:

_OPTIONS = (
'--disable-pip-version-check',
'--no-cache-dir',
)

_DEFAULT_PACKAGES = dict(
Expand Down Expand Up @@ -105,6 +106,15 @@ def show_version(self) -> None:
"""Show the pip version."""
subprocess.run(self._pip_command + ['--version'] + list(self._OPTIONS), check=True)

def wheel(self, args: t.List[str], constraints: pathlib.Path) -> None:
"""Build Python wheels with the given constraints file, storing them in the pip cache."""
env = os.environ.copy()
env.update(PIP_CONSTRAINT=str(constraints))

with tempfile.TemporaryDirectory() as temp_dir:
with self._install_options_context() as options:
subprocess.run(self._pip_command + ['wheel'] + options + list(self._OPTIONS) + args, check=True, env=env, cwd=temp_dir)

def install(self, args: t.List[str]) -> None:
"""Install Python packages."""
with self._install_options_context() as options:
Expand All @@ -121,6 +131,11 @@ def check(self) -> None:
"""Check installed Python packages."""
subprocess.run(self._pip_command + ['check'] + list(self._OPTIONS), check=True)

@staticmethod
def purge_cache() -> None:
"""Purge the pip cache."""
shutil.rmtree(os.path.expanduser('~/.cache/pip')) # The `pip cache purge` command leaves behind directories.

@contextlib.contextmanager
def _install_options_context(self) -> t.List[str]:
"""Create a pip install context for the specified Python interpreter and return options needed for the installation."""
Expand Down
2 changes: 2 additions & 0 deletions files/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def setup_python(python: Python) -> None:

display.section(f'Completed setup of Python {python.version}')

pip.purge_cache()


if __name__ == '__main__':
main()