Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libreoffice: Convert generate-libreoffice-srcs from Bash to Python #18755

Merged
merged 1 commit into from
Sep 20, 2016

Conversation

chris-martin
Copy link
Contributor

This is a rewrite of generate-libreoffice-srcs.sh in Python. The output of this script is identical to that of its predecessor.

I think the result is easier to follow, and slightly less fragile. It does the variable substitution in a more general way, and relies less on the file's ordering.

It still prints skipped lines (and also line numbers) to stderr to help detect problems, though it doesn't print skipped comments.

@mention-bot
Copy link

@chris-martin, thanks for your PR! By analyzing the annotation information on this pull request, we identified @7c6f434c to be a potential reviewer

shellHook = ''
function generate {
./generate-libreoffice-srcs.sh | tee libreoffice-srcs.nix
python3 generate-libreoffice-srcs.py > libreoffice-srcs.nix
Copy link
Member

@7c6f434c 7c6f434c Sep 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add #! /usr/bin/env python3 in the script, too? I think most NixPkgs developers have /usr/bin/env (it is default-on in NixOS)

Of course python3 here would stay anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the lesson learned from NixOS was that shebangs were somewhat evil and /usr/bin/env was just a least-painful compromise. No problem adding it if you like, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - there's no harm in adding a shebang. I'd still leave the explicit call to python3 in this line though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what happens in the current version.


def apply_additions(xs, additions):
for x in xs:
yield {**x, **additions.get(x['name'], {})}
Copy link
Member

@7c6f434c 7c6f434c Sep 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, maybe if the problem you want to fix is low readability of the bash script to people with weak knowledge of bash, **x thing in Python could be worth a comment like «merge two hashtables into one» for people who don't write Python.

Oh, I see you have dict_merge, using it instead of **x would be self-documenting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, will do.

@@ -19,9 +19,11 @@ stdenv.mkDerivation {
builder = ./download-list-builder.sh;
};

buildInputs = [ python36 ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a pre-release of Python 3.6? Please use python3 which at this time refers to python35.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't know 3.6 was considered pre-release. I think I just wanted string interpolation. Guess we can do without it.

@7c6f434c
Copy link
Member

I thought the lesson learned from NixOS was that shebangs were somewhat evil and /usr/bin/env was just a least-painful compromise. No problem adding it if you like, though.

Well, between no shebang and /usr/bin/env shebang I would advise for
the latter — I agree that the buildscript shouldn't rely on that, but
running the script manually becomes easier.

@chris-martin
Copy link
Contributor Author

Added a shebang, changed package python36 -> python3, removed all usages of the new ** dict splat operator.

Copy link
Member

@7c6f434c 7c6f434c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine with me. Any comments, @FRidh ?

@7c6f434c 7c6f434c merged commit d9bb1bf into NixOS:master Sep 20, 2016
@chris-martin chris-martin deleted the libreoffice-gen branch September 20, 2016 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants