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

run: Resolve some py2 unicode issues #3035

Merged
merged 4 commits into from Dec 2, 2018
Merged

Conversation

@kyleam
Copy link
Contributor

@kyleam kyleam commented Nov 30, 2018

This pull request supersedes gh-3033, fixing the py2 issue there as well as other py2 unicode issues in cmd.py and run.py.


@mih: One of the tests added (test_run:test_py2_unicode_command) triggers a case where the patch from #3031 (e3d2af7, RF: Do not force byte-encoding of commit message) fails under Python 2.

======================================================================
ERROR: datalad.interface.tests.test_run.test_py2_unicode_command
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kyle/src/python/venvs/datalad-py2/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/kyle/src/python/datalad/datalad/tests/utils.py", line 596, in newfunc
    return t(*(arg + (filename,)), **kw)
  File "/home/kyle/src/python/datalad/datalad/interface/tests/test_run.py", line 151, in test_py2_unicode_command
    ds.run(u"bβ2.dat")
  File "/home/kyle/src/python/datalad/datalad/distribution/dataset.py", line 494, in apply_func
    return f(**kwargs)
  File "/home/kyle/src/python/datalad/datalad/interface/utils.py", line 479, in eval_func
    return return_func(generator_func)(*args, **kwargs)
  File "/home/kyle/src/python/datalad/datalad/interface/utils.py", line 467, in return_func
    results = list(results)
  File "/home/kyle/src/python/datalad/datalad/interface/utils.py", line 422, in generator_func
    result_renderer, result_xfm, _result_filter, **_kwargs):
  File "/home/kyle/src/python/datalad/datalad/interface/utils.py", line 509, in _process_results
    for res in results:
  File "/home/kyle/src/python/datalad/datalad/interface/run.py", line 223, in __call__
    sidecar=sidecar):
  File "/home/kyle/src/python/datalad/datalad/interface/run.py", line 725, in run_command
    ofh.write(msg)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u03b2' in position 18: ordinal not in range(128)
kyleam added 4 commits Dec 1, 2018
Avoid a UnicodeEncodeError under Python 2 when a failing command
contains non-ascii characters.
Under Python 2, GlobbedPaths incorrectly assumes that the patterns
coming in as well as the paths returned by glob.glob() are unicode.
Make sure the patterns that come in are unicode, which also results in
the unicode paths being returned glob.glob().
This test is focused on input quoting, but we might was well expand
the inputs in the commit message to make sure that dumping the obscure
name to the commit message doesn't fail, and it would have under
Python 2 before the previous commit.

Re: datalad#3031, datalad#3033
The `cmd` argument comes in as unicode.  Avoid a UnicodeEncodeError
under Python 2 when a command contains non-ascii characters.
@kyleam kyleam force-pushed the bf-py2-run-unicode branch from 56bb218 to caf99ae Dec 1, 2018
@codecov
Copy link

@codecov codecov bot commented Dec 1, 2018

Codecov Report

Merging #3035 into master will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3035      +/-   ##
==========================================
+ Coverage   90.12%   90.22%   +0.09%     
==========================================
  Files         246      246              
  Lines       32472    32480       +8     
==========================================
+ Hits        29267    29306      +39     
+ Misses       3205     3174      -31
Impacted Files Coverage Δ
datalad/cmd.py 94.98% <100%> (ø) ⬆️
datalad/interface/run.py 100% <100%> (ø) ⬆️
datalad/tests/test_cmd.py 85.48% <100%> (+0.31%) ⬆️
datalad/interface/tests/test_run.py 99.84% <100%> (ø) ⬆️
datalad/tests/test_utils.py 96.3% <0%> (+0.28%) ⬆️
datalad/tests/utils.py 89.38% <0%> (+0.41%) ⬆️
datalad/support/tests/test_annexrepo.py 96.4% <0%> (+1.46%) ⬆️
datalad/interface/tests/test_unlock.py 100% <0%> (+7.4%) ⬆️

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 ef038a8...caf99ae. Read the comment docs.

1 similar comment
@codecov
Copy link

@codecov codecov bot commented Dec 1, 2018

Codecov Report

Merging #3035 into master will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3035      +/-   ##
==========================================
+ Coverage   90.12%   90.22%   +0.09%     
==========================================
  Files         246      246              
  Lines       32472    32480       +8     
==========================================
+ Hits        29267    29306      +39     
+ Misses       3205     3174      -31
Impacted Files Coverage Δ
datalad/cmd.py 94.98% <100%> (ø) ⬆️
datalad/interface/run.py 100% <100%> (ø) ⬆️
datalad/tests/test_cmd.py 85.48% <100%> (+0.31%) ⬆️
datalad/interface/tests/test_run.py 99.84% <100%> (ø) ⬆️
datalad/tests/test_utils.py 96.3% <0%> (+0.28%) ⬆️
datalad/tests/utils.py 89.38% <0%> (+0.41%) ⬆️
datalad/support/tests/test_annexrepo.py 96.4% <0%> (+1.46%) ⬆️
datalad/interface/tests/test_unlock.py 100% <0%> (+7.4%) ⬆️

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 ef038a8...caf99ae. Read the comment docs.

@kyleam
Copy link
Contributor Author

@kyleam kyleam commented Dec 1, 2018

Pushed update to resolve trivial conflicts with now merged #3037.

@yarikoptic yarikoptic merged commit 2eb16d2 into datalad:master Dec 2, 2018
6 of 7 checks passed
@kyleam kyleam deleted the bf-py2-run-unicode branch Dec 2, 2018
kyleam added a commit to kyleam/datalad that referenced this issue Dec 2, 2018
The tests added in dataladgh-3035 tested the Python API case, where the run
caller passes in unicode strings.  But when called from the command
line, the command will be a byte-string in Python 2.  Ensure that it's
unicode.  Do this in normalize_command() because otherwise we need to
repeat the list/string test elsewhere and outside callers (like
containers-run) would need to apply a similar py2-compatibility fix.
kyleam added a commit to kyleam/datalad that referenced this issue Dec 3, 2018
The tests added in dataladgh-3035 tested the Python API case, where the run
caller passes in unicode strings.  But when called from the command
line, the command will be a byte-string in Python 2.  Ensure that it's
unicode.  Do this in normalize_command() because otherwise we need to
repeat the list/string test elsewhere and outside callers (like
containers-run) would need to apply a similar py2-compatibility fix.
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

2 participants