From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id OH3tIEy2OGa3KAAAe85BDQ:P1 (envelope-from ) for ; Mon, 06 May 2024 12:51:56 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id OH3tIEy2OGa3KAAAe85BDQ (envelope-from ) for ; Mon, 06 May 2024 12:51:56 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=haHERx8B; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1714992716; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=WVdFGj1eni+Ricg5xwFr4yv4nH/HcOyKDOWKEnt+Hf0=; b=ORBg8t4EY7osCoejikJCF67zL4zRibSvtlqidoe9cutucx01lP0YDUd2fBVncQQOrZ5p4z iUcF5eolwXOs65CSeYAuAwVOMLblcY+PY9YkC03Q++KSpe6t/xJrVS9brSnijrTOiTOtos P+OjueA7sf/CqCHI4IXf7RaJ5VlqRG4x872FUelDoekyq7TZ39QlOGHImZazjVgiMdZtiz PZ5oOnyId0dijt7rE9TrVOwQMAIBo8gLwo+NAlyQl7sDxzf0GgBWm8GcZi0wrnqC0zGb2a XCnJ5mC0ObTGA/BhSSyfZW1bzWJmoUDO7Q7xR40IT6jYdkFfsVdoMLwUXjO2bg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1714992716; a=rsa-sha256; cv=none; b=jPtIQg8mTw9afYsV6Z8G55aqgig6RdAYLyYod/vp9FIC4P1G9LtGio8kJVmd6wyj0hwM0G TyAFMaOGwUqoZfn5HEhoIug3SydfR//1lFfZuINlbowY6LdkzrKYpYqpw5uG4odZO5v0oG gq2cMFoqziFxxQLyrbS2KaAzRIZxGDju/IKY3eb4FpkJ1SoFKkfvjZ6lPSMVYqjLYS6zCE tjhTaZA3UAY8+vtIGtwB+xtoJglrf7bE/YGbeuPKo/aVIb5V7ekw1ZVbIVkQRDwHmVRMiv CvPt4fZATsoFSiMR7xsgnqhKdKpvw0uAkcAyBy//Zcpg66x1MxXyfnNJeDixlQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=haHERx8B; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 24BC8716CA for ; Mon, 06 May 2024 12:51:56 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s3vwg-0006Ct-F7; Mon, 06 May 2024 06:51:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s3vwc-0006CB-Qi for guix-patches@gnu.org; Mon, 06 May 2024 06:51:42 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s3vwc-000523-DS; Mon, 06 May 2024 06:51:42 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s3vww-00083c-OD; Mon, 06 May 2024 06:52:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70800] [PATCH] scripts: style: Add 'order' option to alphabetically order file. Resent-From: Herman Rimm Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Mon, 06 May 2024 10:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 70800 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70800@debbugs.gnu.org Cc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by submit@debbugs.gnu.org id=B.171499269330945 (code B ref -1); Mon, 06 May 2024 10:52:02 +0000 Received: (at submit) by debbugs.gnu.org; 6 May 2024 10:51:33 +0000 Received: from localhost ([127.0.0.1]:37201 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s3vwS-000833-W5 for submit@debbugs.gnu.org; Mon, 06 May 2024 06:51:33 -0400 Received: from lists.gnu.org ([2001:470:142::17]:56194) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s3vwO-00082u-9B for submit@debbugs.gnu.org; Mon, 06 May 2024 06:51:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s3vvu-00062k-PJ for guix-patches@gnu.org; Mon, 06 May 2024 06:50:58 -0400 Received: from 81-205-150-117.fixed.kpn.net ([81.205.150.117] helo=email.rimm.ee) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1s3vvl-0004tT-De for guix-patches@gnu.org; Mon, 06 May 2024 06:50:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1714992642; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=WVdFGj1eni+Ricg5xwFr4yv4nH/HcOyKDOWKEnt+Hf0=; b=haHERx8BijRNpzaAdaFi0bo5eazRdQp+8g0bFMyp/00nCbacvLgzUYEZYL8IwJ7AqYMniT WtqQLdYIkWoZgQDhmg1hQWL/YJHXsviicF9xoZZRNpSUi2KUdfLAreHWO4j2t30xh42nWC AU2SeqyVeuohWF57MP/Wqq5s77i4cBR6dS1L9NKTTfHzDDjOmBPK7U2+U++B0n5GhNxvg7 fX+fpvRb+48zfvNlaV8O0Mzjb+K9lDD/ZFakLNVLJKFeJI9b3KxFWxhUfqxLruOVC89Z9q 8P0C1bWSATfBqdV1Pw7WsS76UpwS76h+KraP8r6wRQjEJImzNIEq3hfm4QYMUw== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id 8d314ab5 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO) for ; Mon, 6 May 2024 10:50:42 +0000 (UTC) Date: Mon, 6 May 2024 12:50:34 +0200 Message-ID: <8e0df2707343eaee0bf39fa06fcdd5bc5cd9fba2.1714992109.git.herman@rimm.ee> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=81.205.150.117; envelope-from=herman@rimm.ee; helo=email.rimm.ee X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_PBL=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, TVD_RCVD_IP=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Herman Rimm X-ACL-Warn: , Herman Rimm via Guix-patches From: Herman Rimm via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -2.39 X-Spam-Score: -2.39 X-Migadu-Queue-Id: 24BC8716CA X-Migadu-Scanner: mx11.migadu.com X-TUID: KIugdyKyDw11 * guix/scripts/style.scm (show-help): Describe option. (order-packages): Add procedure. (format-whole-file): Add 'order?' argument. (%options): Add 'order' option. (guix-style): Alphabetically order packages in files. * doc/guix.texi (Invoking guix style): Document option. Change-Id: I4aa7c0bd0b6d42529ae7d304587ffb10bf5f4006 --- Hi, I managed to create a procedure which alphabetically sorts top-level package definitions. Sort is not stable as I understand it, so versions of packages get swapped. It works well enough in small package modules, and should not be a problem once package versions are used in sorting. Cheers, Herman doc/guix.texi | 6 +++++ guix/scripts/style.scm | 52 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 1c1e0164e7..6316f6bfc9 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -15097,6 +15097,12 @@ Invoking guix style guix style -f /etc/config.scm @end example +@item --order +@itemx -o +Place the top-level package definitions in the given files in alphabetical +order. This option only has an effect in combination with +@option{--whole-file}. + @item --styling=@var{rule} @itemx -S @var{rule} Apply @var{rule}, one of the following styling rules: diff --git a/guix/scripts/style.scm b/guix/scripts/style.scm index 211980dc1c..ace28c1bca 100644 --- a/guix/scripts/style.scm +++ b/guix/scripts/style.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021-2023 Ludovic Courtès +;;; Copyright © 2024 Herman Rimm ;;; ;;; This file is part of GNU Guix. ;;; @@ -29,6 +30,7 @@ (define-module (guix scripts style) #:autoload (gnu packages) (specification->package fold-packages) + #:use-module (guix combinators) #:use-module (guix scripts) #:use-module ((guix scripts build) #:select (%standard-build-options)) #:use-module (guix ui) @@ -494,11 +496,43 @@ (define (package-location name1 name2))))))) + (reverse (concatenate lst)))) + +(define* (format-whole-file file order? #:rest rest) + "Reformat all of FILE. When ORDER? is true, top-level package definitions + are put in alphabetical order." (with-fluids ((%default-port-encoding "UTF-8")) - (let ((lst (call-with-input-file file read-with-comments/sequence - #:guess-encoding #t))) + (let* ((lst (call-with-input-file file read-with-comments/sequence + #:guess-encoding #t)) + (lst (if order? + (order-packages lst) + lst))) (with-atomic-file-output file (lambda (port) (apply pretty-print-with-comments/splice port lst @@ -526,6 +560,9 @@ (define %options (option '(#\f "whole-file") #f #f (lambda (opt name arg result) (alist-cons 'whole-file? #t result))) + (option '(#\o "order") #f #f + (lambda (opt name arg result) + (alist-cons 'order? #t result))) (option '(#\S "styling") #t #f (lambda (opt name arg result) (alist-cons 'styling-procedure @@ -569,7 +606,7 @@ (define (show-help) (display (G_ " -S, --styling=RULE apply RULE, a styling rule")) (display (G_ " - -l, --list-stylings display the list of available style rules")) + -l, --list-stylings display the list of available style rules")) (newline) (display (G_ " -n, --dry-run display files that would be edited but do nothing")) @@ -584,6 +621,8 @@ (define (show-help) (newline) (display (G_ " -f, --whole-file format the entire contents of the given file(s)")) + (display (G_ " + -o, --order place the contents in alphabetical order as well")) (newline) (display (G_ " -h, --help display this help and exit")) @@ -627,7 +666,8 @@ (define-command (guix-style . args) (warning (G_ "'--styling' option has no effect in whole-file mode~%"))) (when (null? files) (warning (G_ "no files specified, nothing to do~%"))) - (for-each format-whole-file files)) + (for-each format-whole-file + files (map (const (assoc-ref opts 'order?)) files))) (let ((packages (filter-map (match-lambda (('argument . spec) (specification->package spec)) base-commit: ef8ab6ab66c4d629699d175938ef1912941d4dce -- 2.41.0