cyberjunky / python-garminconnect

Python 3 API wrapper for Garmin Connect to get activity statistics
MIT License
802 stars 132 forks source link

Incompatible dependency resolution with sqlmodel #162

Closed pzelnip closed 9 months ago

pzelnip commented 9 months ago

I use this library & sqlmodel on the same project. I also use pip-tools to generate my requirements.txt file. The latest version of these two libraries are incompatible. With this requirements.in file:

garminconnect
sqlmodel

When I do:

pip-compile --upgrade --generate-hashes --output-file requirements.txt requirements.in

I get:

  ERROR: Cannot install -r requirements.in (line 11) because these package versions have conflicting dependencies.
Traceback (most recent call last):
  File "/Users/adamparkin/.envs/garmin/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 316, in _backjump
    name, candidate = broken_state.mapping.popitem()
KeyError: 'dictionary is empty'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/adamparkin/.envs/garmin/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 92, in resolve
    result = self._result = resolver.resolve(
  File "/Users/adamparkin/.envs/garmin/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 546, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
  File "/Users/adamparkin/.envs/garmin/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 434, in resolve
    success = self._backjump(causes)
  File "/Users/adamparkin/.envs/garmin/lib/python3.10/site-packages/pip/_vendor/resolvelib/resolvers.py", line 318, in _backjump
    raise ResolutionImpossible(causes)
pip._vendor.resolvelib.resolvers.ResolutionImpossible: [RequirementInformation(requirement=SpecifierRequirement('sqlalchemy2-stubs<0.0.2,>=0.0.2-alpha.5'), parent=LinkCandidate('https://files.pythonhosted.org/packages/51/37/2524e8a0329ff511af4e408c3e1fdeea3ed7382ff3faf0f45921f4876b64/sqlmodel-0.0.2-py3-none-any.whl (from https://pypi.org/simple/sqlmodel/) (requires-python:>=3.6.1,<4.0.0)')), RequirementInformation(requirement=SpecifierRequirement('sqlalchemy2-stubs<0.0.2,>=0.0.2-alpha.5'), parent=LinkCandidate('https://files.pythonhosted.org/packages/15/a5/c61987515b78660d7e5994e2b469d2b06b362d3dede951467c9385daa21c/sqlmodel-0.0.1-py3-none-any.whl (from https://pypi.org/simple/sqlmodel/) (requires-python:>=3.6.1,<4.0.0)'))]

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

Traceback (most recent call last):
  File "/Users/adamparkin/.envs/garmin/bin/pip-compile", line 8, in <module>
    sys.exit(cli())
  File "/Users/adamparkin/.envs/garmin/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/Users/adamparkin/.envs/garmin/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/Users/adamparkin/.envs/garmin/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/adamparkin/.envs/garmin/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/Users/adamparkin/.envs/garmin/lib/python3.10/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/adamparkin/.envs/garmin/lib/python3.10/site-packages/piptools/scripts/compile.py", line 659, in cli
    results = resolver.resolve(max_rounds=max_rounds)
  File "/Users/adamparkin/.envs/garmin/lib/python3.10/site-packages/piptools/resolver.py", line 604, in resolve
    is_resolved = self._do_resolve(
  File "/Users/adamparkin/.envs/garmin/lib/python3.10/site-packages/piptools/resolver.py", line 636, in _do_resolve
    resolver.resolve(
  File "/Users/adamparkin/.envs/garmin/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 101, in resolve
    raise error from e
pip._internal.exceptions.DistributionNotFound: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

This is with the latest version of pip-tools (7.3.0).

pzelnip commented 9 months ago

Also, if I disregard pip tools and install all my dependencies except garminconnect, and then manually pip install garminconnect I get this error from pip:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
sqlmodel 0.0.8 requires pydantic<2.0.0,>=1.8.2, but you have pydantic 2.4.2 which is incompatible.

Looking at sqlmodel's pyproject.toml, it looks like it specifies 1.8.2 or greater of Pydantic (but less than 2.0), which isn't compatible with garminconnect.

Digging a bit further, I didn't see Pydantic in garminconnect's direct dependencies. However, it does depend on garth, which in turn does depend on pydantic. I can't find the source repo for garth anywhere (!!).

Doing some digging though it looks like the last version of garth to be compatible with pydantic before 2.0 is 0.4.18, which is less than the 0.4.23 requirement for garminconnect

As such, I can't seem to figure out any workaround for getting both sqlmodel & garminconnect installed together until sqlmodel upgrades to pydantic 2.0 (which is likely a ways off)

matin commented 9 months ago

Garth maintainer here. I'll look into ways to resolve this issue.

Garth depends on certain features only available in Pydantic 2, but there may be a way to support both versions of Pydantic.

Thanks for reporting the issue.

matin commented 9 months ago

fwiw, sqlmodel is working making the transition to Pydantic 2: https://github.com/tiangolo/sqlmodel/issues/532

That being said, I'll still work on ways to support both Pydantic versions in the meantime.

matin commented 9 months ago

@pzelnip can you try upgrading to Garth 0.4.34?

Garth now supports >= 1.10.13 (as tested), which is within the range sqlmodel supports.

pzelnip commented 9 months ago

Confirmed that garth 0.4.34 works with sqlmodel 0.0.8. Thanks!

With this, I think this issue can now be resolved, I could successfully install latest garminconnect & sqlmodel together.