oracle / graalpython

A Python 3 implementation built on GraalVM
Other
1.2k stars 103 forks source link

pyfakefs: AttributeError: module 'os' has no attribute 'getgid' #327

Closed jiridanek closed 1 year ago

jiridanek commented 1 year ago

The following code in pyfakefs does not run, https://github.com/pytest-dev/pyfakefs/blob/fa36aee5d072b4f80d9ad0a0dc9091e4e2e2e193/pyfakefs/helpers.py#L43-L44

I am intending to have a look on Friday and maybe send a PR, if I can figure this out. If it is indeed the case that os.getuid() is implemented and os.getgid() is not, it should not be hard to add that (by analogy)

$ venvgpy_nightly/bin/graalpy -c 'import os; print(os.getgid())'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'os' has no attribute 'getgid'
$ venvgpy_nightly/bin/graalpy -c 'import os; print(os.getuid())'
1000

pyfakefs stacktrace

Traceback (most recent call last):
  File "/home/jdanek/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/231.8109.175.plugins/python/helpers/pycharm/_jb_pytest_runner.py", line 53, in <module>
    sys.exit(pytest.main(args, plugins_to_load + [Plugin]))
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/_pytest/config/__init__.py", line 148, in main
    config = _prepareconfig(args, plugins)
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/_pytest/config/__init__.py", line 329, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/pluggy/_callers.py", line 55, in _multicall
    gen.send(outcome)
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/_pytest/helpconfig.py", line 103, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1060, in pytest_cmdline_parse
    self.parse(args)
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1348, in parse
    self._preparse(args, addopts=addopts)
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1231, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/home/jdanek/Downloads/graalpy-23.1.0-dev-linux-amd64/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/home/jdanek/Downloads/graalpy-23.1.0-dev-linux-amd64/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/pyfakefs/pytest_plugin.py", line 14, in <module>
    from pyfakefs.fake_filesystem_unittest import Patcher
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/pyfakefs/fake_filesystem_unittest.py", line 71, in <module>
    from pyfakefs.fake_filesystem import (
  File "/home/jdanek/venvgpy_nightly/lib/python3.10/site-packages/pyfakefs/fake_filesystem.py", line 210, in <module>
    GROUP_ID = os.getgid()
AttributeError: module 'os' has no attribute 'getgid'
msimacek commented 1 year ago

Indeed, it should be straightforward to just copy and change the code for getuid. There's a bit of boilerplate because of indirection. We have two different backends for posix functions:

If you want to add a new posix call, you need to add a new method to PosixSupportLibrary and implement it in all 4 Truffle library implementations (NFIPosixSupport, EmulatedPosixSupport, ImageBuildtimePosixSupport, LoggingPosixSupport), then add a builtin to PosixModuleBuiltins that calls the function. Feel free to drop by on the #graalpy slack channel if you have any questions.

msimacek commented 1 year ago

PR merged