kynan / nbstripout

strip output from Jupyter and IPython notebooks
Other
1.19k stars 94 forks source link

Add a --system argument for system-wide installation #149

Closed PLPeeters closed 3 years ago

PLPeeters commented 3 years ago

This PR adds a --system argument for system-wide installation.

Since there doesn't seem to be a simple way to figure out the $(prefix) variable of the Git installation, I had to resort to a kind of hacky way to figure that one out in order to put the system-wide gitattributes file in the correct place (see the _get_system_gitconfig_folder() function).

I also fixed the path of the gitattributes file in the documentation when using the --global argument, which was incorrectly documented as being .git/info/attributes instead of ~/.config/git/attributes.

I also took the liberty of adding a few newlines to improve readability.

PLPeeters commented 3 years ago

I also just went ahead and added a fix and a test for the --status command which was apparently broken, along with some unification in the treatment of shell output (setting text=True everywhere and removing calls to .decode() that are no longer necessary with this). I can do a separate PR for that if you prefer, but since it intersects with my changes it was just easier for me to include it in here.

PLPeeters commented 3 years ago

@kynan Changed the text parameter as requested.

The stray output was due to the git config call to fetch the extra keys. I changed it to a simple git config when nbstripout is called without the --system or --global parameters, since that seemed to make the most sense.

I also fixed the Git test since it didn't run properly on my system even though it looks fine on Travis. Apparently the version of Git on macOS seems to insist on having a newline at the end of the attributes file (it threw an *.txt is not a valid attribute name: .git/info/attributes:1 error on all the Git calls in that test for me).