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

Exception raised if installed under root. #2157

Closed
Spacetown opened this issue Apr 27, 2021 · 2 comments · Fixed by #2158
Closed

Exception raised if installed under root. #2157

Spacetown opened this issue Apr 27, 2021 · 2 comments · Fixed by #2158
Labels
C: configuration CLI and configuration C: crash Black is crashing T: bug Something isn't working

Comments

@Spacetown
Copy link

Describe the bug
If black is installed under root and run as restricted user following exception is raised:

python3 -m black --diff doc gcovr
Running chmod with sudoTraceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.6/dist-packages/black/__main__.py", line 3, in <module>
    patched_main()
  File "/usr/local/lib/python3.6/dist-packages/black/__init__.py", line 7002, in patched_main
    main()
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 781, in main
    with self.make_context(prog_name, args, **extra) as ctx:
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 700, in make_context
    self.parse_args(ctx, args)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1048, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 1630, in handle_parse_result
    value = invoke_param_callback(self.callback, ctx, self, value)
  File "/usr/local/lib/python3.6/dist-packages/click/core.py", line 123, in invoke_param_callback
    return callback(ctx, param, value)
  File "/usr/local/lib/python3.6/dist-packages/black/__init__.py", line 337, in read_pyproject_toml
    value = find_pyproject_toml(ctx.params.get("src", ()))
  File "/usr/local/lib/python3.6/dist-packages/black/__init__.py", line 315, in find_pyproject_toml
    return str(path_user_pyproject_toml) if path_user_pyproject_toml.is_file() else None
  File "/usr/lib/python3.6/pathlib.py", line 1362, in is_file
    return S_ISREG(self.stat().st_mode)
  File "/usr/lib/python3.6/pathlib.py", line 1158, in stat
    return self._accessor.stat(self)
  File "/usr/lib/python3.6/pathlib.py", line 387, in wrapped
    return strfunc(str(pathobj), *args)
PermissionError: [Errno 13] Permission denied: '/root/.config/black'

To Reproduce

  1. Install black as root
  2. Run python3 -m black --diff .
  3. See error (e.g. https://github.com/Spacetown/gcovr/runs/2450843804?check_suite_focus=true)

Expected behavior

The code shall formatted the same way as in `20.8b1, see https://github.com/Spacetown/gcovr/runs/2433190163?check_suite_focus=true.

Environment (please complete the following information):

  • Version: 21.4b1
  • OS and Python version: Docker image based on ubuntu:18.04 with Python 3.6.7.

Does this bug also happen on master?

This is the current master.

Additional context

@Spacetown Spacetown added the T: bug Something isn't working label Apr 27, 2021
@JelleZijlstra
Copy link
Collaborator

I think #2158 should fix this, could you check?

@Spacetown
Copy link
Author

Sorry, posted in the PR.

JelleZijlstra added a commit that referenced this issue Apr 27, 2021
@ichard26 ichard26 added C: crash Black is crashing C: configuration CLI and configuration labels Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: configuration CLI and configuration C: crash Black is crashing T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants