lk-geimfari / mimesis

Mimesis is a robust data generator for Python that can produce a wide range of fake data in multiple languages.
https://mimesis.name
MIT License
4.4k stars 334 forks source link

Mimesis fails on FreeBSD #1544

Closed patmaddox closed 4 months ago

patmaddox commented 5 months ago

Bug report

What's wrong

self = <mimesis.providers.path.Path object at 0x8634f1490>, platform = 'freebsd13', args = (), kwargs = {'seed': <mimesis.types._MissingSeed object at 0x845334b10>}

    def __init__(
        self,
        platform: str = sys.platform,
        *args: t.Any,
        **kwargs: t.Any,
    ) -> None:
        """Initialize attributes.

        Supported platforms: 'linux', 'darwin', 'win32', 'win64'.

        :param platform: Required platform type.
        """
        super().__init__(*args, **kwargs)
        self.platform = platform
        self._pathlib_home = PureWindowsPath() if "win" in platform else PurePosixPath()
>       self._pathlib_home /= PLATFORMS[platform]["home"]
E       KeyError: 'freebsd13'

mimesis/providers/path.py:37: KeyError

How is that should be

It works

System information

FreeBSD 13

patmaddox commented 5 months ago

In #1545 I added explicit support for FreeBSD. Instead of this approach, I wonder if it would be worth defaulting to /home/ on POSIX systems, and have Windows be the one exceptional case? The only system-specific config is the home dir.

I don't have access to a windows machine for testing, so I don't know exactly what it would be, but something like:

if "win" in platform:
    self._pathlib_home = PureWindowsPath() / "C:\\Users\\"
else:
    self._pathlib_home = PurePosixPath / "/home/"

or perhaps it's even simpler:

self._pathlib_home = WindowsPath("C:\\Users\\") if "win" in platform else PosixPath("/home/")

That way it would work on any BSD, solaris, etc.