Pull step environment variables

Is there a way to set environment variables for the pull step? I can’t find an answer to this question and the existing environment variable options don’t seem to be used in the pull step.

Interesting. Can you share your use case @brando?

Without knowing exactly what you need, you may be able to use override-pull, e.g.

  override-pull: |
    export FOO=BAR
    snapcraftctl pull

Hi Chris,

I’ve tried doing what you suggested by overriding with a pull script but the environment variable exported there does not seem to persist. I think I read somewhere that when you call snapcraftctl pull it runs exactly the same process as it would otherwise which I assume includes some environment variable clearing.

I’ve also tried using the top level (snapcraft.yml) environment property but those don’t seem to work in the pull step either.

The issue that I’m trying to resolve is suppressing warning messages emitted by the catkin plugin by using the ROS_PYTHON_VERSION environment variable to tell it that I want to use python 2. I checked the source code and confirmed that the plugin seems to be emitting the warnings in the pull step (https://github.com/snapcore/snapcraft/blob/739c65fe791287f84222b89e1d0835e5fcd5508e/snapcraft/plugins/v1/catkin.py#L514). From looking at the code I couldn’t figure out a way to trick it to accept the variable I wanted to set. It seems like there would be other cases where utilities that get run in the pull step could be configured with environment variables. Would it be difficult to implement a pull-environment property for parts similar to build-environment? I didn’t check the code for that yet.

Last I checked, it’s actually impossible to change the pull environment that way because snapcraftctl pull just talks back to the running (i.e. already-established, including its environment) process.

I didn’t realize rosdep would start yelling about not having that variable defined (this warning is not coming from snapcraft). Each ROS distro defines the python version it uses, after all! It wouldn’t be hard to add it to the plugin, though; that’s probably the best way to resolve this. The colcon plugin can set it to 3 unconditionally, but the catkin plugin will need to set it to 2 for anything before Noetic, and to 3 for Noetic.