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

[BUG] Change to pathlib causes Permission Errors when checking for config files #181

Closed
jmahlik opened this issue Sep 27, 2022 · 1 comment · Fixed by pypa/setuptools#3617
Assignees

Comments

@jmahlik
Copy link

jmahlik commented Sep 27, 2022

c7d65dd switched over to pathlib for performing config file checks. Specifically moving from os.path.isfile(...) to pathlib.Path(...).is_file(). The behavior of pathlib seems different than os. Pathlib is propagating permission errors in certain situations where the file doesn't exist or can't be accessed.

It seems like adding error handling in distutils.dist.file_config_files could resolve the issue.

Here's the result of running python -m build with setuptools 65.0.4 (includes the most vendored commit) as the root user in ci.

* Creating venv isolated environment...\n' +
    '* Installing packages in isolated environment... (setuptools >= 40.9.0, wheel)\n' +
    '* Getting dependencies for sdist...\n' +
    '\n' +
    'ERROR Backend subprocess exited when trying to invoke get_requires_for_build_sdist',
  stderr: 'Traceback (most recent call last):\n' +
    '  File "/usr/local/lib/python3.9/dist-packages/pep517/in_process/_in_process.py", line 351, in <module>\n' +
    '    main()\n' +
    '  File "/usr/local/lib/python3.9/dist-packages/pep517/in_process/_in_process.py", line 333, in main\n' +
    "    json_out['return_val'] = hook(**hook_input['kwargs'])\n" +
    '  File "/usr/local/lib/python3.9/dist-packages/pep517/in_process/_in_process.py", line 285, in get_requires_for_build_sdist\n' +
    '    return hook(config_settings)\n' +
    '  File "/tmp/build-env-eq3q247f/lib/python3.9/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_sdist\n' +
    '    return self._get_build_requires(config_settings, requirements=[])\n' +
    '  File "/tmp/build-env-eq3q247f/lib/python3.9/site-packages/setuptools/build_meta.py", line 320, in _get_build_requires\n' +
    '    self.run_setup()\n' +
    '  File "/tmp/build-env-eq3q247f/lib/python3.9/site-packages/setuptools/build_meta.py", line 335, in run_setup\n' +
    '    exec(code, locals())\n' +
    '  File "<string>", line 4, in <module>\n' +
    '  File "/tmp/build-env-eq3q247f/lib/python3.9/site-packages/setuptools/__init__.py", line 86, in setup\n' +
    '    _install_setup_requires(attrs)\n' +
    '  File "/tmp/build-env-eq3q247f/lib/python3.9/site-packages/setuptools/__init__.py", line 78, in _install_setup_requires\n' +
    '    dist.parse_config_files(ignore_option_errors=True)\n' +
    '  File "/tmp/build-env-eq3q247f/lib/python3.9/site-packages/setuptools/dist.py", line 862, in parse_config_files\n' +
    '    self._parse_config_files(filenames=inifiles)\n' +
    '  File "/tmp/build-env-eq3q247f/lib/python3.9/site-packages/setuptools/dist.py", line 704, in _parse_config_files\n' +
    '    filenames = self.find_config_files()\n' +
    '  File "/tmp/build-env-eq3q247f/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 337, in find_config_files\n' +
    '    files = [str(path) for path in self._gen_paths() if path.is_file()]\n' +
    '  File "/tmp/build-env-eq3q247f/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 337, in <listcomp>\n' +
    '    files = [str(path) for path in self._gen_paths() if path.is_file()]\n' +
    '  File "/usr/lib/python3.9/pathlib.py", line 1456, in is_file\n' +
    '    return S_ISREG(self.stat().st_mode)\n' +
    '  File "/usr/lib/python3.9/pathlib.py", line 1232, in stat\n' +
    '    return self._accessor.stat(self)\n' +
    "PermissionError: [Errno 13] Permission denied: '/root/.pydistutils.cfg'"
@victoriarouton
Copy link

Ran into the same issue.

@jmahlik jmahlik changed the title [BUG] Change to pathlib causes Perimssion Errors when checking for config files [BUG] Change to pathlib causes Permission Errors when checking for config files Sep 27, 2022
FFY00 added a commit to FFY00/distutils that referenced this issue Sep 28, 2022
Fixes pypa#181

Signed-off-by: Filipe Laíns <lains@riseup.net>
FFY00 added a commit to FFY00/distutils that referenced this issue Sep 28, 2022
Fixes pypa#181

Signed-off-by: Filipe Laíns <lains@riseup.net>
FFY00 added a commit to FFY00/distutils that referenced this issue Sep 28, 2022
Fixes pypa#181

Signed-off-by: Filipe Laíns <lains@riseup.net>
@jaraco jaraco self-assigned this Sep 29, 2022
jaraco added a commit that referenced this issue Sep 29, 2022
@jaraco jaraco closed this as completed in 2c90ac8 Sep 29, 2022
jaraco added a commit that referenced this issue Sep 29, 2022
clrpackages pushed a commit to clearlinux-pkgs/pypi-setuptools that referenced this issue Sep 30, 2022
…version 65.4.1

Jason R. Coombs (33):
      Use path.Path for changing the cwd temporarily.
      Remove needless assert renderings. Any decent test runner will provide this detail.
      Remove reference to duplicate issue.
      Refactor _is_python_source_dir using pathlib.
      Use 'samefile' to check for same file, because they may not be the same path. Fixes #180.
      Split test into two tests.
      Use pathlib
      Remove special case for TestCore.write_setup.
      Replace TESTFN with temp_file fixture.
      Remove 'cleanup_testfn', unused.
      Remove distracting comments
      In test_sysconfig, prefer fixtures to TESTFN.
      Remove cleanup_testfn, no longer used.
      Replace TESTFN with fixture.
      Remove empty logic branch.
      Use path.Path for changing the cwd temporarily.
      Remove reliance on TESTFN in test_dist
      Remove TESTFN from py38compat, no longer needed.
      xfail srcdir_simple on Windows
      Remove reliance on os_helper in test_build_ext
      Remove reliance on change_cwd
      Add compatibility shim for subprocess on Python 3.7 on Windows
      Extract _save_cwd for saving the current working directory.
      Prefer a temp_cwd fixture to reduce indentation.
      Remove reliance on create_empty_file
      Add PyPy to the test matrix on Linux. Fixes jaraco/skeleton#63.
      When rendering docs, preserve the syntax for defaults. Fixes jaraco/path#197.
      Add test for PermissionError. Ref pypa/distutils#181.
      Use os.path.isfile for checking if path.is_file, suppresses exceptions. Fixes pypa/distutils#181.
      Update changelog
      Use pathlib to open the file
      Update changelog
      Bump version: 65.4.0 → 65.4.1

Julien Palard (1):
      expand: Give bytes to ast.parse to let it discover encoding cookie.

Matthias Koeppe (3):
      .github/workflows/ci-sage.yml: Use reusable workflow https://github.com/sagemath/sage/blob/develop/.github/workflows/docker.yml
      .github/workflows/ci-sage.yml: Run on pull_request when the yml file is modified
      .github/workflows/ci-sage.yml: Use reusable workflow from https://trac.sagemath.org/ticket/33288
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Oct 5, 2022
v65.4.1

Misc

Fixed encoding errors in expand.StaticModule when system default encoding doesn't match expectations for source files.
Merge with pypa/distutils@6852b20 including fix for pypa/distutils#181.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants