Install requirement from development fork

I’m trying to add some functionality to a custom integration (hafas) which requires updating a requirement (pyhafas). In order to test this together, I’d like to run the custom component with my own fork of the requirement.

I updated manifest.json temporarily with:

"requirements": ["git+https://github.com/akloeckner/pyhafas.git@main#egg=pyhafas"]

Supposedly, that should work, because this field takes any pip-compatible string. And the string should be pip-compatible. But this gives me an error during start of HA.

Logger: homeassistant.bootstrap
Source: util/package.py:47
First occurred: 9. Mai 2023 um 23:30:53 (1 occurrences)
Last logged: 9. Mai 2023 um 23:30:53

Error setting up integration hafas - received exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 35, in __init__
    parsed = parse_requirement(requirement_string)
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/_parser.py", line 64, in parse_requirement
    return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES))
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/_parser.py", line 82, in _parse_requirement
    url, specifier, marker = _parse_requirement_details(tokenizer)
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/_parser.py", line 126, in _parse_requirement_details
    marker = _parse_requirement_marker(
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/_parser.py", line 147, in _parse_requirement_marker
    tokenizer.raise_syntax_error(
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/_tokenizer.py", line 163, in raise_syntax_error
    raise ParserSyntaxError(
pkg_resources.extern.packaging._tokenizer.ParserSyntaxError: Expected end or semicolon (after name and no valid version specifier)
    git+https://github.com/akloeckner/pyhafas.git@main#egg=pyhafas
       ^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/util/package.py", line 40, in is_installed
    pkg_resources.get_distribution(package)
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py", line 512, in get_distribution
    dist = Requirement.parse(dist)
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py", line 3144, in parse
    (req,) = parse_requirements(s)
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py", line 3103, in __init__
    super(Requirement, self).__init__(requirement_string)
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 37, in __init__
    raise InvalidRequirement(str(e)) from e
pkg_resources.extern.packaging.requirements.InvalidRequirement: Expected end or semicolon (after name and no valid version specifier)
    git+https://github.com/akloeckner/pyhafas.git@main#egg=pyhafas
       ^

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 35, in __init__
    parsed = parse_requirement(requirement_string)
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/_parser.py", line 64, in parse_requirement
    return _parse_requirement(Tokenizer(source, rules=DEFAULT_RULES))
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/_parser.py", line 82, in _parse_requirement
    url, specifier, marker = _parse_requirement_details(tokenizer)
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/_parser.py", line 126, in _parse_requirement_details
    marker = _parse_requirement_marker(
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/_parser.py", line 147, in _parse_requirement_marker
    tokenizer.raise_syntax_error(
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/_tokenizer.py", line 163, in raise_syntax_error
    raise ParserSyntaxError(
pkg_resources.extern.packaging._tokenizer.ParserSyntaxError: Expected end or semicolon (after name and no valid version specifier)
    egg=pyhafas
       ^

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 100, in async_setup_component
    return await task
  File "/usr/src/homeassistant/homeassistant/setup.py", line 203, in _async_setup_component
    await async_process_deps_reqs(hass, config, integration)
  File "/usr/src/homeassistant/homeassistant/setup.py", line 388, in async_process_deps_reqs
    await requirements.async_get_integration_with_requirements(
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 52, in async_get_integration_with_requirements
    return await manager.async_get_integration_with_requirements(domain)
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 171, in async_get_integration_with_requirements
    await self._async_process_integration(integration, done)
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 186, in _async_process_integration
    await self.async_process_requirements(
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 252, in async_process_requirements
    await self._async_process_requirements(name, missing)
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 284, in _async_process_requirements
    installed, failures = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/requirements.py", line 113, in _install_requirements_if_missing
    if pkg_util.is_installed(req) or _install_with_retry(req, kwargs):
  File "/usr/src/homeassistant/homeassistant/util/package.py", line 47, in is_installed
    req = pkg_resources.Requirement.parse(urlparse(package).fragment)
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py", line 3144, in parse
    (req,) = parse_requirements(s)
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/__init__.py", line 3103, in __init__
    super(Requirement, self).__init__(requirement_string)
  File "/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 37, in __init__
    raise InvalidRequirement(str(e)) from e
pkg_resources.extern.packaging.requirements.InvalidRequirement: Expected end or semicolon (after name and no valid version specifier)
    egg=pyhafas
       ^

I don’t understand what I should do to make this work. Can anyone please point me in the right direction?

I found a solution. This seems to work:

"requirements": ["git+https://github.com/akloeckner/pyhafas.git@main#pyhafas"]

The documentation led me in the right direction :man_facepalming: :

I found it through this topic:

1 Like