Repository: conda-forge/conda-smithy

Issue:
AttributeError: module 'conda_build.metadata' has no attribute 'cc'
@pmlandwehr commented on [Thu Aug 18 2016](https://github.com/conda-forge/conda-smithy-feedstock/issues/34)

My _assumption_ is that this break is caused by using the just-released latest-and-greatest `conda-build` (`1.21.12`, with `python==3.5`)

Running it on a fork of the `requests-futures-feedstock`, I get:

``` bash
$ conda smithy regenerate
Traceback (most recent call last):
  File "/opt/anaconda3/bin/conda-smithy", line 9, in <module>
    load_entry_point('conda-smithy==1.0.3', 'console_scripts', 'conda-smithy')()
  File "/opt/anaconda3/lib/python3.5/site-packages/conda_smithy/cli.py", line 236, in main
    args.subcommand_func(args)
  File "/opt/anaconda3/lib/python3.5/site-packages/conda_smithy/cli.py", line 185, in __call__
    configure_feedstock.main(args.feedstock_directory)
  File "/opt/anaconda3/lib/python3.5/site-packages/conda_smithy/configure_feedstock.py", line 361, in main
    render_run_docker_build(env, config, forge_dir)
  File "/opt/anaconda3/lib/python3.5/site-packages/conda_smithy/configure_feedstock.py", line 24, in render_run_docker_build
    with fudge_subdir('linux-64'):
  File "/opt/anaconda3/lib/python3.5/contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "/opt/anaconda3/lib/python3.5/site-packages/conda_smithy/configure_feedstock.py", line 103, in fudge_subdir
    orig = conda_build.metadata.cc.subdir
AttributeError: module 'conda_build.metadata' has no attribute 'cc'
```

---

@jakirkham commented on [Thu Aug 18 2016](https://github.com/conda-forge/conda-smithy-feedstock/issues/34#issuecomment-240877787)

Thanks for raising this issue, @pmlandwehr. Can confirm seeing this as well myself. See issue ( https://github.com/conda-forge/status/issues/3 ) for a description of another occurrence of this issue, build logs showing the problem, and what was done to fix it. Have found that downgrading to `conda-build` version `1.21.11` seems to be a sufficient workaround for the meantime.

FYI this repo is the feedstock used to generate `conda-smithy` releases. As this isn't an issue generating the package itself, but an issue with `conda-smithy` (I think), I'm going to move this over to the [`conda-smithy` repo](https://github.com/conda-forge/conda-smithy). Thanks again for bring this to our attention.



Discussion:
cc @jschueller

cc @msarahan

So, I tried to handle the compatibility issue with commit ( https://github.com/conda-forge/conda-smithy/commit/293bddbc80e9d1dd7169e19f45e91cdecf183b1e ). However, this doesn't actually work. The point of that function is to trick `conda-build` into thinking we are on a different OS than we are. However, handling it this way doesn't seem to work. Maybe the 3 of us are going to have to put our heads together on this one and see what we can drum up.

cc @pelson @msarahan

You can change the import to conda_build.conda_interface.cc for conda-build 1.21.12+, but this is pretty horrible.  To be clear, what you are doing here is importing conda's config through conda-build.  Surely there is a better way?  Ideally conda will provide some kind of API eventually.  I have discussed an intermediate step with @kalefranz that would isolate "legacy exports" and freeze an interface to them, with the intent of deprecating this when a proper API is available.  For now, you should emulate/copy (part of) the conda_interface file from conda_build.conda_interface.  Use conda-build as your interface layer if it makes sense, but I'm not sure it makes sense here.

Please raise an issue on the conda issue tracker stating what you need access to, so that @kalefranz can factor that into any thoughts/development on a conda API (or frozen interface of some sort, as intermediary).

> You can change the import to conda_build.conda_interface.cc for conda-build 1.21.12+, but this is pretty horrible.

I just tried that too, but it also doesn't appear to work. ( https://github.com/conda-forge/conda-smithy/commit/b5a52b761271e768e3207eac78ac9d3bd42263fa )

To be clear on what not work means, it doesn't crash like before, but it does re-render things incorrectly. For instance, re-rendering `pyelftools` on my Mac, which should build on Linux only, results in changes to CircleCI that would cause it to be skipped. This incorrect re-rendering only occurs with `conda-build >=1.21.12`.

In other words, we are no longer able to masquerade as one platform (e.g. Linux) when using another (e.g. Mac). This is a pretty serious problem for `conda-smithy`. So we need to brainstorm how we are going to fix this.

> To be clear, what you are doing here is importing conda's config through conda-build. Surely there is a better way?

Can't really say. This code isn't actually mine. See PR ( https://github.com/conda-forge/conda-smithy/pull/86 ) for where this came from.

`conda-smithy` really relies heavily on having a way to "convince" `conda`/`conda-build` that the platform is different from what one would naively assume. This seems to be what @pelson came up with.

To be honest, I'm not sure any other way we would do it still wouldn't be some horrible hack. Though this would be a good thing to keep in mind for the `conda-build` (and potentially `conda`) Python API(s) if it is not already handled somehow.

> Please raise an issue on the conda issue tracker stating what you need access to, so that @kalefranz can factor that into any thoughts/development on a conda API (or frozen interface of some sort, as intermediary).

I'll let @pelson do that as he has a clear idea of what he wants. I'm just here to plug my finger in the dam and yell for help. 😄

Replying here as well as on that commit:

Could you accomplish this with some kind of monkeypatching with mock? https://docs.python.org/3/library/unittest.mock.html#unittest.mock.patch

I am looking into this now, and will post back if/when I find a solution.


Resolving patch:
diff --git a/conda_smithy/configure_feedstock.py b/conda_smithy/configure_feedstock.py
--- a/conda_smithy/configure_feedstock.py
+++ b/conda_smithy/configure_feedstock.py
@@ -9,14 +9,11 @@
 import warnings
 
 import conda.api
-from conda.resolve import MatchSpec
-import conda_build.metadata
 from conda_build.metadata import MetaData
 from conda_build_all.version_matrix import special_case_version_matrix, filter_cases
 from conda_build_all.resolved_distribution import ResolvedDistribution
 from jinja2 import Environment, FileSystemLoader
 
-
 conda_forge_content = os.path.abspath(os.path.dirname(__file__))
 
 
@@ -100,12 +97,20 @@ def render_circle(jinja_env, forge_config, forge_dir):
     with open(target_fname, 'w') as fh:
         fh.write(template.render(**forge_config))
 
+
 @contextmanager
 def fudge_subdir(subdir):
-    orig = conda_build.metadata.cc.subdir
-    conda_build.metadata.cc.subdir = subdir
+    # conda build <1.21.12 (no conda 4.2+)
+    try:
+        import conda_build.metadata
+        cc = conda_build.metadata.cc
+    # conda build 1.21.12+ (supports conda 4.2+)
+    except AttributeError:
+        import conda_build.metadata as cc
+    orig = cc.subdir
+    cc.subdir = subdir
     yield
-    conda_build.metadata.cc.subdir = orig
+    cc.subdir = orig
 
 
 def render_travis(jinja_env, forge_config, forge_dir):


Test patch: