conda-forge / pycryptodomex-feedstock

A conda-smithy repository for pycryptodomex.
BSD 3-Clause "New" or "Revised" License
1 stars 5 forks source link

Is 0001-Make-load_lib-CONDA_PREFIX-aware.patch still required? #60

Open beenje opened 8 months ago

beenje commented 8 months ago

Trying to use this package without activating the conda env (but using the full python path) raises:

File "/opt/conda/envs/mxcube/lib/python3.10/site-packages/Cryptodome/PublicKey/RSA.py", line 42, in <module>
    from Cryptodome.Math.Numbers import Integer
  File "/opt/conda/envs/mxcube/lib/python3.10/site-packages/Cryptodome/Math/Numbers.py", line 34, in <module>
    from Cryptodome.Math._IntegerGMP import IntegerGMP as Integer
  File "/opt/conda/envs/mxcube/lib/python3.10/site-packages/Cryptodome/Math/_IntegerGMP.py", line 100, in <module>
    lib = load_lib("gmp", gmp_defs)
  File "/opt/conda/envs/mxcube/lib/python3.10/site-packages/Cryptodome/Util/_raw_api.py", line 199, in load_lib
    full_name = os.path.join(os.environ['CONDA_PREFIX'], 'lib', _name)
  File "/opt/conda/envs/mxcube/lib/python3.10/os.py", line 680, in __getitem__
    raise KeyError(key) from None
KeyError: 'CONDA_PREFIX'

I see there is patch to rely on CONDA_PREFIX: https://github.com/conda-forge/pycryptodomex-feedstock/blob/96cc661b787d106b82c42aeb3719a25259997a2b/recipe/0001-Make-load_lib-CONDA_PREFIX-aware.patch#L26

Is this really still required? I don't see any such patch in https://github.com/conda-forge/pycryptodome-feedstock

I think it's better if we don't have to rely on this CONDA variable.

nehaljwani commented 8 months ago

IIRC, it was required to load the dependency on GMP correctly (from the conda ecosystem) rather than the system-wide installed one.

CONDA_PREFIX is set if you activate a conda environment. You might have a valid use case for not doing so.

I wrote the patch three years ago. Python has improved a lot since then. Perhaps the patch is not required anymore or it needs to be fixed to not always assume that that env variable is always available.

fabcor-maxiv commented 1 month ago

CONDA_PREFIX is set if you activate a conda environment. You might have a valid use case for not doing so.

Activating a conda environment is not necessary, so in most cases we in fact don't activate the environment, but call the binaries of this environment directly. For example, calling path/to/conda/env/bin/python works as well as activating the environment and then calling python.