How to set environment variables for parts?

Trying to get some basic snap bits in place for apache-airflow it looks like I need to set an environment variable at pip install time.

Here are my initial airflow snap bits https://github.com/omnivector-solutions/snap-airflow, and here is the error I’m getting that seems to be forcing me to set an environment variable prior to pip install.

Fetching and installing setuptools...
Collecting setuptools
  Downloading https://files.pythonhosted.org/packages/37/06/754589caf971b0d2d48f151c2586f62902d93dc908e2fd9b9b9f6aa3c9dd/setuptools-40.6.3-py2.py3-none-any.whl (573kB)
    100% |████████████████████████████████| 573kB 13.4MB/s 
  Saved ./parts/apache-airflow/python-packages/setuptools-40.6.3-py2.py3-none-any.whl
Successfully downloaded setuptools
Looking in links: /root/build_airflow/parts/apache-airflow/python-packages
Collecting setuptools
Installing collected packages: setuptools
Successfully installed setuptools-40.6.3
Collecting apache-airflow[all]
  Downloading https://files.pythonhosted.org/packages/02/4c/44af9c88308fc07322c42a19a8b8a692a2ffae9f9100ab46339981621b1e/apache-airflow-1.10.1.tar.gz (4.3MB)
    100% |████████████████████████████████| 4.3MB 5.8MB/s 
  Saved ./parts/apache-airflow/python-packages/apache-airflow-1.10.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-download-f0qrnlpp/apache-airflow/setup.py", line 394, in <module>
        do_setup()
      File "/tmp/pip-download-f0qrnlpp/apache-airflow/setup.py", line 259, in do_setup
        verify_gpl_dependency()
      File "/tmp/pip-download-f0qrnlpp/apache-airflow/setup.py", line 49, in verify_gpl_dependency
        raise RuntimeError("By default one of Airflow's dependencies installs a GPL "
    RuntimeError: By default one of Airflow's dependencies installs a GPL dependency (unidecode). To avoid this dependency set SLUGIFY_USES_TEXT_UNIDECODE=yes in your environment when you install or upgrade Airflow. To force installing the GPL version set AIRFLOW_GPL_UNIDECODE

Any insight on how this might be accomplished using the python plugin would be very helpful.

Thanks!

You can use the build-environment property, however it’s a Snapcraft 3 feature and will require you using the new snapcraft syntax(i.e. with the base keyword, without the remote parts)

Refer https://github.com/snapcore/snapcraft/pull/2322 for more info.

For legacy Snapcraft syntax you have to override the build step and build the part manually, or write a local plugin to replace/complement the python plugin.

2 Likes

I’ve got a few 2x4s beating me in the face here.

Kicking the tires with 3.x, using my airflow bits as a catalyst, I’ve added https://github.com/omnivector-solutions/snap-airflow/blob/master/snap/snapcraft.yaml#L23,L24 and https://github.com/omnivector-solutions/snap-airflow/blob/master/snap/snapcraft.yaml#L7.

Now when I attempt to build my snap I get the following:

$ snapcraft cleanbuild
The cleanbuild command is no longer supported when using the base keyword.
✘-2 ~/allcode/github/omnivector/snap-airflow [master|✚ 2…2] 
10:06 $ snapcraft
You need multipass installed to build snaps which use the base keyword.
Would you like to install it now? [y/N]: y
snapd is not logged in, snap install commands will use sudo
[sudo] password for bdx: 
multipass (beta) 2018.12.1 from Canonical✓ installed
Channel latest/beta for multipass is closed; temporarily forwarding to beta.
Waiting for multipass...
Launching a VM.
launch failed: CPU does not support KVM extensions.                             
An error occurred when trying to launch the instance with 'multipass': returned exit code 2.
Ensure that 'multipass' is setup correctly and try again.

To me, this indicates that I will not be able to build snaps that use bases on my little virtualbox vm anymore, looks like I will require bare metal hosts, or lxd running on bare metal hosts such that snapcraft will be able to spawn a vm. Does this sound correct?

Thanks

You can still run the build in a compatible base version of LXD container by running Snapcraft in the container with the SNAPCRAFT_BUILD_ENVIRONMENT=host environment variable exported.