Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1603046pxb; Mon, 11 Oct 2021 09:17:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykvzHrOFqnxL+wvFFvbRKcGIYTAvRFfQ6TA1HWm6E38rzg/fOAos6bHeVjZDYVvNhvkiGL X-Received: by 2002:a62:5fc6:0:b0:44c:591a:5bf6 with SMTP id t189-20020a625fc6000000b0044c591a5bf6mr26574282pfb.36.1633969029430; Mon, 11 Oct 2021 09:17:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633969029; cv=none; d=google.com; s=arc-20160816; b=qgju4dgTLdJcUT3fu02rAXXlceOTFCkRFuGfn6uzllFH9+wuxC5aWHeDoviMsgB7Xo gHsTjUeTJ7V2uqL/zKwc6+WNZdMrJuxg+xdV+DDK8TYh+44BMO3C2mkGUfwamoI6pTo3 VwDnf/p6dkAPIQDiGYvNT8YyRETyNoLZw+tU01PtCZ3vSb36BpKBIBMQHFcM6cfy7Ox6 b553rHlvrwWb0gcI+i1vmwReCVFBi9py5rwBZmg5T6RKNRBeXtjp9atS6gdE6hz5KkU7 CdbLnJKHbZQKdEoGwJ69GSID/nT5mpKxIsFYRl+eKUH4zHekfqxbAx8eKe503WQkZNdz s02w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=zpR+sEmT7BLevEyNovVGhaI5h6cdyvuM5wlBxYFODFg=; b=dzvYfwBATaWR0/zXfq4zp5FjW6GgXWodx8Wi/yYc9GHoKnbq24awjKC87mx98dMcAz P/HKh7+3AsRWpCwg63otJuJK2GaV/OYgu8bbAauY0Ff3rFbtiR4t33cnvDczxToqorh+ 3MXwybu3QO0HPS6QZLsaDmtAjnEiOfOsAvlZHGUr8nA/03EJy9yVW5L+qvMWAtz8wzQb BAwkcCWlE3x/3t2tc0FYVpz+Z08PVWqJu7udiGAHoIBNg8hWeX9pLSfKSjWZuyrqVqLB C+8Vq2B5paIXQY9XLI7dwgTCdhVvbZU6ihiGACmCmA4SDz2STTm0v+8J0qiVs7t0+pHF D37g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u6si13024093pfk.23.2021.10.11.09.16.56; Mon, 11 Oct 2021 09:17:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235535AbhJKJjm (ORCPT + 99 others); Mon, 11 Oct 2021 05:39:42 -0400 Received: from mga14.intel.com ([192.55.52.115]:10638 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235443AbhJKJjl (ORCPT ); Mon, 11 Oct 2021 05:39:41 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10133"; a="227125535" X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="227125535" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2021 02:37:41 -0700 X-IronPort-AV: E=Sophos;i="5.85,364,1624345200"; d="scan'208";a="479786701" Received: from acleivam-mobl1.amr.corp.intel.com (HELO pujfalus-desk.ger.corp.intel.com) ([10.249.40.144]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2021 02:37:38 -0700 From: Peter Ujfalusi To: apw@canonical.com, joe@perches.com Cc: dwaipayanray1@gmail.com, lukas.bulwahn@gmail.com, peter.ujfalusi@linux.intel.com, linux-kernel@vger.kernel.org Subject: [PATCH v3] checkpatch: get default codespell dictionary path from package location Date: Mon, 11 Oct 2021 12:37:48 +0300 Message-Id: <20211011093748.2455-1-peter.ujfalusi@linux.intel.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The standard location of dictionary.txt is under codespell's package, on my machine atm (codespell 2.1, Artix Linux): /usr/lib/python3.9/site-packages/codespell_lib/data/dictionary.txt Since we enable the codespell by default for SOF I have constant: No codespell typos will be found - \ file '/usr/share/codespell/dictionary.txt': No such file or directory The patch proposes to try to fix up the path following the recommendation found here: https://github.com/codespell-project/codespell/issues/1540 Signed-off-by: Peter Ujfalusi --- Hi, Changes since v2: - Only try to check for dictionary path it is enabled or when the help is displayed - Move the check after the GetOptions() - Set $help to 2 in case invalid option is passed in order to be able to use correct exitcode and still display the correct path for dictionary.txt Changes sicne v1: - add missing ';' to the line updating the $codespellfile with $codespell_dict Regards, Peter scripts/checkpatch.pl | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index c27d2312cfc3..179e02acab6e 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -130,7 +130,7 @@ Options: --ignore-perl-version override checking of perl version. expect runtime errors. --codespell Use the codespell dictionary for spelling/typos - (default:/usr/share/codespell/dictionary.txt) + (default:$codespellfile) --codespellfile Use this codespell dictionary --typedefsfile Read additional types from this file --color[=WHEN] Use colors 'always', 'never', or only when output @@ -325,9 +325,19 @@ GetOptions( 'kconfig-prefix=s' => \${CONFIG_}, 'h|help' => \$help, 'version' => \$help -) or help(1); +) or $help = 2; -help(0) if ($help); +print($help); + +# Override the codespellfile location based on codespell install location +if (($codespell || $help) && which("codespell") ne "" && which("python") ne "") { + my $codespell_dict = `python -c "import os.path as op; import codespell_lib; print(op.join(op.dirname(codespell_lib.__file__), 'data', 'dictionary.txt'), end='')" 2> /dev/null`; + $codespellfile = $codespell_dict if (-e $codespell_dict); +} + +# $help is 1 if either -h, --help or --version is passed as option - exitcode: 0 +# $help is 2 if invalid option is passed - exitcode: 1 +help($help - 1) if ($help); die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix)); die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse); -- 2.33.0