diff --git a/.github/workflows/alpine.yml b/.github/workflows/alpine.yml new file mode 100644 index 0000000..16843ae --- /dev/null +++ b/.github/workflows/alpine.yml @@ -0,0 +1,43 @@ +name: Alpine Python 3.12 + +on: + push: + branches: ["main"] + pull_request: + +jobs: + test-alpine: + name: Alpine Python 3.12 + runs-on: ubuntu-latest + container: + image: python:3.12-alpine + env: + PIP_DISABLE_PIP_VERSION_CHECK: "1" + PYTHONUNBUFFERED: "1" + steps: + - name: Install system dependencies + run: | + apk update + apk add --no-cache \ + bash \ + curl \ + git \ + build-base \ + postgresql-dev \ + libffi-dev \ + openssl-dev \ + linux-headers \ + gcompat \ + tzdata + + - name: Checkout repository + uses: actions/checkout@v5 + + - name: Set up uv + uses: astral-sh/setup-uv@v6 + + - name: Install project + run: uv sync --locked --all-extras --dev + + - name: Run tests + run: uv run --python 3.12 pytest -vv diff --git a/src/tinypg/binaries.py b/src/tinypg/binaries.py index 6d88e06..b11d30c 100644 --- a/src/tinypg/binaries.py +++ b/src/tinypg/binaries.py @@ -48,6 +48,7 @@ def __init__(self, cache_dir: Optional[Path] = None): # Detect platform self.os_name = self._detect_os() self.arch = self._detect_arch() + self._using_musl = self._detect_musl() def _detect_os(self) -> str: """Detect the operating system.""" @@ -82,9 +83,8 @@ def _get_platform_string(self) -> str: """Get the platform string for binary downloads.""" platform = f"{self.os_name}-{self.arch}" - # TODO not returning alpine yet for testing - # if False and self.os_name == "linux" and self._using_musl: - # return f"{platform}-alpine" + if self.os_name == "linux" and self._using_musl: + return f"{platform}-alpine" return platform @@ -94,7 +94,11 @@ def _detect_musl(self) -> bool: return False libc, _ = platform.libc_ver() - if libc and libc.lower().startswith("musl"): + force_glibc = bool(os.environ.get("TINYPG_GLIBC")) + if libc and libc.lower().startswith("musl") and not force_glibc: + # Will use a musl build unless TINYPG_GLIBC=1 + # tinypg glibc binaries works on alpine (extensions as well) + # with gcompat return True if Path("/etc/alpine-release").exists():