optimagic-dev / optimagic

optimagic is a Python package for numerical optimization. It is a unified interface to optimizers from SciPy, NlOpt and other packages. optimagic's minimize function works just like SciPy's, so you don't have to adjust your code. You simply get more optimizers for free. On top you get diagnostic tools, parallel numerical derivatives and more.
https://optimagic.readthedocs.io/
MIT License
266 stars 30 forks source link

adjust `update_envs` to make sure that created files have LF line endings #455

Closed ChristianZimpelmann closed 1 year ago

ChristianZimpelmann commented 1 year ago
codecov[bot] commented 1 year ago

Codecov Report

Merging #455 (88049f3) into main (6d762a5) will not change coverage. The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #455   +/-   ##
=======================================
  Coverage   93.24%   93.24%           
=======================================
  Files         247      247           
  Lines       17987    17987           
=======================================
  Hits        16772    16772           
  Misses       1215     1215           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

janosg commented 1 year ago

Hi @ChristianZimpelmann, can you describe the problem you get with the mixed-line-ending hook? I thought the whole point of that hook was to fix such problems.

ChristianZimpelmann commented 1 year ago

Hi @ChristianZimpelmann, can you describe the problem you get with the mixed-line-ending hook? I thought the whole point of that hook was to fix such problems.

The problem is that mixed-line-ending and update-environment-files fail alternatingly and alternatingly change the line endings from LF to CRLF and viceversa. Somehow mixed-line-ending does not check the files created by update-environment-files during the same pre-commit run, but only after I try to commit again.

janosg commented 1 year ago

Ah, probably because they are not staged.

I was just worried how robust this approach is. Do you have a source for this trick? Then we could just add a comment and the source to explain why we open a yaml file in binary mode.

ChristianZimpelmann commented 1 year ago

Good point!

I found a much better solution now, but nevertheless added a comment including a source for the solution.

timmens commented 1 year ago

Our development environment already uses Python 3.10, so we could probably also use this, right?

Path('my.txt').write_text('hello\nworld', newline='\n')

Source: https://stackoverflow.com/a/69869641

ChristianZimpelmann commented 1 year ago

Thanks, @timmens for the reference! That seems like the best solution.