Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conda smithy rerender -c auto failing with AssertionError on git repositories with index v3 #2116

Closed
1 task done
mgorny opened this issue Nov 4, 2024 · 5 comments · Fixed by #2120
Closed
1 task done
Labels

Comments

@mgorny
Copy link
Contributor

mgorny commented Nov 4, 2024

Solution to issue cannot be found in the documentation.

  • I checked the documentation.

Issue

When using new enough git (2.47.0 here), all newly cloned repositories are using index version 3. When trying to use conda-smithy on such a repository, I'm getting the following error:

$ conda smithy rerender -c auto
Traceback (most recent call last):
  File "/home/mgorny/miniforge3/bin/conda-smithy", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/conda_smithy/cli.py", line 758, in main
    args.subcommand_func(args)
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/conda_smithy/cli.py", line 599, in __call__
    self._call(args, tmpdir)
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/conda_smithy/cli.py", line 604, in _call
    configure_feedstock.main(
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/conda_smithy/configure_feedstock.py", line 2766, in main
    config = _load_forge_config(forge_dir, exclusive_config_file, forge_yml)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/conda_smithy/configure_feedstock.py", line 2417, in _load_forge_config
    config = _legacy_compatibility_checks(config, forge_dir)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/conda_smithy/configure_feedstock.py", line 2300, in _legacy_compatibility_checks
    remove_file_or_dir(os.path.join(forge_dir, old_file))
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/conda_smithy/feedstock_io.py", line 67, in remove_file_or_dir
    return remove_file(filename)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/conda_smithy/feedstock_io.py", line 76, in remove_file
    touch_file(filename)
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/conda_smithy/feedstock_io.py", line 61, in touch_file
    with write_file(filename) as fh:
         ^^^^^^^^^^^^^^^^^^^^
  File "/home/mgorny/miniforge3/lib/python3.12/contextlib.py", line 144, in __exit__
    next(self.gen)
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/conda_smithy/feedstock_io.py", line 57, in write_file
    repo.index.add([filename])
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/git/index/base.py", line 946, in add
    self.entries[(entry.path, 0)] = IndexEntry.from_base(entry)
    ^^^^^^^^^^^^
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/gitdb/util.py", line 253, in __getattr__
    self._set_cache_(attr)
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/git/index/base.py", line 168, in _set_cache_
    self._deserialize(stream)
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/git/index/base.py", line 197, in _deserialize
    self.version, self.entries, self._extension_data, _conten_sha = read_cache(stream)
                                                                    ^^^^^^^^^^^^^^^^^^
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/git/index/fun.py", line 252, in read_cache
    version, num_entries = read_header(stream)
                           ^^^^^^^^^^^^^^^^^^^
  File "/home/mgorny/miniforge3/lib/python3.12/site-packages/git/index/fun.py", line 210, in read_header
    assert version in (1, 2)
           ^^^^^^^^^^^^^^^^^
AssertionError

This seems to be gitpython-developers/GitPython#1960. However, from what I understand it's unlikely to be fixed anytime soon, so perhaps some solution on conda-smithy end would be preferable.

A possible workaround is to force feature.manyFiles=false in git while cloning the repository.

Installed packages

# packages in environment at /home/mgorny/miniforge3:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
anyio                     4.6.2.post1        pyhd8ed1ab_0    conda-forge
archspec                  0.2.3              pyhd8ed1ab_0    conda-forge
attrs                     24.2.0             pyh71513ae_0    conda-forge
backports                 1.0                pyhd8ed1ab_4    conda-forge
backports.strenum         1.2.8              pyhd8ed1ab_0    conda-forge
backports.tarfile         1.0.0              pyhd8ed1ab_1    conda-forge
beautifulsoup4            4.12.3             pyha770c72_0    conda-forge
blinker                   1.8.2              pyhd8ed1ab_0    conda-forge
boltons                   24.0.0             pyhd8ed1ab_0    conda-forge
boolean.py                4.0                pyhd8ed1ab_0    conda-forge
brotli-python             1.1.0           py312h2ec8cdc_2    conda-forge
bzip2                     1.0.8                h4bc722e_7    conda-forge
c-ares                    1.32.3               h4bc722e_0    conda-forge
ca-certificates           2024.8.30            hbcca054_0    conda-forge
certifi                   2024.8.30          pyhd8ed1ab_0    conda-forge
cffi                      1.17.1          py312h06ac9bb_0    conda-forge
chardet                   5.2.0           py312h7900ff3_2    conda-forge
charset-normalizer        3.4.0              pyhd8ed1ab_0    conda-forge
cirun                     0.30               pyhd8ed1ab_0    conda-forge
click                     8.1.7           unix_pyh707e725_0    conda-forge
colorama                  0.4.6              pyhd8ed1ab_0    conda-forge
conda                     24.9.2          py312h7900ff3_0    conda-forge
conda-build               24.9.0          py312h7900ff3_0    conda-forge
conda-forge-pinning       2024.11.04.11.32.56      hd8ed1ab_0    conda-forge
conda-index               0.5.0              pyhd8ed1ab_0    conda-forge
conda-libmamba-solver     24.9.0             pyhd8ed1ab_0    conda-forge
conda-package-handling    2.4.0              pyh7900ff3_0    conda-forge
conda-package-streaming   0.11.0             pyhd8ed1ab_0    conda-forge
conda-smithy              3.43.2          unix_pyh707e725_0    conda-forge
cryptography              43.0.3          py312hda17c39_0    conda-forge
dbus                      1.13.6               h5008d03_3    conda-forge
deprecated                1.2.14             pyh1a96a4e_0    conda-forge
distlib                   0.3.9              pyhd8ed1ab_0    conda-forge
distro                    1.9.0              pyhd8ed1ab_0    conda-forge
editables                 0.5                pyhd8ed1ab_0    conda-forge
exceptiongroup            1.2.2              pyhd8ed1ab_0    conda-forge
expat                     2.6.3                h5888daf_0    conda-forge
filelock                  3.16.1             pyhd8ed1ab_0    conda-forge
fmt                       10.2.1               h00ab1b0_0    conda-forge
frozendict                2.4.6           py312h66e93f0_0    conda-forge
git                       2.47.0          pl5321h59d505e_0    conda-forge
gitdb                     4.0.11             pyhd8ed1ab_0    conda-forge
gitpython                 3.1.43             pyhd8ed1ab_0    conda-forge
gmp                       6.3.0                hac33072_2    conda-forge
h11                       0.14.0             pyhd8ed1ab_0    conda-forge
h2                        4.1.0              pyhd8ed1ab_0    conda-forge
hatch                     1.13.0             pyhd8ed1ab_0    conda-forge
hatchling                 1.25.0             pyhd8ed1ab_0    conda-forge
hpack                     4.0.0              pyh9f0ad1d_0    conda-forge
httpcore                  1.0.6              pyhd8ed1ab_0    conda-forge
httpx                     0.27.2             pyhd8ed1ab_0    conda-forge
hyperframe                6.0.1              pyhd8ed1ab_0    conda-forge
hyperlink                 21.0.0             pyhd3deb0d_0    conda-forge
icu                       75.1                 he02047a_0    conda-forge
idna                      3.10               pyhd8ed1ab_0    conda-forge
importlib-metadata        8.5.0              pyha770c72_0    conda-forge
importlib_resources       6.4.5              pyhd8ed1ab_0    conda-forge
isodate                   0.7.2              pyhd8ed1ab_0    conda-forge
jaraco.classes            3.4.0              pyhd8ed1ab_1    conda-forge
jaraco.context            5.3.0              pyhd8ed1ab_1    conda-forge
jaraco.functools          4.0.0              pyhd8ed1ab_0    conda-forge
jeepney                   0.8.0              pyhd8ed1ab_0    conda-forge
jinja2                    3.1.4              pyhd8ed1ab_0    conda-forge
jsonpatch                 1.33               pyhd8ed1ab_0    conda-forge
jsonpointer               3.0.0           py312h7900ff3_1    conda-forge
jsonschema                4.23.0             pyhd8ed1ab_0    conda-forge
jsonschema-specifications 2024.10.1          pyhd8ed1ab_0    conda-forge
keyring                   25.5.0             pyha804496_0    conda-forge
keyutils                  1.6.1                h166bdaf_0    conda-forge
krb5                      1.21.3               h659f571_0    conda-forge
ld_impl_linux-64          2.43                 h712a8e2_2    conda-forge
libarchive                3.7.4                hfca40fe_0    conda-forge
libcurl                   8.10.1               hbbe4b11_0    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 hd590300_2    conda-forge
libexpat                  2.6.3                h5888daf_0    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc                    14.2.0               h77fa898_1    conda-forge
libgcc-ng                 14.2.0               h69a702a_1    conda-forge
libglib                   2.82.2               h2ff4ddf_0    conda-forge
libgomp                   14.2.0               h77fa898_1    conda-forge
libiconv                  1.17                 hd590300_2    conda-forge
liblief                   0.14.1               h5888daf_2    conda-forge
libmamba                  1.5.9                h4cc3d14_0    conda-forge
libmambapy                1.5.9           py312h7fb9e8e_0    conda-forge
libnghttp2                1.64.0               h161d5f1_0    conda-forge
libnsl                    2.0.1                hd590300_0    conda-forge
libsodium                 1.0.20               h4ab18f5_0    conda-forge
libsolv                   0.7.30               h3509ff9_0    conda-forge
libsqlite                 3.47.0               hadc24fc_0    conda-forge
libssh2                   1.11.0               h0841786_0    conda-forge
libstdcxx                 14.2.0               hc0a3c3a_1    conda-forge
libstdcxx-ng              14.2.0               h4852527_1    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libxcrypt                 4.4.36               hd590300_1    conda-forge
libxml2                   2.12.7               he7c6b58_4    conda-forge
libzlib                   1.3.1                hb9d3cd8_2    conda-forge
license-expression        30.3.1             pyhd8ed1ab_0    conda-forge
lz4-c                     1.9.4                hcb278e6_0    conda-forge
lzo                       2.10              hd590300_1001    conda-forge
mamba                     1.5.9           py312h9460a1c_0    conda-forge
markdown-it-py            3.0.0              pyhd8ed1ab_0    conda-forge
markupsafe                3.0.2           py312h178313f_0    conda-forge
mdurl                     0.1.2              pyhd8ed1ab_0    conda-forge
menuinst                  2.1.2           py312h7900ff3_1    conda-forge
more-itertools            10.5.0             pyhd8ed1ab_0    conda-forge
msrest                    0.6.21             pyh44b312d_0    conda-forge
ncurses                   6.5                  he02047a_1    conda-forge
oauthlib                  3.2.2              pyhd8ed1ab_0    conda-forge
openssl                   3.3.2                hb9d3cd8_0    conda-forge
packaging                 24.1               pyhd8ed1ab_0    conda-forge
patch                     2.7.6             h7f98852_1002    conda-forge
patchelf                  0.17.2               h58526e2_0    conda-forge
pathspec                  0.12.1             pyhd8ed1ab_0    conda-forge
pcre2                     10.44                hba22ea6_2    conda-forge
perl                      5.32.1          7_hd590300_perl5    conda-forge
pexpect                   4.9.0              pyhd8ed1ab_0    conda-forge
pip                       24.2               pyh8b19718_1    conda-forge
pkginfo                   1.11.2             pyhd8ed1ab_0    conda-forge
pkgutil-resolve-name      1.3.10             pyhd8ed1ab_1    conda-forge
platformdirs              4.3.6              pyhd8ed1ab_0    conda-forge
pluggy                    1.5.0              pyhd8ed1ab_0    conda-forge
psutil                    6.1.0           py312h66e93f0_0    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
py-lief                   0.14.1          py312h2ec8cdc_2    conda-forge
pybind11-abi              4                    hd8ed1ab_3    conda-forge
pycosat                   0.6.6           py312h98912ed_0    conda-forge
pycparser                 2.22               pyhd8ed1ab_0    conda-forge
pycryptodome              3.21.0          py312h6368725_0    conda-forge
pygithub                  2.4.0              pyhd8ed1ab_0    conda-forge
pygments                  2.18.0             pyhd8ed1ab_0    conda-forge
pyjwt                     2.9.0              pyhd8ed1ab_1    conda-forge
pynacl                    1.5.0           py312h66e93f0_4    conda-forge
pysocks                   1.7.1              pyha2e5f31_6    conda-forge
python                    3.12.7          hc5c86c4_0_cpython    conda-forge
python-dateutil           2.9.0              pyhd8ed1ab_0    conda-forge
python-libarchive-c       5.1             py312h7900ff3_1    conda-forge
python_abi                3.12                    5_cp312    conda-forge
pytz                      2024.2             pyhd8ed1ab_0    conda-forge
pyyaml                    6.0.2           py312h66e93f0_1    conda-forge
rattler-build             0.28.2               h51b9b6e_0    conda-forge
rattler-build-conda-compat 1.2.2              pyhd8ed1ab_0    conda-forge
readline                  8.2                  h8228510_1    conda-forge
referencing               0.35.1             pyhd8ed1ab_0    conda-forge
reproc                    14.2.4.post0         hd590300_1    conda-forge
reproc-cpp                14.2.4.post0         h59595ed_1    conda-forge
requests                  2.32.3             pyhd8ed1ab_0    conda-forge
requests-oauthlib         2.0.0              pyhd8ed1ab_0    conda-forge
rich                      13.9.4             pyhd8ed1ab_0    conda-forge
ripgrep                   14.1.1               h8fae777_0    conda-forge
rpds-py                   0.20.1          py312h12e396e_0    conda-forge
ruamel.yaml               0.18.6          py312h66e93f0_1    conda-forge
ruamel.yaml.clib          0.2.8           py312h66e93f0_1    conda-forge
scrypt                    0.8.27          py312h2214df5_0    conda-forge
secretstorage             3.3.3           py312h7900ff3_3    conda-forge
setuptools                75.1.0             pyhd8ed1ab_0    conda-forge
shellingham               1.5.4              pyhd8ed1ab_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
smmap                     5.0.0              pyhd8ed1ab_0    conda-forge
sniffio                   1.3.1              pyhd8ed1ab_0    conda-forge
soupsieve                 2.5                pyhd8ed1ab_1    conda-forge
tk                        8.6.13          noxft_h4845f30_101    conda-forge
tomli                     2.0.2              pyhd8ed1ab_0    conda-forge
tomli-w                   1.1.0              pyhd8ed1ab_0    conda-forge
tomlkit                   0.13.2             pyha770c72_0    conda-forge
toolz                     1.0.0              pyhd8ed1ab_0    conda-forge
tqdm                      4.66.5             pyhd8ed1ab_0    conda-forge
trove-classifiers         2024.10.21.16      pyhd8ed1ab_0    conda-forge
truststore                0.9.2              pyhd8ed1ab_0    conda-forge
typer                     0.12.5             pyhd8ed1ab_0    conda-forge
typer-slim                0.12.5             pyhd8ed1ab_0    conda-forge
typer-slim-standard       0.12.5               hd8ed1ab_0    conda-forge
typing-extensions         4.12.2               hd8ed1ab_0    conda-forge
typing_extensions         4.12.2             pyha770c72_0    conda-forge
tzdata                    2024b                hc8b5060_0    conda-forge
urllib3                   2.2.3              pyhd8ed1ab_0    conda-forge
userpath                  1.7.0              pyhd8ed1ab_0    conda-forge
uv                        0.4.29               h0f3a69f_0    conda-forge
virtualenv                20.27.1            pyhd8ed1ab_0    conda-forge
vsts-python-api           0.1.25             pyhd8ed1ab_1    conda-forge
wheel                     0.44.0             pyhd8ed1ab_0    conda-forge
wrapt                     1.16.0          py312h66e93f0_1    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
yaml                      0.2.5                h7f98852_2    conda-forge
yaml-cpp                  0.8.0                h59595ed_0    conda-forge
zipp                      3.20.2             pyhd8ed1ab_0    conda-forge
zstandard                 0.23.0          py312hef9b889_1    conda-forge
zstd                      1.5.6                ha6fb4c9_0    conda-forge

Environment info

     active environment : base
    active env location : /home/mgorny/miniforge3
            shell level : 1
       user config file : /home/mgorny/.condarc
 populated config files : /home/mgorny/miniforge3/.condarc
          conda version : 24.9.2
    conda-build version : 24.9.0
         python version : 3.12.7.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=zen2
                          __conda=24.9.2=0
                          __glibc=2.40=0
                          __linux=6.11.6=0
                          __unix=0=0
       base environment : /home/mgorny/miniforge3  (writable)
      conda av data dir : /home/mgorny/miniforge3/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /home/mgorny/miniforge3/pkgs
                          /home/mgorny/.conda/pkgs
       envs directories : /home/mgorny/miniforge3/envs
                          /home/mgorny/.conda/envs
               platform : linux-64
             user-agent : conda/24.9.2 requests/2.32.3 CPython/3.12.7 Linux/6.11.6-gentoo-dist gentoo/2.16 glibc/2.40 solver/libmamba conda-libmamba-solver/24.9.0 libmambapy/1.5.9
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False
@mgorny mgorny added the bug label Nov 4, 2024
@jaimergp
Copy link
Member

jaimergp commented Nov 6, 2024

I wonder if we should pin git to <2.46 to avoid this error altogether? Or maybe in the gitpython recipe.

Edit: Nah, that'd be too late if the repo has been cloned already. We might need to catch the exception and print some informative error instead, because the user might need to re-clone.

Edit 2: Maybe we can use git update-index --index-version 2 programmatically?

@mgorny
Copy link
Contributor Author

mgorny commented Nov 6, 2024

We also probably need to start thinking of a long-term solution, which probably involves replacing GitPython.

@jaimergp
Copy link
Member

jaimergp commented Nov 6, 2024

Dulwich looks well maintained, nice API, no git dependency! There's also pygit2 but Dulwich seems more popular (see below). Both are available on conda-forge already.

Image

@mgorny
Copy link
Contributor Author

mgorny commented Nov 6, 2024

An argument in favor of pygit2 would be that it's based on libgit2 which is also used by Rust/Cargo.

@jaimergp
Copy link
Member

jaimergp commented Nov 6, 2024

No strong opinions. Note that conda-forge/conda-forge-webservices and conda-forge/admin-migrations seem to also depend on gitpython, in case they need updates too.

mgorny added a commit to mgorny/conda-smithy that referenced this issue Nov 6, 2024
Replace the use of GitPython package with pygit2.  The latter seems
to have better git support, in particular it supports the newer index
versions 3 and 4.  Since it is backed by the libgit2 library that is
also used by Cargo, it seems to have the best chances of being updated
for compatibility with new git versions.

Admittedly, the API feels very low-level.  In particular, it is
necessary to explicitly request writing changes to index back,
and explicitly reread it when it's modified externally (e.g. via another
`pygit2.Repository` instance, as in tests).  On the plus side, it does
not invoke `git` at all -- everything is done by the library.

Fixes conda-forge#2116
mgorny added a commit to mgorny/conda-smithy that referenced this issue Nov 6, 2024
Replace the use of GitPython package with pygit2.  The latter seems
to have better git support, in particular it supports the newer index
versions 3 and 4.  Since it is backed by the libgit2 library that is
also used by Cargo, it seems to have the best chances of being updated
for compatibility with new git versions.

Admittedly, the API feels very low-level.  In particular, it is
necessary to explicitly request writing changes to index back,
and explicitly reread it when it's modified externally (e.g. via another
`pygit2.Repository` instance, as in tests).  On the plus side, it does
not invoke `git` at all -- everything is done by the library.

Fixes conda-forge#2116
mgorny added a commit to mgorny/conda-smithy that referenced this issue Nov 6, 2024
Replace the use of GitPython package with pygit2.  The latter seems
to have better git support, in particular it supports the newer index
versions 3 and 4.  Since it is backed by the libgit2 library that is
also used by Cargo, it seems to have the best chances of being updated
for compatibility with new git versions.

Admittedly, the API feels very low-level.  In particular, it is
necessary to explicitly request writing changes to index back,
and explicitly reread it when it's modified externally (e.g. via another
`pygit2.Repository` instance, as in tests).  On the plus side, it does
not invoke `git` at all -- everything is done by the library.

Fixes conda-forge#2116
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants