Fix prepare-dev.py hook installation on Python 3

Review Request #10680 — Created Sept. 5, 2019 and submitted

Information

Review Board
master
9f69293...

Reviewers

There were two issues in the implementation of install_git_hooks that
prevented it from working on Python 3:
- an old-style (0777) octal literal was used instead of a new-style one
(0o777): old-style literals are not supported on Python 3; and
- bytes and unicode were being mixed in os.path.join, which is not an
issue in Python 2 but is on Python 3.

Since prepare-dev.py is intended to install dependencies, we can't
assume the presence of six, so we determine the correct string type
manually.

Ran prepare-dev.py under Python 2 and Python 3 and it created git
hooks successfully.

Description From Last Updated

This whole thing could probably just be: if isinstance(gitdir, bytes): gitdir = gitdir.decode('utf-8')

daviddavid

subprocess.check_output() is going to return bytes on both Python 2.x and 3.x. So we can actually just include this in …

chipx86chipx86
brennie
brennie
david
  1. 
      
  2. contrib/internal/prepare-dev.py (Diff revision 3)
     
     
     
     
     
     
     
     
     
     
    Show all issues

    This whole thing could probably just be:

    if isinstance(gitdir, bytes):
        gitdir = gitdir.decode('utf-8')
    
  3. 
      
brennie
brennie
david
  1. Ship It!
  2. 
      
chipx86
  1. 
      
  2. contrib/internal/prepare-dev.py (Diff revision 5)
     
     
     
    Show all issues

    subprocess.check_output() is going to return bytes on both Python 2.x and 3.x. So we can actually just include this in the above call, like:

    gitdir = (
        subprocess.check_output(...)
        .decode('utf-8')
        .strip()
    )
    
  3. 
      
brennie
brennie
chipx86
  1. Ship It!
  2. 
      
brennie
Review request changed
Status:
Completed
Change Summary:
Pushed to master (79b5aac)