Skip to content

Commit

Permalink
make dict sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
solomoncyj authored Dec 16, 2024
1 parent 8679ea9 commit 145ba88
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions data/mesongenbuildreq.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import json
import sys
deps_json = json.loads(subprocess.run([sys.argv[1], "introspect", "--dependencies", "meson.build"], capture_output=True).stdout)
deps = dict(sorted(zip([x['name'] for x in deps_json],[x['version'] for x in deps_json])))
deps.pop('', None)
unsorted_deps = dict(zip([x['name'] for x in deps_json],[x['version'] for x in deps_json]))
unsorted_deps.pop('', None)
deps = {}
for lib in list(unsorted_deps.keys()) :
deps[lib] = unsorted_deps[lib]
for lib, versions in deps.items() :
# Prepare version constraint
version_str = ' ' + ' '.join(versions) if versions else ''
Expand Down

4 comments on commit 145ba88

@bmwiedemann
Copy link

Choose a reason for hiding this comment

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

This does not really sort anything. But then I re-tested https://github.com/bmwiedemann/theunreproduciblepackage/blob/master/hash/hash.py and found that python3 already seems to sort it internally.

@eli-schwartz
Copy link
Member

Choose a reason for hiding this comment

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

(This comment isn't on the PR.)

Sort what? Python has order-preserving dicts (as an implementation detail starting Python 3.6, and as an official language specification requirement starting 3.7), which aren't the same as sorted dicts, but do mean that the output is as deterministic as the input (in this case, json from a subprocess).

@QuLogic
Copy link
Member

Choose a reason for hiding this comment

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

The variable names unsorted_deps -> deps implies there is some sorting going on, but all that happens is an unnecessary copy.

@dcbaker
Copy link
Member

@dcbaker dcbaker commented on 145ba88 Dec 16, 2024

Choose a reason for hiding this comment

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

Yeah, that really should be deps = dict(sorted(unsorted_deps.items(), key=lambda x: x[0]))

edit: I left this are review on the actual PR

Please sign in to comment.