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

Make YAMLFormatter sort keys #237

Merged
merged 2 commits into from
Sep 14, 2020
Merged

Make YAMLFormatter sort keys #237

merged 2 commits into from
Sep 14, 2020

Conversation

jwodder
Copy link
Member

@jwodder jwodder commented Sep 10, 2020

Closes #235.

@codecov
Copy link

codecov bot commented Sep 10, 2020

Codecov Report

Merging #237 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #237   +/-   ##
=======================================
  Coverage   81.78%   81.79%           
=======================================
  Files          52       52           
  Lines        4261     4262    +1     
=======================================
+ Hits         3485     3486    +1     
  Misses        776      776           
Flag Coverage Δ
#unittests 81.79% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
dandi/cli/formatter.py 93.02% <100.00%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 419e8de...94ba354. Read the comment docs.

Copy link
Member

@yarikoptic yarikoptic left a comment

Choose a reason for hiding this comment

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

needs something like default_flow_style=False of the yaml module to not place lists/dicts inline

@@ -47,7 +47,7 @@ def __init__(self, out=None):
def __exit__(self, exc_type, exc_value, traceback):
import ruamel.yaml

yaml = ruamel.yaml.YAML()
yaml = ruamel.yaml.YAML(typ="safe")
Copy link
Member

Choose a reason for hiding this comment

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

ha ha -- that "works" as for sorting. But starts to serialize (short?) lists and dictionaries. If you merge/rebase on top of master and run ls you will see:

$> DANDI_CACHE=ignore DANDI_DEVEL=1 dandi ls -f yaml -r https://dandiarchive.org/dandiset/000027/draft
2020-09-10 20:53:26,267 [    INFO] Traversing remote dandisets (000027) recursively
- created: '2020-07-08T21:54:42.543000+00:00'
  metadata:
    dandiset:
      age: {maximum: 12 mo, minimum: 12 mo, units: TODO}
      contributors:
      - orcid: 0000-0003-3456-2493
        roles: [Author]
      description: 'Should be ignored by regular mortals.


        ATM contains only a few files from http://github.com/dandi-datasets/nwb_test_data
        which more or less appropriate (do not lack critical metadata) for testing'
      identifier: '000027'
      keywords: [development]
      name: Test dataset for testing dandi-cli.
      number_of_subjects: 1
      organism:
      - {species: Rattus norvegicus}
      sex: [M]
  path: '000027'
  updated: '2020-08-31T21:41:16.957000+00:00'
- attrs: {ctime: '2020-07-21T22:00:36.362000+00:00', mtime: '2020-07-21T17:31:55.283394-04:00',
    size: 18792}
  girder: {id: 5f176584f63d62e1dbd06946}
...

so more to be done. with a "regular" yaml module there is default_flow_style=False which I believe achieves that but blindly adding it to this YAML doesn't work

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding yaml.default_flow_style = False gives me:

- created: '2020-07-08T21:54:42.543000+00:00'
  metadata:
    dandiset:
      age:
        maximum: 12 mo
        minimum: 12 mo
        units: TODO
      contributors:
      - orcid: 0000-0003-3456-2493
        roles:
        - Author
      description: 'Should be ignored by regular mortals.


        ATM contains only a few files from http://github.com/dandi-datasets/nwb_test_data
        which more or less appropriate (do not lack critical metadata) for testing'
      identifier: '000027'
      keywords:
      - development
      name: Test dataset for testing dandi-cli.
      number_of_subjects: 1
      organism:
      - species: Rattus norvegicus
      sex:
      - M
  path: '000027'
  updated: '2020-08-31T21:41:16.957000+00:00'
- attrs:
    ctime: '2020-07-21T22:00:36.362000+00:00'
    mtime: '2020-07-21T17:31:55.283394-04:00'
    size: 18792
  girder:
    id: 5f176584f63d62e1dbd06946
  metadata:
    age: 12 mo
    genotype: wt
    identifier: test_subject
    md5: 33318fd510094e4304868b4a481d4a5a
    nwb_version: 2.0b
    session_description: a file to test writing and reading a subject
    session_start_time: '1971-01-01T12:00:00+00:00'
    sex: m
    sha1: 3db188426a3f91ae08fb5899491dcbc551292b1f
    sha256: 1a765509384ea96b7b12136353d9c5b94f23d764ad0431e049197f7875eb352c
    sha512: f80861c210fd83cd9cbcd9ec38ab94ad25484cd479d38a14db68c5d3fb9880b4c580a79ab0f6d51a7e19f527a83540f690cd0636fbd2339134c28a972934f442
    species: rattus norvegicus
    subject_id: rat123
    uploaded_by: dandi 0.5.0+12.gd4ef762.dirty
    uploaded_datetime: '2020-07-21T18:00:36.703727-04:00'
    uploaded_mtime: '2020-07-21T17:31:55.283394-04:00'
    uploaded_size: 18792
  modified: 2020-07-21 17:31:55.283394-04:00
  name: sub-RAT123.nwb
  path: /sub-RAT123/sub-RAT123.nwb
  sha256: 1a765509384ea96b7b12136353d9c5b94f23d764ad0431e049197f7875eb352c
  size: 18792
  type: file

Is this not what you want?

Copy link
Member

Choose a reason for hiding this comment

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

yes, this looks good. Please add that (I guess I have not done it correctly)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added.

@yarikoptic
Copy link
Member

failing tests -- docker compose failed to bring up our fixture, not sure why yet. May be since too many at once ? anyways -- unrelated, this looks good, merging

@yarikoptic yarikoptic merged commit 9e29cdf into master Sep 14, 2020
@yarikoptic yarikoptic deleted the gh-235 branch September 14, 2020 23:52
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.

Make YAMLFormatter to sort the keys
2 participants