title: Check if virtual environment is activated and act accordingly in a Makefile
body: <p>I am using Python together with Anaconda and I want to have a rule <code>test</code> in my <code>Makefile</code>. However, I want to assert that when running <code>make test</code>, the right environment will be activated. When a <code>conda</code> environment is activated it defines the environment variable <code>$(CONDA_DEFAULT_ENV)</code>. </p>
  
  <p>First I did:</p>
  
  <pre><code>REPO_NAME = my_repo
  
  define execute_in_env
    source activate $(REPO_NAME); \
    $1
  endef
  
  test:
      $(call execute_in_env, pytest -v --ignore=src/foo)
  </code></pre>
  
  <p>This way, when I executed <code>make test</code> it activated the virtual environment and ran the test inside. Problem is that it is length. I want to check if <code>make</code> is executed from an activated virtual environment. To that end, I modified the code:</p>
  
  <pre><code>.PHONY: test
  REPO_NAME = my_repo
  define execute_in_env =
      $@echo "Checking if in environment"
      ifeq ($(CONDA_DEFAULT_ENV),$(REPO_NAME))
          $1
      else
          source activate $(REPO_NAME); \
          $1
      endif
  endef
  test:
      $(call execute_in_env, pytest -v --ignore=src/rebuydsutils)
  </code></pre>
  
  <p>With this implementation, the testing doesn't happen. I get a </p>
  
  <pre><code>make: Nothing to be done for `test'.
  </code></pre>