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

ENH: run: Strip leading "--" to allow command disambiguation #3119

Merged
merged 1 commit into from Jan 14, 2019

Conversation

@kyleam
Copy link
Contributor

@kyleam kyleam commented Jan 11, 2019

The command is collected with argparse's REMAINDER. In the context of
DataLad's command-line parsing, this usually works fine but (1) has a
known issue with parsing at least one special flag, --version, and (2)
doesn't allow the command to start with an option, which is a common
situation when using runscripts with container-run. "--" can be used
in both these cases to explicitly tell argparse that the option is a
part of the command; we just need to remove it from the command list.

Fixes datalad/datalad-container#46.
Re: #3067

@yarikoptic
Copy link
Member

@yarikoptic yarikoptic commented Jan 13, 2019

The Travis failure seems to be unrelated and smells like @tyarkoni breaking the world again (but I could be wrong, didn't check yet)

"/home/travis/virtualenv/python3.5.6/lib/python3.5/site-packages/datalad_neuroimaging/extractors/bids.py", line 14, in <module>
    from bids.grabbids import BIDSLayout
ImportError: No module named 'bids.grabbids'

Copy link
Member

@yarikoptic yarikoptic left a comment

The unit test is neat. But I wonder if we could have at least a single test which checks interactions with argparse, eg by actually calling out to datalad run -- cmd.... so we could have assurance that it actually works across the systems where we test it

The command is collected with argparse's REMAINDER.  In the context of
DataLad's command-line parsing, this usually works fine but (1) has a
known issue with parsing at least one special flag, --version, and (2)
doesn't allow the command to start with an option, which is a common
situation when using runscripts with container-run.  "--" can be used
in both these cases to explicitly tell argparse that the option is a
part of the command; we just need to remove it from the command list.

Fixes datalad/datalad-container#46.
Re: datalad#3067
@kyleam kyleam force-pushed the run-disambig-switch branch from 7426ccf to 7f9fe2e Jan 14, 2019
@codecov
Copy link

@codecov codecov bot commented Jan 14, 2019

Codecov Report

Merging #3119 into master will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3119      +/-   ##
==========================================
- Coverage   90.82%   90.78%   -0.05%     
==========================================
  Files         248      248              
  Lines       32668    32678      +10     
==========================================
- Hits        29671    29667       -4     
- Misses       2997     3011      +14
Impacted Files Coverage Δ
datalad/interface/run.py 100% <100%> (ø) ⬆️
datalad/interface/tests/test_run.py 99.83% <100%> (ø) ⬆️
datalad/downloaders/http.py 82.53% <0%> (-3.18%) ⬇️
datalad/downloaders/tests/test_http.py 91.08% <0%> (-1.24%) ⬇️
datalad/downloaders/base.py 80.72% <0%> (-0.37%) ⬇️

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 2d9d7e8...7f9fe2e. Read the comment docs.

1 similar comment
@codecov
Copy link

@codecov codecov bot commented Jan 14, 2019

Codecov Report

Merging #3119 into master will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3119      +/-   ##
==========================================
- Coverage   90.82%   90.78%   -0.05%     
==========================================
  Files         248      248              
  Lines       32668    32678      +10     
==========================================
- Hits        29671    29667       -4     
- Misses       2997     3011      +14
Impacted Files Coverage Δ
datalad/interface/run.py 100% <100%> (ø) ⬆️
datalad/interface/tests/test_run.py 99.83% <100%> (ø) ⬆️
datalad/downloaders/http.py 82.53% <0%> (-3.18%) ⬇️
datalad/downloaders/tests/test_http.py 91.08% <0%> (-1.24%) ⬇️
datalad/downloaders/base.py 80.72% <0%> (-0.37%) ⬇️

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 2d9d7e8...7f9fe2e. Read the comment docs.

@kyleam
Copy link
Contributor Author

@kyleam kyleam commented Jan 14, 2019

test which checks interactions with argparse, eg by actually calling out to datalad run -- cmd....

OK, I've pushed an update.

edit: Travis failure is the same one from before.

@yarikoptic
Copy link
Member

@yarikoptic yarikoptic commented Jan 14, 2019

What a nice test, thanks! ;-)

@yarikoptic yarikoptic merged commit 0d63043 into datalad:master Jan 14, 2019
2 of 3 checks passed
@yarikoptic
Copy link
Member

@yarikoptic yarikoptic commented Jan 14, 2019

Regarding failure - will kick out release for neuroimaging extension - I think it is fixed and we probably test against pypi

@kyleam kyleam deleted the run-disambig-switch branch Jan 14, 2019
@tyarkoni
Copy link

@tyarkoni tyarkoni commented Jan 14, 2019

Have you updated datalad to reflect the API changes in 0.7? We got rid of bids.grabbids entirely (it was deprecated in the last version).

@yarikoptic
Copy link
Member

@yarikoptic yarikoptic commented Jan 15, 2019

Thanks @tyarkoni
I had the feeling that I fixed for that somewhere, and assumed that it was in datalad-neuroimaging. But now I do not see such a change/PR and we actually have datalad/datalad-neuroimaging#43 open and the last "catch to pybids" marathon was already half a year ago (time flies) to adjust for 0.6.4. We will attend to it, cheers!

yarikoptic added a commit that referenced this issue Feb 8, 2019
 A variety of bugfixes and enhancements

 ### Major refactoring and deprecations

 - All extracted metadata is now placed under git-annex by default.
   Previously files smaller than 20 kb were stored in git. ([#3109])
 - TODO: get_runner #3104 and pending #3131

 ### Fixes

 - Improved handling of long commands:
   - The code that inspected `SC_ARG_MAX` didn't check that the
     reported value was a sensible, positive number. ([#3025])
   - More commands that invoke `git` and `git-annex` with file
     arguments learned to split up the command calls when it is likely
     that the command would fail due to exceeding the maximum supported
     length. ([#3138])
 - The `setup_yoda_dataset` procedure created a malformed
   .gitattributes line. ([#3057])
 - [download-url] unnecessarily tried to infer the dataset when
   `--no-save` was given. ([#3029])
 - [rerun] aborted too late and with a confusing message when a ref
   specified via `--onto` didn't exist. ([#3019])
 - [run]:
   - `run` didn't preserve the current directory prefix ("./") on
      inputs and outputs, which is problematic if the caller relies on
      this representation when formatting the command. ([#3037])
   - Fixed a number of unicode py2-compatibility issues. ([#3035]) ([#3046])
   - To proceed with a failed command, the user was confusingly
     instructed to use `save` instead of `add` even though `run` uses
     `add` underneath. ([#3080])
 - Fixed a case where the helper class for checking external modules
   incorrectly reported a module as unknown. ([#3051])
 - [add-archive-content] mishandled the archive path when the leading
   path contained a symlink. ([#3058])
 - Following denied access, the credential code failed to consider a
   scenario, leading to a type error rather than an appropriate error
   message. ([#3091])
 - Some tests failed when executed from a `git worktree` checkout of the
   source repository. ([#3129])
 - During metadata extraction, batched annex processes weren't properly
   terminated, leading to issues on Windows. ([#3137])
 - [add] incorrectly handled an "invalid repository" exception when
   trying to add a submodule. ([#3141])
 - Pass `GIT_SSH_VARIANT=ssh` to git processes to be able to specify
   alternative ports in SSH urls

 ### Enhancements and new features

 - [search] learned to suggest closely matching keys if there are no
   hits. ([#3089])
 - [create-sibling] gained a `--group` option so that the caller can
   specify the file system group for the repository. ([#3098])
 - Interface classes can now override the default renderer for
   summarizing results. ([#3061])
 - [run]:
   - `--input` and `--output` can now be shortened to `-i` and `-o`.
     ([#3066])
   - Placeholders such as "{inputs}" are now expanded in the command
     that is shown in the commit message subject. ([#3065])
   - `interface.run.run_command` gained an `extra_inputs` argument so
     that wrappers like [datalad-container] can specify additional inputs
     that aren't considered when formatting the command string. ([#3038])
   - "--" can now be used to separate options for `run` and those for
     the command in ambiguous cases. ([#3119])
 - The utilities `create_tree` and `ok_file_has_content` now support
   ".gz" files. ([#3049])
 - The Singularity container for 0.11.1 now uses [nd_freeze] to make
   its builds reproducible.
 - A [publications] page has been added to the documentation. ([#3099])
 - `GitRepo.set_gitattributes` now accepts a `mode` argument that
   controls whether the .gitattributes file is appended to (default) or
   overwritten. ([#3115])
 - `datalad --help` now avoids using `man` so that the list of
   subcommands is shown.  ([#3124])

* tag '0.11.2': (124 commits)
  Changelog entry for GIT_SSH_VARIANT change
  ENH: Declare our GIT_SSH_COMMAND as GIT_SSH_VARIANT=ssh
  BF: sshconnector: Don't use ssh's port flag as scp's
  RF: sshconnector: Simplify shlex quote import
  CHANGELOG(0.11.2): Fix some typos
  [DATALAD RUNCMD] CHANGELOG: Linkify 0.11.2 entries
  CHANGELOG: Do first pass for 0.11.2
  CHANGELOG: Add missing link target for download-url
  Start cooking the 0.11.2 release
  RF: appveyor - move test_install tests to be ran the last
  RF: text_type instead of str
  ENH(TST): provide my timing for the slow test
  BF(TST): adjust the test for the fact that AnnexRepo.add does not blow on nonexisting files
  ENH(TST): two tests which test quick or thorough for add failing with too long list of files
  BF: get stderr if present, otherwise just use str(e)
  BF: append out/err only if not empty/None
  Centrlize handling running commands with long files list in _run_command_files_split
  RF: remove minor duplication of -- handling, place all files handling closer to the call
  RF: move unrelated to try/except handling outside
  ENH+DOC: Report actual process handle, not just PID
  ...
@yarikoptic yarikoptic added this to the Release 0.11.2 milestone Feb 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants