Skip to content

Commit

Permalink
Merge pull request #1 from dwoz/common
Browse files Browse the repository at this point in the history
Move environ method to commmon module
  • Loading branch information
dwoz authored Sep 2, 2024
2 parents f10128d + 4b4a446 commit e591b0c
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 58 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 32 additions & 16 deletions .github/workflows/package-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
14 changes: 2 additions & 12 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**P**ortable **P**ython **T**oolchain
**P**ortable **P**ython **B**uild **T**oolchain
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ requires = [
"wheel",
]
build-backend = "build"
backend-path = ["src/ppt"]
backend-path = ["src/ppbt"]

[tool.pytest.ini_options]
pythonpath = [
Expand Down
8 changes: 4 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[metadata]
name = ppt
name = ppbt
version = 0.1.0
author = Daniel A. Wozniak
author_email = <[email protected]>
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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
8 changes: 8 additions & 0 deletions src/ppbt/__init__.py
Original file line number Diff line number Diff line change
@@ -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")
12 changes: 6 additions & 6 deletions src/ppt/build.py → src/ppbt/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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}")

Expand All @@ -255,7 +255,7 @@ def build_ppt(branch=None, use_tempdir=True):
config = (
root
/ "src"
/ "ppt"
/ "ppbt"
/ "_config"
/ machine
/ "{}-ct-ng.config".format(triplet)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
26 changes: 20 additions & 6 deletions src/ppt/environ.py → src/ppbt/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import csv
import logging
import pathlib

from .build import build_arch, extract_archive, get_triplet
Expand All @@ -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():
Expand All @@ -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}",
Expand Down
8 changes: 0 additions & 8 deletions src/ppt/__init__.py

This file was deleted.

4 changes: 2 additions & 2 deletions tests/test_build.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e591b0c

Please sign in to comment.