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 DF831C61DA4 for ; Fri, 24 Feb 2023 01:19:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 036FC85A00; Fri, 24 Feb 2023 02:19:18 +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="gbnLu6tn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C995D8338B; Fri, 24 Feb 2023 02:18:57 +0100 (CET) Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) (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 4C7CB85A03 for ; Fri, 24 Feb 2023 02:18: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-il1-x12d.google.com with SMTP id l2so1517080ilg.7 for ; Thu, 23 Feb 2023 17:18: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=OZZpN750OL3fKuSGLDcBTCDfI3EDM+l2JQzy4vMZD74=; b=gbnLu6tnrsSdneRHneu8dtPGae979ei/2IZy/Mect0FB0Y1Y2O/T8nS+jeIXE96bpX RWHy1nWrN/U8bWhyuJDYI6j9jKkBnhS05aFHCbVN0knNv4gRl+1cuIn8tT4leswSHteu NFGqj0Q30WN2ZSBJEeABE//xUr5/WOWSe0ZUs= 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=OZZpN750OL3fKuSGLDcBTCDfI3EDM+l2JQzy4vMZD74=; b=ck7GzUQ9WC3nQcd55qv/6CVLsvCnDOUARb4RUtnqTcyivqpQNKmukn4OwV6zBJzhsW uXmC1m4pGnBsAsF+bVzB202qmm9rqumysBjStIIgTTn0innqcqbwx+zmrAO2aCo1psz3 XBeXMwMitdSXVE71eskej1I+rba3S6pzTGHlco4lebEl6FqzRMbLbk49pYJH7YhyPwxa YoW9LLXwwrOJpSQpk4xFNNnOsueMRqZf12kPYu3cukv61XKhBwjk7WNNjdDBRs4AwnLI 3N4WUsy/abpUMu1sEFmSdgZ9dI8wTQUvH6QiBVDahGo/nl86UQ7KTeaXWValuYWq5gTN SW6g== X-Gm-Message-State: AO0yUKXFB7p5DL/h8RZ6N+qd+VGbYBVehm3h6nVJW52B0a2gZcODTRoD xFtpr+5RxgT32VOi/mLiicjCa6ccxeulyeei X-Google-Smtp-Source: AK7set+7fhtjvrdSjzr/t11Xk1nhj24x4SPUWVmQ5Rhsek2zKheO1KNxuyYx26tdgslITMQcbuTI1w== X-Received: by 2002:a05:6e02:184c:b0:316:fcbe:628f with SMTP id b12-20020a056e02184c00b00316fcbe628fmr4196792ilv.26.1677201528745; Thu, 23 Feb 2023 17:18:48 -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 q3-20020a92d403000000b003127b668eafsm2677214ilm.19.2023.02.23.17.18.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 17:18:48 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Alper Nebi Yasak , Neha Malcom Francis , Stefan Herbrechtsmeier , Philippe Reynes , Peng Fan , Heinrich Schuchardt , Simon Glass Subject: [PATCH v2 05/24] script: Add a script to build a PyPi package Date: Thu, 23 Feb 2023 18:18:05 -0700 Message-Id: <20230224011824.2111976-6-sjg@chromium.org> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog In-Reply-To: <20230224011824.2111976-1-sjg@chromium.org> References: <20230224011824.2111976-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 --- Changes in v2: - Drop test files - Fix removable of the /tmp dir - Quite a few updates to make things work with the new names scripts/make_pip.sh | 117 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 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..4602dcf61c8 --- /dev/null +++ b/scripts/make_pip.sh @@ -0,0 +1,117 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0+ + +# Packages a U-Boot tool +# +# Usage: make_pip.sh [--real] +# +# Where tool_name is one of patman, buildman, dtoc, binman, 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}" =~ ^(patman|buildman|dtoc|binman|u_boot_pylib)$ ]]; then + echo "Building dist package for tool ${tool}" +else + echo "Unknown tool ${tool}: use patman, buildman, dtoc or binman" + 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 \; + +# Remove test files +rm -rf ${dest}/*test* + +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