Add --format flag

The flag will invoke nixpkgs-fmt
This commit is contained in:
Tim Steinbach 2021-02-21 11:41:33 -05:00
parent 6263b42c26
commit 76cf63bbe2
No known key found for this signature in database
GPG Key ID: 1B40229F19262402
4 changed files with 16 additions and 1 deletions

View File

@ -98,6 +98,8 @@ tested.
Additionally, the `--review` flag can be used to initiate a run of
nixpkgs-review <https://github.com/Mic92/nixpkgs-review>, which will ensure all
dependent packages can be built.
In order to ensure consistent formatting, the `--format` flag will invoke
[nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt).
::
@ -112,6 +114,8 @@ dependent packages can be built.
$ nix-update --run nixpkgs-review
# Run `nixpkgs-review wip` to validate dependent packages
$ nix-update --review nixpkgs-review
# Format file
$ nix-update --format nixpkgs-review
Nix-update also can optionally generate a commit message in the form
`attribute: old_version -> new_version` with the applied version update:

View File

@ -27,7 +27,7 @@ python3.pkgs.buildPythonApplication rec {
mypy --strict nix_update
'';
makeWrapperArgs = [
"--prefix PATH" ":" (lib.makeBinPath [ nixFlakes nix-prefetch nixpkgs-review ])
"--prefix PATH" ":" (lib.makeBinPath [ nixFlakes nix-prefetch nixpkgs-fmt nixpkgs-review ])
];
shellHook = ''
# workaround because `python setup.py develop` breaks for me

View File

@ -26,6 +26,7 @@ def parse_args() -> Options:
parser.add_argument(
"--review", action="store_true", help="Run `nixpkgs-review wip`"
)
parser.add_argument("--format", action="store_true", help="Run `nixpkgs-fmt`")
parser.add_argument(
"--commit", action="store_true", help="Commit the updated package"
)
@ -59,6 +60,7 @@ def parse_args() -> Options:
test=args.test,
version_regex=args.version_regex,
review=args.review,
format=args.format,
)
@ -173,6 +175,11 @@ def nixpkgs_review() -> None:
run(cmd, check=True)
def nixpkgs_fmt(package: Package) -> None:
cmd = ["nixpkgs-fmt", package.filename]
run(cmd, check=True)
def main() -> None:
options = parse_args()
if not os.path.exists(options.import_path):
@ -208,6 +215,9 @@ def main() -> None:
if options.review:
nixpkgs_review()
if options.format:
nixpkgs_fmt(package)
if options.commit:
assert git_dir is not None
git_commit(git_dir, options.attribute, package)

View File

@ -13,3 +13,4 @@ class Options:
build: bool = False
test: bool = False
review: bool = False
format: bool = False