python-bibtexparser icon indicating copy to clipboard operation
python-bibtexparser copied to clipboard

Allow preservation of existing order of entry fields in writer

Open alexreg opened this issue 4 years ago • 6 comments
trafficstars

This should be fairly self-explanatory. I couldn't immediately see why display_order = reversed(entry) is correct to preserve the pre-existing order of fields, but it seems to work reliably.

alexreg avatar Feb 13 '21 05:02 alexreg

Coverage Status

Coverage decreased (-0.05%) to 97.36% when pulling 54884565e5e9093a3a5cb9089af2b3b9cef25b73 on alexreg:no-display-order into bfb7502306c44b490fe77c2b06c4ee6b1a88d893 on sciunto-org:master.

coveralls avatar Feb 13 '21 05:02 coveralls

FYI I added a new test, so coveralls shouldn't be complaining now, though I think it forgot to rerun.

alexreg avatar Feb 16 '21 12:02 alexreg

Is this aimed at preserving

@article{foo,
 title = {I would like to change as few as possible for version management},
 year = {20202}
 author = {Foo, B.},
}

(the order of title, year, author in this example). That would be amazing for version management!

tdegeus avatar Feb 09 '22 15:02 tdegeus

Hi @alexreg, and sorry for the wait :-)

I just started helping this repo a bit with maintenance and I'd like to get this merged. Are you still interested in working on this PR? If so, a few remarks:

You asked why reversing the dict gives the original order. I guess that's caused by this line, where the fields found in pyparsing are reversed. They are later stored in a dict, which, as of python3.7 are guaranteed to preserve order.

A few comments on your PR, before going into a deeper review:

  • Please resolve merge conflicts.
  • Please move the tidying of the literals in the test into a separate PR.
  • Please document your changes in the corresponding docstring.
  • Python versions pre-dating 3.7 reached EOL, hence I guess we can continue working with dict instead of OrderedDict. But we may want to raise a warning if your enhancement is called (i.e, display_order set to None) with previous python versions. What do you think?

If you're not interested in continuing with this, please give me a quick heads-up - I'll hope to find someone else, then :-)

MiWeiss avatar Jul 09 '22 10:07 MiWeiss

@MiWeiss Thanks for your response. I'm afraid I don't have the time to rework this PR right now (and I haven't been using this library lately), so if you could find someone else, that would be great.

alexreg avatar Jul 10 '22 01:07 alexreg

Thanks a lot for getting back with me so quickly!

MiWeiss avatar Jul 10 '22 10:07 MiWeiss

I can take this feature 👍.

michaelfruth avatar Sep 05 '22 20:09 michaelfruth

Replaced in #317 by @michaelfruth. Thanks 👍

MiWeiss avatar Sep 06 '22 06:09 MiWeiss