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

[MRG] refactor argparse.FileType out of sourmash argument handling. #853

Merged
merged 17 commits into from
Jan 21, 2020

Conversation

ctb
Copy link
Contributor

@ctb ctb commented Jan 20, 2020

argparse.FileType('wt') is annoying because it opens the specified file immediately upon argument parsing, which overwrites it. As shown in #571, this can destroy outputs unnecessarily.

This PR changes most of the FileType arguments in sourmash to string filenames, which are only opened at the time of write. I add a FileOutput context manager that behaves properly wrt default arguments encountered in the wild.

Fixes #571, overwriting files even on error.
May pave the way for --inplace behavior, ref #625.
Also cleans up an accidental duplication of the describe implementation 😆

  • Is it mergeable?
  • make test Did it pass the tests?
  • make coverage Is the new code covered?
  • Did it change the command-line interface? Only additions are allowed
    without a major version increment. Changing file formats also requires a
    major version number increment.
  • Was a spellchecker run on the source code and documentation after
    changes were made?

@ctb ctb changed the title refactor sourmash signature commands to NOT use argparse.FileType [WIP] refactor sourmash signature commands to NOT use argparse.FileType Jan 20, 2020
@codecov
Copy link

codecov bot commented Jan 20, 2020

Codecov Report

Merging #853 into master will increase coverage by 12.1%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #853      +/-   ##
==========================================
+ Coverage   79.03%   91.14%   +12.1%     
==========================================
  Files          82       69      -13     
  Lines        6874     4913    -1961     
  Branches      470        0     -470     
==========================================
- Hits         5433     4478     -955     
+ Misses       1139      435     -704     
+ Partials      302        0     -302
Flag Coverage Δ
#pytests ?
#rusttests ?
Impacted Files Coverage Δ
sourmash/sbt_storage.py 85.39% <0%> (-1.28%) ⬇️
sourmash/signature.py 86.59% <0%> (-0.47%) ⬇️
sourmash/sbtmh.py 84.28% <0%> (-0.23%) ⬇️
sourmash/_minhash.py 97.33% <0%> (-0.11%) ⬇️
sourmash/index.py 98.38% <0%> (-0.08%) ⬇️
sourmash/cli/__init__.py 98.83% <0%> (-0.02%) ⬇️
src/core/src/from.rs
src/core/src/sketch/minhash.rs
src/core/src/lib.rs
src/core/src/index/storage.rs
... and 13 more

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 0faafac...4d18853. Read the comment docs.

@ctb
Copy link
Contributor Author

ctb commented Jan 20, 2020

@luizirber would be useful to get your opinion on this when you have a chance. So far it's lookin' good to me.

@ctb ctb changed the title [WIP] refactor sourmash signature commands to NOT use argparse.FileType [MRG] refactor argparse.FileType out of sourmash argument handling. Jan 20, 2020
@luizirber
Copy link
Member

argparse.FileType('wt') is annoying because it opens the specified file immediately upon argument parsing, which overwrites it. As shown in #571, this can destroy outputs unnecessarily.

This PR changes most of the FileType arguments in sourmash to string filenames, which are only opened at the time of write. I add a FileOutput context manager that behaves properly wrt default arguments encountered in the wild.

Nice! I think this also fixes the output argument problem in compute in the Python CLI, mentioned at the end of #245 (comment)

tests/test_sourmash.py Outdated Show resolved Hide resolved
@luizirber luizirber added this to the 3.2 milestone Jan 20, 2020
@ctb ctb merged commit 1c617da into master Jan 21, 2020
@ctb ctb deleted the update/sig_in_place branch January 21, 2020 05:43
@ctb ctb mentioned this pull request Jan 21, 2020
5 tasks
@ctb ctb mentioned this pull request Feb 10, 2020
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.

argparse erases previously-generated .csv results
2 participants