Repository: conda/conda-build

Issue:
--source flag raises AttributeError, no source obtained
Using the `--source` flag with conda-build seems to raise a AttributeError.  This flag seems to have last worked in conda-build version 2.0.10 and the new behavior starts in version 2.0.11.

For example, using the following recipe:

``` yaml
package:
  name: markupsafe
  version: "0.23"

source:
  fn: MarkupSafe-0.23.tar.gz
  url: https://pypi.io/packages/source/M/MarkupSafe/MarkupSafe-0.23.tar.gz

build:
  script: python setup.py install

requirements:
  build:
    - python
    - setuptools
  run:
    - python
```

I get the following when trying to obtain the source:

```
$ conda build -V
conda-build 2.1.1
$ conda build --source .
Traceback (most recent call last):
  File "/home/jhelmus/anaconda/bin/conda-build", line 6, in <module>
    sys.exit(conda_build.cli.main_build.main())
  File "/home/jhelmus/anaconda/lib/python3.5/site-packages/conda_build/cli/main_build.py", line 321, in main
    execute(sys.argv[1:])
  File "/home/jhelmus/anaconda/lib/python3.5/site-packages/conda_build/cli/main_build.py", line 306, in execute
    action(recipe, config)
  File "/home/jhelmus/anaconda/lib/python3.5/site-packages/conda_build/cli/main_build.py", line 246, in source_action
    source.provide(metadata, config=config)
  File "/home/jhelmus/anaconda/lib/python3.5/site-packages/conda_build/source.py", line 495, in provide
    meta = metadata.get_section('source')
AttributeError: 'str' object has no attribute 'get_section'
```

Trying out a few recent versions bring up the following:

```
$ conda build -V
conda-build 2.0.10
$ conda build --source .
Source cache directory is: /home/jhelmus/anaconda/conda-bld/src_cache
Downloading source to cache: MarkupSafe-0.23.tar.gz
Downloading https://pypi.io/packages/source/M/MarkupSafe/MarkupSafe-0.23.tar.gz
Success
Extracting download
Source tree in: /home/jhelmus/anaconda/conda-bld/fake_1484239801666/work/MarkupSafe-0.23



####################################################################################
Source and build intermediates have been left in /home/jhelmus/anaconda/conda-bld.
There are currently 8 accumulated.
To remove them, you can run the ```conda build purge``` command
```

and

```
$ conda build -V
conda-build 2.0.11
$ conda build --source .
Traceback (most recent call last):
  File "/home/jhelmus/anaconda/bin/conda-build", line 6, in <module>
    sys.exit(conda_build.cli.main_build.main())
  File "/home/jhelmus/anaconda/lib/python3.5/site-packages/conda_build/cli/main_build.py", line 244, in main
    execute(sys.argv[1:])
  File "/home/jhelmus/anaconda/lib/python3.5/site-packages/conda_build/cli/main_build.py", line 231, in execute
    action(recipe, config)
  File "/home/jhelmus/anaconda/lib/python3.5/site-packages/conda_build/cli/main_build.py", line 183, in source_action
    source.provide(metadata.path, metadata.get_section('source'), config=config)
AttributeError: 'str' object has no attribute 'path'
```



Discussion:
Thanks for reporting and for tracking down the change.  Will fix soon.

Resolving patch:
diff --git a/conda_build/cli/main_build.py b/conda_build/cli/main_build.py
--- a/conda_build/cli/main_build.py
+++ b/conda_build/cli/main_build.py
@@ -242,7 +242,8 @@ def output_action(recipe, config):
             print(bldpkg_path(metadata))
 
 
-def source_action(metadata, config):
+def source_action(recipe, config):
+    metadata, _, _ = api.render(recipe, config=config)
     source.provide(metadata, config=config)
     print('Source tree in:', config.work_dir)
 


Test patch:
diff --git a/tests/test_cli.py b/tests/test_cli.py
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -141,6 +141,14 @@ def test_build_output_folder(testing_workdir, test_metadata, capfd):
         assert os.path.isfile(os.path.join(out, test_metadata.config.subdir, os.path.basename(output)))
 
 
+def test_build_source(testing_workdir):
+    with TemporaryDirectory() as tmp:
+        args = [os.path.join(metadata_dir, '_pyyaml_find_header'), '--source', '--no-build-id',
+                '--croot', tmp, '--no-activate', '--no-anaconda-upload', ]
+        main_build.execute(args)
+        assert os.path.isfile(os.path.join(tmp, 'work', 'PyYAML-3.11', 'setup.py'))
+
+
 def test_render_output_build_path_set_python(testing_workdir, test_metadata, capfd):
     api.output_yaml(test_metadata, 'meta.yaml')
     # build the other major thing, whatever it is