mtkennerly / dunamai

Dynamic versioning library and CLI
https://dunamai.readthedocs.io/en/latest
MIT License
320 stars 23 forks source link

`test__version__from_fossil` fails without home #77

Closed mtelka closed 7 months ago

mtelka commented 7 months ago

The test__version__from_fossil test fails when there is no home set:

__________________________ test__version__from_fossil __________________________

tmp_path = PosixPath('/tmp/pytest-of-marcel/pytest-18/test__version__from_fossil0')

    @pytest.mark.skipif(shutil.which("fossil") is None, reason="Requires Fossil")
    def test__version__from_fossil(tmp_path) -> None:
        vcs = tmp_path / "dunamai-fossil"
        vcs.mkdir()
        run = make_run_callback(vcs)
        from_vcs = make_from_callback(Version.from_fossil)
        b = "trunk"

        with chdir(vcs):
>           run("fossil init repo")

tests/integration/test_dunamai.py:800:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/integration/test_dunamai.py:44: in inner
    _, out = _run_cmd(command, where=where, codes=[expected_code], env=env)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

command = 'fossil init repo'
where = PosixPath('/tmp/pytest-of-marcel/pytest-18/test__version__from_fossil0/dunamai-fossil')
codes = [0], shell = False, env = None

    def _run_cmd(
        command: str,
        where: Optional[Path],
        codes: Sequence[int] = (0,),
        shell: bool = False,
        env: Optional[dict] = None,
    ) -> Tuple[int, str]:
        result = subprocess.run(
            shlex.split(command),
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            cwd=str(where) if where is not None else None,
            shell=shell,
            env=env,
        )
        output = result.stdout.decode().strip()
        if codes and result.returncode not in codes:
>           raise RuntimeError(
                "The command '{}' returned code {}. Output:\n{}".format(
                    command, result.returncode, output
                )
            )
E           RuntimeError: The command 'fossil init repo' returned code 1. Output:
E           cannot locate home directory - please set one of the FOSSIL_HOME, XDG_CONFIG_HOME, or HOME environment variables

dunamai/__init__.py:207: RuntimeError

Please note that once I provide home (by setting HOME to /tmp) then test complains with this:

>           raise RuntimeError(
                "The command '{}' returned code {}. Output:\n{}".format(
                    command, result.returncode, output
                )
            )
E           RuntimeError: The command 'fossil init repo' returned code 1. Output:
E           cannot determine user
E           Cannot figure out who you are!  Consider using the --user
E           command line option, setting your USER environment variable,
E           or setting a default user with "fossil user default USER".

So user needs to be provided too. It looks like fossil is too picky and is unable to call getuid() :-). Nomen omen? :-)

mtkennerly commented 7 months ago

That's good to know, thanks! I've added a note to CONTRIBUTING.md about this.

mtelka commented 7 months ago

Wouldn't it be simpler to simply set HOME in test__version__from_fossil if it is not set already?

mtkennerly commented 7 months ago

I guess that's probably fine. It may not always be necessary (e.g., user already ran fossil user default ..., or is on Windows where it's seemingly not required), but it shouldn't hurt anything.

mtelka commented 7 months ago

Looking at the patch... will that work when there is no user dunamai in /etc/passwd? Sorry for stupid question, I've zero experience with fossil.

mtkennerly commented 7 months ago

I'm assuming Fossil just takes the env var value as-is, but I'm not sure either. Would you mind giving it a test in your setup?

mtelka commented 7 months ago

Confirmed: all tests pass with 3cc9be2 without need to set HOME/USER explicitly.

Thank you!

PS1: I think you can remove fossil note from f17bcf2 PS2: I do NOT need new dunamai release with this fix only.