diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9e264f..40ca50a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,7 +72,8 @@ jobs: - pre-commit with: kind: "${{ inputs.kind }}" - cmd: "${{ inputs.package_command }}" + cmd: python -m build + #cmd: "${{ inputs.package_command }}" test: name: Test diff --git a/.github/workflows/package-action.yml b/.github/workflows/package-action.yml index 85bde7a..ff217e1 100644 --- a/.github/workflows/package-action.yml +++ b/.github/workflows/package-action.yml @@ -26,32 +26,47 @@ jobs: build: name: Build Python Wheel runs-on: ubuntu-latest + container: + image: debian:11 outputs: version: ${{ steps.version.outputs.version }} steps: - uses: actions/checkout@master - - name: Set up Python 3.10 - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - name: Install pypa/build + + - name: Update Apt + run: >- + apt-get update + + - name: Install OS Dependencies run: >- - python -m - pip install - build - --user - - name: Install pypa/pkginffo + apt-get install -y gcc python3 + python3-pip python3-venv flex make + texinfo unzip help2man gawk libtool-bin libncurses5-dev + bison wget rsync git + + - name: Create virtualenv run: >- - python -m - pip install - pkginfo - --user + python3 -m venv venv + + - name: Activate virtualenv + run: | + . venv/bin/activate + echo PATH=$PATH >> $GITHUB_ENV + + - name: Python Version + run: >- + python3 --version + + - name: Install Python Dependencies + run: >- + pip install build wheel setuptools pkginfo - name: Echo Build Wheel Command run: echo "${{ inputs.cmd }}" - name: Build Wheel - run: "${{ inputs.cmd }}" + run: | + ${{ inputs.cmd }} - name: Python Build Artifact uses: actions/upload-artifact@v3 @@ -60,11 +75,12 @@ jobs: name: dist path: dist/* retention-days: 5 + - name: Read Version run: >- python3 -c - "from pkginfo import Wheel; s = Wheel('dist/$(ls dist/)'); print(f'version={s.version}')" + "from pkginfo import Wheel; s = Wheel('''$(ls dist/*.whl)'''); print('version='+str(s.version))" >> $GITHUB_OUTPUT id: version diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index 8c61d46..e88027a 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -32,18 +32,8 @@ jobs: - name: Install python dependencies run: | - pip3 install nox - - - name: Install Linux dependencies - if: ${{ matrix.runs-on == 'linux' }} - run: | - apt-get install -y shellcheck - - - name: Install Mac dependencies - if: ${{ matrix.runs-on == 'macos-12' || matrix.runs-on == 'macos-13-xlarge' }} - run: | - brew install shellcheck + pip3 install pytest - name: Run tests run: | - nox -e tests + pytest -v diff --git a/README.md b/README.md index a66e721..50ebd9a 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -**P**ortable **P**ython **T**oolchain +**P**ortable **P**ython **B**uild **T**oolchain diff --git a/pyproject.toml b/pyproject.toml index 3afd60b..13e7758 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = [ "wheel", ] build-backend = "build" -backend-path = ["src/ppt"] +backend-path = ["src/ppbt"] [tool.pytest.ini_options] pythonpath = [ diff --git a/setup.cfg b/setup.cfg index f2bfd64..6df24b8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,13 +1,13 @@ [metadata] -name = ppt +name = ppbt version = 0.1.0 author = Daniel A. Wozniak author_email = -description = Portable Python Toolchain +description = Portable Python Build Toolchain long_description = file: README.md long_description_content_type = text/markdown -url = https://github.com/saltstack/python-portable-toolchains - Bug Tracker = https://github.com/saltstack/python-portable-toolchains/issues +url = https://github.com/saltstack/ppbt + Bug Tracker = https://github.com/saltstack/ppbt/issues classifiers = Programming Language :: Python :: 3 License :: OSI Approved :: Apache Software License diff --git a/setup.py b/setup.py index 319d8fd..6d83d3c 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ # If crosstool is updated to a newer version of glibc this should get updated # too. Would also be nice to detect this instead. -# hint: grep CT_GLIBC_VERSION src/ppt/_config/x86_64/x86_64-linux-gnu-ct-ng.config +# hint: grep CT_GLIBC_VERSION src/ppbt/_config/x86_64/x86_64-linux-gnu-ct-ng.config GLIBC_VERSION = "2.17" diff --git a/src/ppbt/__init__.py b/src/ppbt/__init__.py new file mode 100644 index 0000000..3b0ac27 --- /dev/null +++ b/src/ppbt/__init__.py @@ -0,0 +1,8 @@ +# Copyright 2024 Broadcom Corporation +# SPDX-License-Identifier: Apache-2.0 +""" +Portable Python Build Toolchains. +""" +from .common import environ, extract + +ALL = ("environ", "extract") diff --git a/src/ppt/_config/aarch64/aarch64-linux-gnu-ct-ng.config b/src/ppbt/_config/aarch64/aarch64-linux-gnu-ct-ng.config similarity index 100% rename from src/ppt/_config/aarch64/aarch64-linux-gnu-ct-ng.config rename to src/ppbt/_config/aarch64/aarch64-linux-gnu-ct-ng.config diff --git a/src/ppt/_config/aarch64/x86_64-linux-gnu-ct-ng.config b/src/ppbt/_config/aarch64/x86_64-linux-gnu-ct-ng.config similarity index 100% rename from src/ppt/_config/aarch64/x86_64-linux-gnu-ct-ng.config rename to src/ppbt/_config/aarch64/x86_64-linux-gnu-ct-ng.config diff --git a/src/ppt/_config/x86_64/aarch64-linux-gnu-ct-ng.config b/src/ppbt/_config/x86_64/aarch64-linux-gnu-ct-ng.config similarity index 100% rename from src/ppt/_config/x86_64/aarch64-linux-gnu-ct-ng.config rename to src/ppbt/_config/x86_64/aarch64-linux-gnu-ct-ng.config diff --git a/src/ppt/_config/x86_64/x86_64-linux-gnu-ct-ng.config b/src/ppbt/_config/x86_64/x86_64-linux-gnu-ct-ng.config similarity index 100% rename from src/ppt/_config/x86_64/x86_64-linux-gnu-ct-ng.config rename to src/ppbt/_config/x86_64/x86_64-linux-gnu-ct-ng.config diff --git a/src/ppt/build.py b/src/ppbt/build.py similarity index 97% rename from src/ppt/build.py rename to src/ppbt/build.py index 5b116c2..0b68a78 100644 --- a/src/ppt/build.py +++ b/src/ppbt/build.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # """ -Build a ppt wheel which includes a toolchain archive. +Build a ppbt wheel which includes a toolchain archive. """ import base64 import csv @@ -198,7 +198,7 @@ def runcmd(*args, **kwargs): return proc -def build_ppt(branch=None, use_tempdir=True): +def build_ppbt(branch=None, use_tempdir=True): """Build a toolchain and include it in the wheel. - Downloads and installs crosstool-ng for building a toolchain. @@ -240,7 +240,7 @@ def build_ppt(branch=None, use_tempdir=True): arch = build_arch() machine = platform.machine() - toolchain = cwd / "src" / "ppt" / "_toolchain" + toolchain = cwd / "src" / "ppbt" / "_toolchain" print(f"toolchain: {toolchain}") @@ -255,7 +255,7 @@ def build_ppt(branch=None, use_tempdir=True): config = ( root / "src" - / "ppt" + / "ppbt" / "_config" / machine / "{}-ct-ng.config".format(triplet) @@ -328,7 +328,7 @@ def build_ppt(branch=None, use_tempdir=True): .rstrip(b"=") .decode() ) - hashpath = str(pathlib.Path("ppt") / "_toolchain" / relpath) + hashpath = str(pathlib.Path("ppbt") / "_toolchain" / relpath) rwriter.writerow([hashpath, f"sha256={hsh}", len(data)]) try: fp.add(relpath, relpath, recursive=False) @@ -346,5 +346,5 @@ def build_ppt(branch=None, use_tempdir=True): def build_wheel(wheel_directory, metadata_directory=None, config_settings=None): """PEP 517 wheel creation hook.""" - build_ppt() + build_ppbt() return _build_wheel(wheel_directory, metadata_directory, config_settings) diff --git a/src/ppt/environ.py b/src/ppbt/common.py similarity index 74% rename from src/ppt/environ.py rename to src/ppbt/common.py index 00647a1..a544ba6 100644 --- a/src/ppt/environ.py +++ b/src/ppbt/common.py @@ -6,6 +6,7 @@ """ import csv +import logging import pathlib from .build import build_arch, extract_archive, get_triplet @@ -17,17 +18,19 @@ toolchain_root = pathlib.Path(__file__).parent / "_toolchain" -distinfo = pathlib.Path(__file__).resolve().parent.parent / "ppt-0.1.0.dist-info" +distinfo = pathlib.Path(__file__).resolve().parent.parent / "ppbt-0.1.0.dist-info" +log = logging.getLogger(__name__) -def environ(): + +def extract(overwrite=False): """ - Toolchain build environment. + Extract the toolchain tarball. """ - if toolchain.exists(): - print("Toolchain directory exists") + if toolchain.exists() and not overwrite: + log.debug("Toolchain directory exists") else: - print("extract archive") + log.info("Extract archive") extract_archive(toolchain_root, str(archive)) record = distinfo / "RECORD" if record.exists(): @@ -43,6 +46,17 @@ def environ(): writer = csv.writer(fp) for row in records: writer.writerow(row) + + +def environ(auto_extract=False): + """ + Toolchain build environment. + """ + if not toolchain.exists(): + if auto_extract: + extract() + else: + raise RuntimeError("Toolchain not extracted") basebin = toolchain / "bin" / triplet return { "TOOLCHAIN_PATH": f"{toolchain}", diff --git a/src/ppt/__init__.py b/src/ppt/__init__.py deleted file mode 100644 index 2840552..0000000 --- a/src/ppt/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright 2024 Broadcom Corporation -# SPDX-License-Identifier: Apache-2.0 -""" -Protable toolchains for python -""" -from environ import environ - -ALL = ("environ",) diff --git a/tests/test_build.py b/tests/test_build.py index 80f5a49..b989898 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -1,8 +1,8 @@ # Copyright 2024 Broadcom Corporation # SPDX-License-Identifier: Apache-2.0 # -import ppt.build +import ppbt.build def test_noop(): - assert ppt.build + assert ppbt.build