pkgxdev / pkgx

run anything
https://pkgx.sh
Apache License 2.0
8.95k stars 1.36k forks source link

`pkgx black`: PermissionError: [Errno 13] Permission denied: '/.git' #973

Closed magnusviri closed 7 months ago

magnusviri commented 7 months ago

This happens on more than one of my computers. One is macOS 14, the other is macOS 13.

pkgx black            
 ✓  ~/.pkgx/python.org/v3.11.8                                    
Traceback (most recent call last):                                
  File "/Users/test/.pkgx/github.com/psf/black/v24.2.0/venv/bin/black", line 8, in <module>
    sys.exit(patched_main())
             ^^^^^^^^^^^^^^
  File "/Users/test/.pkgx/github.com/psf/black/v24.2.0/venv/lib/python3.11/site-packages/black/__init__.py", line 1587, in patched_main
    main()
  File "/Users/test/.pkgx/github.com/psf/black/v24.2.0/venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/test/.pkgx/github.com/psf/black/v24.2.0/venv/lib/python3.11/site-packages/click/core.py", line 1077, in main
    with self.make_context(prog_name, args, **extra) as ctx:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/test/.pkgx/github.com/psf/black/v24.2.0/venv/lib/python3.11/site-packages/click/core.py", line 943, in make_context
    self.parse_args(ctx, args)
  File "/Users/test/.pkgx/github.com/psf/black/v24.2.0/venv/lib/python3.11/site-packages/click/core.py", line 1408, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/test/.pkgx/github.com/psf/black/v24.2.0/venv/lib/python3.11/site-packages/click/core.py", line 2400, in handle_parse_result
    value = self.process_value(ctx, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/test/.pkgx/github.com/psf/black/v24.2.0/venv/lib/python3.11/site-packages/click/core.py", line 2362, in process_value
    value = self.callback(ctx, self, value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/test/.pkgx/github.com/psf/black/v24.2.0/venv/lib/python3.11/site-packages/black/__init__.py", line 129, in read_pyproject_toml
    value = find_pyproject_toml(
            ^^^^^^^^^^^^^^^^^^^^
  File "/Users/test/.pkgx/github.com/psf/black/v24.2.0/venv/lib/python3.11/site-packages/black/files.py", line 109, in find_pyproject_toml
    path_project_root, _ = find_project_root(path_search_start, stdin_filename)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/test/.pkgx/github.com/psf/black/v24.2.0/venv/lib/python3.11/site-packages/black/files.py", line 91, in find_project_root
    if (directory / ".git").exists():
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/test/.pkgx/python.org/v3.11.8/lib/python3.11/pathlib.py", line 1235, in exists
    self.stat()
  File "/Users/test/.pkgx/python.org/v3.11.8/lib/python3.11/pathlib.py", line 1013, in stat
    return os.stat(self, follow_symlinks=follow_symlinks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: '/.git'
dosubot[bot] commented 7 months ago

🤖

Hey @magnusviri! Good to see you back, hope you're doing well.

The error you're encountering is due to insufficient permissions when trying to access the /.git directory. This is happening because the black command is trying to find the root of the project by looking for a .git directory, starting from the current directory and moving upwards. When it reaches the root directory / and tries to access /.git, it fails because of insufficient permissions.

This issue can be resolved by ensuring that you're running the pkgx black command from within the directory of the project you're trying to format with Black, and not from the root directory /.

If you're already running the command from within the project directory and still encountering this issue, it could be due to an incorrect setup of your environment. In this case, you might want to check the permissions of your project directory and its parent directories.

Here's a command you can use to check the permissions of the current directory and its parent directories:

name=$(pwd); while [[ "$name" != "" ]]; do ls -ld "$name"; name=${name%/*}; done

This command will list the permissions of the current directory and each of its parent directories. If you see any directory that doesn't have read and execute permissions for your user, you can add them using the chmod command. For example, to add read and execute permissions for the user on the directory /path/to/directory, you can use the following command:

chmod u+rx /path/to/directory

Please note that you might need to use sudo with the chmod command if you don't own the directory.

I hope this helps! If you have any further questions, feel free to ask.

Sources:

Sources

#### About Dosu This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.
magnusviri commented 7 months ago

I think this is a black bug. Nevermind.

magnusviri commented 7 months ago

Yeah, I just confirmed it's a black bug.