Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A5FF1C61DA4 for ; Sun, 19 Feb 2023 14:53:52 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D13C785831; Sun, 19 Feb 2023 15:53:27 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="MqQWNFRk"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 71DCB857E3; Sun, 19 Feb 2023 15:52:36 +0100 (CET) Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8EE6D85748 for ; Sun, 19 Feb 2023 15:51:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2c.google.com with SMTP id h5so321555ioj.7 for ; Sun, 19 Feb 2023 06:51:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Rm0jl98Fvp577WmfUlXfQYp6cYn9au2EKePvG3z7f60=; b=MqQWNFRko5IER/k3LGIEheZHc0F5FR3jIaUCv+3/hHxjeaZHwHenuErMjpZpWPMolO 4s3+Vwij3Ww4ifTcIpA5UKDlIfjSmcN5zv7wNVLf9ftMCOeFxK0rrZF83poSvz5nFmn4 7vU02LkQcqA3z9EGGdXYfyhtQ1j20wjPAHpnw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rm0jl98Fvp577WmfUlXfQYp6cYn9au2EKePvG3z7f60=; b=hbx1lmGib39vv3CIWaabT95usbZEQeAAcb3ugIlei2mlOxqJi9Vm6JiYz87fW6tOS0 nfoRkh3XqyTyG85LxCda/9gsFkvjqSEsPs6RpqpGXClJo7jG8vJu87bG5GYjvORlk+dn MA7nd8LVb9MfwsjFAnIeh+Un9Y07lFaDRhUPiP2blm9oJNJsdx9HboZmEfLrXjx0R24k 5WZkZOuBx2nFBlkndLP86gQ23XizjSCdZbB3ske9w7dFKRm/PrCVa0nEDPQFQQxL6xgX hz5MvLonIa9NdkUK30aT/N1eG+6dHMtQARrEFA34PdHFn8oAKh8bDpujv9U/lTqBujBC /1+g== X-Gm-Message-State: AO0yUKVTZkbHaN107+IOIv0yk4Vi7pw/vYYGObeTlJ9IHu4Y3yYC801I Ry5cTgdKXLjAnrcHykOAEEKt4/K5G6KjTNXt X-Google-Smtp-Source: AK7set83T+RlhMc5H9ZgYTJEYs/SKIIa2mhNLGv3Rhs6Bb7tY6YtlWkgo94w8uTB7ei9oYM50+RcBw== X-Received: by 2002:a5d:9947:0:b0:71f:8124:de52 with SMTP id v7-20020a5d9947000000b0071f8124de52mr5417957ios.9.1676818309059; Sun, 19 Feb 2023 06:51:49 -0800 (PST) Received: from sjg1.roam.corp.google.com (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id c84-20020a6bb357000000b0071c66d1a2fcsm3444772iof.0.2023.02.19.06.51.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Feb 2023 06:51:48 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Alper Nebi Yasak , Neha Malcom Francis , Stefan Herbrechtsmeier , Philippe Reynes , Peng Fan , Simon Glass Subject: [PATCH 05/15] script: Add a script to build a PyPi package Date: Sun, 19 Feb 2023 07:51:13 -0700 Message-Id: <20230219145124.1782335-6-sjg@chromium.org> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog In-Reply-To: <20230219145124.1782335-1-sjg@chromium.org> References: <20230219145124.1782335-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Create a script which can package a tool for use with PyPi and the 'pip' tool. This involves quite a few steps so is best automated. Future work will enable use of this for some of the tools in U-Boot. Signed-off-by: Simon Glass --- scripts/make_pip.sh | 113 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100755 scripts/make_pip.sh diff --git a/scripts/make_pip.sh b/scripts/make_pip.sh new file mode 100755 index 00000000000..358d0f3a465 --- /dev/null +++ b/scripts/make_pip.sh @@ -0,0 +1,113 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0+ + +# Packages a U-Boot tool +# +# Usage: make_pip.sh [--real] +# +# Where tool_name is one of patmanu, buildman, dtoc, binmanu, u_boot_pylib +# +# and --real means to upload to the real server (otherwise the test one is used) +# +# The username for upload is always __token__ so set TWINE_PASSWORD to your +# password before running this script: +# +# export TWINE_PASSWORD=pypi-xxx +# +# To test your new packages: +# +# pip install -i https://test.pypi.org/simple/ +# + +# DO NOT use patman or binman + +set -xe + +# Repo to upload to +repo="--repository testpypi" + +# Non-empty to do the actual upload +upload=1 + +tool="$1" +shift +flags="$*" + +if [[ "${tool}" =~ ^(patmanu|buildman|dtoc|binmanu|u_boot_pylib)$ ]]; then + echo "Building dist package for tool ${tool}" +else + echo "Unknown tool ${tool}: use patmanu, buildman, dtoc or binmanu" + exit 1 +fi + +for flag in "${flags}"; do + if [ "${flag}" == "--real" ]; then + echo "Using real server" + repo= + fi + if [ "${flag}" == "-n" ]; then + echo "Doing dry run" + upload= + fi +done + +if [ -n "${upload}" ]; then + if [ -z "${TWINE_PASSWORD}" ]; then + echo "Please set TWINE_PASSWORD to your password and retry" + exit 1 + fi +fi + +# Create a temp dir to work in +dir=$(mktemp -d) + +# Copy in some basic files +cp -v tools/${tool}/pyproject.toml ${dir} +cp -v Licenses/gpl-2.0.txt ${dir}/LICENSE +readme="tools/${tool}/README.*" + +# Copy in the README, dropping some Sphinx constructs that PyPi doesn't like +cat ${readme} | sed -E 's/:(doc|ref):`.*`//; /sectionauthor/d; /toctree::/d' \ + > ${dir}/$(basename ${readme}) + +# Copy the top-level Python and doc files +dest=${dir}/src/${tool} +mkdir -p ${dest} +cp -v tools/$tool/{*.py,*.rst} ${dest} + +# Copy over the subdirectories, including any sub files. Drop any cache files +# and other such things +pushd tools/${tool} +for subdir in $(find . -maxdepth 1 -type d | \ + grep -vE "(__pycache__|home|usr|scratch|\.$|pyproject)"); do + pathname="${dest}/${subdir}" + echo "Copy ${pathname}" + cp -a ${subdir} ${pathname} +done +popd + +# Remove cache files that accidentally made it through +find ${dest} -name __pycache__ -type f -exec rm {} \; +find ${dest} -depth -name __pycache__ -exec rmdir 112 \; +mkdir ${dir}/tests +cd ${dir} + +# Make sure the tools are up to date +python3 -m pip install --upgrade build +python3 -m pip install --upgrade twine + +# Build the PyPi package +python3 -m build + +echo "Completed build of ${tool}" + +# Use --skip-existing to work even if the version is already present +if [ -n "${upload}" ]; then + echo "Uploading from ${dir}" + python3 -m twine upload ${repo} -u __token__ dist/* + echo "Completed upload of ${tool}" +fi + +rm -rf "{$dir}" + +echo -e "done\n\n" -- 2.39.2.637.g21b0678d19-goog