kynan / nbstripout

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

nbstripout --install --global cannot file ~/.config/git/attributes #139

Closed dennisobrien closed 3 years ago

dennisobrien commented 3 years ago

I am trying to install nbstripout git integrations globally but I get an error finding the file ~/.config/git/attributes.

$ nbstripout --install --global
Traceback (most recent call last):
  File "/Users/denniso/opt/anaconda3/bin/nbstripout", line 10, in <module>
    sys.exit(main())
  File "/Users/denniso/opt/anaconda3/lib/python3.7/site-packages/nbstripout/_nbstripout.py", line 299, in main
    sys.exit(install(git_config, user=args._global, attrfile=args.attributes))
  File "/Users/denniso/opt/anaconda3/lib/python3.7/site-packages/nbstripout/_nbstripout.py", line 175, in install
    with open(attrfile, 'a', newline='') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/denniso/.config/git/attributes'

Is this attribute file expected to exist already? I would expect it to be using the file ~/.gitconfig based on the docs.

This is on MacOS 10.15.7

$ git --version
git version 2.24.3 (Apple Git-128)
$ nbstripout --version
0.3.9
dennisobrien commented 3 years ago

If I manually create this empty file before installing, I don't see an error.

$ mkdir -p ~/.config/git
$ touch ~/.config/git/attributes
$ nbstripout --install --global

I'm not sure if the file ~/.config/git/attributes not existing is a bug with my git setup, or if nbstripout should be modified to create the file if it doesn't exist. I'm happy to make a PR if you have an opinion about how best to handle this.

0x326 commented 3 years ago

The ${HOME}/.config/git directory isn't created by default in a Git installation. The error is essentially the same error one would get doing the following:

echo '...' > "${HOME}/.config/git/attributes

nbstripout should create the ${HOME}/.config/git directory (and any missing parent directories) if they don't exist (e.g. mkdir -p "${HOME}/.config/git")

kynan commented 3 years ago

Thanks for reporting this. That is indeed a regression and nbstripout should be creating this directory if needed.

I'm implementing the convention document in man gitattributes btw.:

If you wish to affect only a single repository (i.e., to assign attributes to files that are particular to one user’s workflow for that repository), then attributes should be placed in the $GIT_DIR/info/attributes file. Attributes which should be version-controlled and distributed to other repositories (i.e., attributes of interest to all users) should go into .gitattributes files. Attributes that should affect all repositories for a single user should be placed in a file specified by the core.attributesFile configuration option (see git-config(1)). Its default value is $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/attributes is used instead. Attributes for all users on a system should be placed in the $(prefix)/etc/gitattributes file.