We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
CPU_COUNT reliability in MacOSX
Hello!
After a talk with @ccordoba12 in [conda-recipes/pr427](https://github.com/conda/conda-recipes/pull/427), it seems that CPU_COUNT is not reliable in MacOSX and he suggests to use "sysctl -n hw.ncpu".

Have you encountered this bug ?
I see that in python3.5, multiprocessing.cpu_count uses os.cpu_count and this builtin command uses also sysctl : posixmodule.c, line 11220:

``` c
#elif defined(__DragonFly__) || \
      defined(__OpenBSD__)   || \
      defined(__FreeBSD__)   || \
      defined(__NetBSD__)    || \
      defined(__APPLE__)
    int mib[2];
    size_t len = sizeof(ncpu);
    mib[0] = CTL_HW;
    mib[1] = HW_NCPU;
    if (sysctl(mib, 2, &ncpu, &len, NULL, 0) != 0)
        ncpu = 0;
```

To fix it, I can create a patch that add an OSX case in in [conda-build/environ.py:109](https://github.com/conda/conda-build/blob/master/conda_build/environ.py#L109) with something like:

``` python
import subprocess
import sys

if sys.platform == 'darwin':
    out, err = subprocess.Popen('sysctl -n hw.ncpu', shell=True, stdout=subprocess.PIPE).communicate()
    d['CPU_COUNT'] = str(out).strip()
```

Do you agree on this approach ?
Thank you very much

CPU_COUNT reliability in MacOSX
Hello!
After a talk with @ccordoba12 in [conda-recipes/pr427](https://github.com/conda/conda-recipes/pull/427), it seems that CPU_COUNT is not reliable in MacOSX and he suggests to use "sysctl -n hw.ncpu".

Have you encountered this bug ?
I see that in python3.5, multiprocessing.cpu_count uses os.cpu_count and this builtin command uses also sysctl : posixmodule.c, line 11220:

``` c
#elif defined(__DragonFly__) || \
      defined(__OpenBSD__)   || \
      defined(__FreeBSD__)   || \
      defined(__NetBSD__)    || \
      defined(__APPLE__)
    int mib[2];
    size_t len = sizeof(ncpu);
    mib[0] = CTL_HW;
    mib[1] = HW_NCPU;
    if (sysctl(mib, 2, &ncpu, &len, NULL, 0) != 0)
        ncpu = 0;
```

To fix it, I can create a patch that add an OSX case in in [conda-build/environ.py:109](https://github.com/conda/conda-build/blob/master/conda_build/environ.py#L109) with something like:

``` python
import subprocess
import sys

if sys.platform == 'darwin':
    out, err = subprocess.Popen('sysctl -n hw.ncpu', shell=True, stdout=subprocess.PIPE).communicate()
    d['CPU_COUNT'] = str(out).strip()
```

Do you agree on this approach ?
Thank you very much


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `conda_build/environ.py`
Content:
```
1 from __future__ import absolute_import, division, print_function
2 
3 import os
4 import sys
5 from os.path import join
6 import subprocess
7 import multiprocessing
8 
9 import conda.config as cc
10 
11 from conda_build.config import config
12 
13 from conda_build import source
14 from conda_build.scripts import prepend_bin_path
15 
16 
17 def get_perl_ver():
18     return str(config.CONDA_PERL)
19 
20 def get_py_ver():
21     return '.'.join(str(config.CONDA_PY))
22 
23 def get_npy_ver():
24     if config.CONDA_NPY:
25         # Convert int -> string, e.g.
26         #   17 -> '1.7'
27         #   110 -> '1.10'
28         conda_npy = str(config.CONDA_NPY)
29         return conda_npy[0] + '.' + conda_npy[1:]
30     return ''
31 
32 def get_stdlib_dir():
33     return join(config.build_prefix, 'Lib' if sys.platform == 'win32' else
34                                 'lib/python%s' % get_py_ver())
35 
36 def get_sp_dir():
37     return join(get_stdlib_dir(), 'site-packages')
38 
39 def get_git_build_info(src_dir):
40     env = os.environ.copy()
41     d = {}
42     git_dir = join(src_dir, '.git')
43     if os.path.exists(git_dir):
44         env['GIT_DIR'] = git_dir
45     else:
46         return d
47 
48     # grab information from describe
49     key_name = lambda a: "GIT_DESCRIBE_{}".format(a)
50     keys = [key_name("TAG"), key_name("NUMBER"), key_name("HASH")]
51     env = {str(key): str(value) for key, value in env.items()}
52     process = subprocess.Popen(["git", "describe", "--tags", "--long", "HEAD"],
53                                stdout=subprocess.PIPE, stderr=subprocess.PIPE,
54                                env=env)
55     output = process.communicate()[0].strip()
56     output = output.decode('utf-8')
57     parts = output.rsplit('-', 2)
58     parts_length = len(parts)
59     if parts_length == 3:
60         d.update(dict(zip(keys, parts)))
61     # get the _full_ hash of the current HEAD
62     process = subprocess.Popen(["git", "rev-parse", "HEAD"],
63                                stdout=subprocess.PIPE, stderr=subprocess.PIPE,
64                                env=env)
65     output = process.communicate()[0].strip()
66     output = output.decode('utf-8')
67     d['GIT_FULL_HASH'] = output
68     # set up the build string
69     if key_name('NUMBER') in d and key_name('HASH') in d:
70         d['GIT_BUILD_STR'] = '{}_{}'.format(d[key_name('NUMBER')],
71                                             d[key_name('HASH')])
72 
73     return d
74 
75 def get_dict(m=None, prefix=None):
76     if not prefix:
77         prefix = config.build_prefix
78 
79     python = config.build_python
80     d = {'CONDA_BUILD': '1', 'PYTHONNOUSERSITE': '1'}
81     d['CONDA_DEFAULT_ENV'] = config.build_prefix
82     d['ARCH'] = str(cc.bits)
83     d['PREFIX'] = prefix
84     d['PYTHON'] = python
85     d['PY3K'] = str(config.PY3K)
86     d['STDLIB_DIR'] = get_stdlib_dir()
87     d['SP_DIR'] = get_sp_dir()
88     d['SYS_PREFIX'] = sys.prefix
89     d['SYS_PYTHON'] = sys.executable
90     d['PERL_VER'] = get_perl_ver()
91     d['PY_VER'] = get_py_ver()
92     if get_npy_ver():
93         d['NPY_VER'] = get_npy_ver()
94     d['SRC_DIR'] = source.get_dir()
95     if "LANG" in os.environ:
96         d['LANG'] = os.environ['LANG']
97     if "HTTPS_PROXY" in os.environ:
98         d['HTTPS_PROXY'] = os.environ['HTTPS_PROXY']
99     if "HTTP_PROXY" in os.environ:
100         d['HTTP_PROXY'] = os.environ['HTTP_PROXY']
101 
102     if m:
103         for var_name in m.get_value('build/script_env', []):
104             value = os.getenv(var_name)
105             if value is None:
106                 value = '<UNDEFINED>'
107             d[var_name] = value
108 
109     try:
110         d['CPU_COUNT'] = str(multiprocessing.cpu_count())
111     except NotImplementedError:
112         d['CPU_COUNT'] = "1"
113 
114     d.update(**get_git_build_info(d['SRC_DIR']))
115     d['PATH'] = dict(os.environ)['PATH']
116     d = prepend_bin_path(d, prefix)
117 
118     if sys.platform == 'win32':         # -------- Windows
119         d['SCRIPTS'] = join(prefix, 'Scripts')
120         d['LIBRARY_PREFIX'] = join(prefix, 'Library')
121         d['LIBRARY_BIN'] = join(d['LIBRARY_PREFIX'], 'bin')
122         d['LIBRARY_INC'] = join(d['LIBRARY_PREFIX'], 'include')
123         d['LIBRARY_LIB'] = join(d['LIBRARY_PREFIX'], 'lib')
124         # This probably should be done more generally
125         d['CYGWIN_PREFIX'] = prefix.replace('\\', '/').replace('C:', '/cygdrive/c')
126 
127         d['R'] = join(prefix, 'Scripts', 'R.exe')
128     else:                               # -------- Unix
129         d['HOME'] = os.getenv('HOME', 'UNKNOWN')
130         d['PKG_CONFIG_PATH'] = join(prefix, 'lib', 'pkgconfig')
131         d['R'] = join(prefix, 'bin', 'R')
132 
133     if sys.platform == 'darwin':         # -------- OSX
134         d['OSX_ARCH'] = 'i386' if cc.bits == 32 else 'x86_64'
135         d['CFLAGS'] = '-arch %(OSX_ARCH)s' % d
136         d['CXXFLAGS'] = d['CFLAGS']
137         d['LDFLAGS'] = d['CFLAGS']
138         d['MACOSX_DEPLOYMENT_TARGET'] = '10.6'
139 
140     elif sys.platform.startswith('linux'):      # -------- Linux
141         d['LD_RUN_PATH'] = prefix + '/lib'
142 
143     if m:
144         d['PKG_NAME'] = m.name()
145         d['PKG_VERSION'] = m.version()
146         d['PKG_BUILDNUM'] = str(m.build_number())
147         d['PKG_BUILD_STRING'] = str(m.build_id())
148         d['RECIPE_DIR'] = m.path
149 
150     return d
151 
152 
153 if __name__ == '__main__':
154     e = get_dict()
155     for k in sorted(e):
156         assert isinstance(e[k], str), k
157         print('%s=%s' % (k, e[k]))
158
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/conda_build/environ.py b/conda_build/environ.py
--- a/conda_build/environ.py
+++ b/conda_build/environ.py
@@ -106,10 +106,16 @@
                 value = '<UNDEFINED>'
             d[var_name] = value
 
-    try:
-        d['CPU_COUNT'] = str(multiprocessing.cpu_count())
-    except NotImplementedError:
-        d['CPU_COUNT'] = "1"
+    if sys.platform == "darwin":
+        # multiprocessing.cpu_count() is not reliable on OSX
+        # See issue #645 on github.com/conda/conda-build
+        out, err = subprocess.Popen('sysctl -n hw.logicalcpu', shell=True, stdout=subprocess.PIPE).communicate()
+        d['CPU_COUNT'] = out.decode('utf-8').strip()
+    else:
+        try:
+            d['CPU_COUNT'] = str(multiprocessing.cpu_count())
+        except NotImplementedError:
+            d['CPU_COUNT'] = "1"
 
     d.update(**get_git_build_info(d['SRC_DIR']))
     d['PATH'] = dict(os.environ)['PATH']

{"golden_diff": "diff --git a/conda_build/environ.py b/conda_build/environ.py\n--- a/conda_build/environ.py\n+++ b/conda_build/environ.py\n@@ -106,10 +106,16 @@\n                 value = '<UNDEFINED>'\n             d[var_name] = value\n \n-    try:\n-        d['CPU_COUNT'] = str(multiprocessing.cpu_count())\n-    except NotImplementedError:\n-        d['CPU_COUNT'] = \"1\"\n+    if sys.platform == \"darwin\":\n+        # multiprocessing.cpu_count() is not reliable on OSX\n+        # See issue #645 on github.com/conda/conda-build\n+        out, err = subprocess.Popen('sysctl -n hw.logicalcpu', shell=True, stdout=subprocess.PIPE).communicate()\n+        d['CPU_COUNT'] = out.decode('utf-8').strip()\n+    else:\n+        try:\n+            d['CPU_COUNT'] = str(multiprocessing.cpu_count())\n+        except NotImplementedError:\n+            d['CPU_COUNT'] = \"1\"\n \n     d.update(**get_git_build_info(d['SRC_DIR']))\n     d['PATH'] = dict(os.environ)['PATH']\n", "issue": "CPU_COUNT reliability in MacOSX\nHello!\nAfter a talk with @ccordoba12 in [conda-recipes/pr427](https://github.com/conda/conda-recipes/pull/427), it seems that CPU_COUNT is not reliable in MacOSX and he suggests to use \"sysctl -n hw.ncpu\".\n\nHave you encountered this bug ?\nI see that in python3.5, multiprocessing.cpu_count uses os.cpu_count and this builtin command uses also sysctl : posixmodule.c, line 11220:\n\n``` c\n#elif defined(__DragonFly__) || \\\n      defined(__OpenBSD__)   || \\\n      defined(__FreeBSD__)   || \\\n      defined(__NetBSD__)    || \\\n      defined(__APPLE__)\n    int mib[2];\n    size_t len = sizeof(ncpu);\n    mib[0] = CTL_HW;\n    mib[1] = HW_NCPU;\n    if (sysctl(mib, 2, &ncpu, &len, NULL, 0) != 0)\n        ncpu = 0;\n```\n\nTo fix it, I can create a patch that add an OSX case in in [conda-build/environ.py:109](https://github.com/conda/conda-build/blob/master/conda_build/environ.py#L109) with something like:\n\n``` python\nimport subprocess\nimport sys\n\nif sys.platform == 'darwin':\n    out, err = subprocess.Popen('sysctl -n hw.ncpu', shell=True, stdout=subprocess.PIPE).communicate()\n    d['CPU_COUNT'] = str(out).strip()\n```\n\nDo you agree on this approach ?\nThank you very much\n\nCPU_COUNT reliability in MacOSX\nHello!\nAfter a talk with @ccordoba12 in [conda-recipes/pr427](https://github.com/conda/conda-recipes/pull/427), it seems that CPU_COUNT is not reliable in MacOSX and he suggests to use \"sysctl -n hw.ncpu\".\n\nHave you encountered this bug ?\nI see that in python3.5, multiprocessing.cpu_count uses os.cpu_count and this builtin command uses also sysctl : posixmodule.c, line 11220:\n\n``` c\n#elif defined(__DragonFly__) || \\\n      defined(__OpenBSD__)   || \\\n      defined(__FreeBSD__)   || \\\n      defined(__NetBSD__)    || \\\n      defined(__APPLE__)\n    int mib[2];\n    size_t len = sizeof(ncpu);\n    mib[0] = CTL_HW;\n    mib[1] = HW_NCPU;\n    if (sysctl(mib, 2, &ncpu, &len, NULL, 0) != 0)\n        ncpu = 0;\n```\n\nTo fix it, I can create a patch that add an OSX case in in [conda-build/environ.py:109](https://github.com/conda/conda-build/blob/master/conda_build/environ.py#L109) with something like:\n\n``` python\nimport subprocess\nimport sys\n\nif sys.platform == 'darwin':\n    out, err = subprocess.Popen('sysctl -n hw.ncpu', shell=True, stdout=subprocess.PIPE).communicate()\n    d['CPU_COUNT'] = str(out).strip()\n```\n\nDo you agree on this approach ?\nThank you very much\n\n", "before_files": [{"content": "from __future__ import absolute_import, division, print_function\n\nimport os\nimport sys\nfrom os.path import join\nimport subprocess\nimport multiprocessing\n\nimport conda.config as cc\n\nfrom conda_build.config import config\n\nfrom conda_build import source\nfrom conda_build.scripts import prepend_bin_path\n\n\ndef get_perl_ver():\n    return str(config.CONDA_PERL)\n\ndef get_py_ver():\n    return '.'.join(str(config.CONDA_PY))\n\ndef get_npy_ver():\n    if config.CONDA_NPY:\n        # Convert int -> string, e.g.\n        #   17 -> '1.7'\n        #   110 -> '1.10'\n        conda_npy = str(config.CONDA_NPY)\n        return conda_npy[0] + '.' + conda_npy[1:]\n    return ''\n\ndef get_stdlib_dir():\n    return join(config.build_prefix, 'Lib' if sys.platform == 'win32' else\n                                'lib/python%s' % get_py_ver())\n\ndef get_sp_dir():\n    return join(get_stdlib_dir(), 'site-packages')\n\ndef get_git_build_info(src_dir):\n    env = os.environ.copy()\n    d = {}\n    git_dir = join(src_dir, '.git')\n    if os.path.exists(git_dir):\n        env['GIT_DIR'] = git_dir\n    else:\n        return d\n\n    # grab information from describe\n    key_name = lambda a: \"GIT_DESCRIBE_{}\".format(a)\n    keys = [key_name(\"TAG\"), key_name(\"NUMBER\"), key_name(\"HASH\")]\n    env = {str(key): str(value) for key, value in env.items()}\n    process = subprocess.Popen([\"git\", \"describe\", \"--tags\", \"--long\", \"HEAD\"],\n                               stdout=subprocess.PIPE, stderr=subprocess.PIPE,\n                               env=env)\n    output = process.communicate()[0].strip()\n    output = output.decode('utf-8')\n    parts = output.rsplit('-', 2)\n    parts_length = len(parts)\n    if parts_length == 3:\n        d.update(dict(zip(keys, parts)))\n    # get the _full_ hash of the current HEAD\n    process = subprocess.Popen([\"git\", \"rev-parse\", \"HEAD\"],\n                               stdout=subprocess.PIPE, stderr=subprocess.PIPE,\n                               env=env)\n    output = process.communicate()[0].strip()\n    output = output.decode('utf-8')\n    d['GIT_FULL_HASH'] = output\n    # set up the build string\n    if key_name('NUMBER') in d and key_name('HASH') in d:\n        d['GIT_BUILD_STR'] = '{}_{}'.format(d[key_name('NUMBER')],\n                                            d[key_name('HASH')])\n\n    return d\n\ndef get_dict(m=None, prefix=None):\n    if not prefix:\n        prefix = config.build_prefix\n\n    python = config.build_python\n    d = {'CONDA_BUILD': '1', 'PYTHONNOUSERSITE': '1'}\n    d['CONDA_DEFAULT_ENV'] = config.build_prefix\n    d['ARCH'] = str(cc.bits)\n    d['PREFIX'] = prefix\n    d['PYTHON'] = python\n    d['PY3K'] = str(config.PY3K)\n    d['STDLIB_DIR'] = get_stdlib_dir()\n    d['SP_DIR'] = get_sp_dir()\n    d['SYS_PREFIX'] = sys.prefix\n    d['SYS_PYTHON'] = sys.executable\n    d['PERL_VER'] = get_perl_ver()\n    d['PY_VER'] = get_py_ver()\n    if get_npy_ver():\n        d['NPY_VER'] = get_npy_ver()\n    d['SRC_DIR'] = source.get_dir()\n    if \"LANG\" in os.environ:\n        d['LANG'] = os.environ['LANG']\n    if \"HTTPS_PROXY\" in os.environ:\n        d['HTTPS_PROXY'] = os.environ['HTTPS_PROXY']\n    if \"HTTP_PROXY\" in os.environ:\n        d['HTTP_PROXY'] = os.environ['HTTP_PROXY']\n\n    if m:\n        for var_name in m.get_value('build/script_env', []):\n            value = os.getenv(var_name)\n            if value is None:\n                value = '<UNDEFINED>'\n            d[var_name] = value\n\n    try:\n        d['CPU_COUNT'] = str(multiprocessing.cpu_count())\n    except NotImplementedError:\n        d['CPU_COUNT'] = \"1\"\n\n    d.update(**get_git_build_info(d['SRC_DIR']))\n    d['PATH'] = dict(os.environ)['PATH']\n    d = prepend_bin_path(d, prefix)\n\n    if sys.platform == 'win32':         # -------- Windows\n        d['SCRIPTS'] = join(prefix, 'Scripts')\n        d['LIBRARY_PREFIX'] = join(prefix, 'Library')\n        d['LIBRARY_BIN'] = join(d['LIBRARY_PREFIX'], 'bin')\n        d['LIBRARY_INC'] = join(d['LIBRARY_PREFIX'], 'include')\n        d['LIBRARY_LIB'] = join(d['LIBRARY_PREFIX'], 'lib')\n        # This probably should be done more generally\n        d['CYGWIN_PREFIX'] = prefix.replace('\\\\', '/').replace('C:', '/cygdrive/c')\n\n        d['R'] = join(prefix, 'Scripts', 'R.exe')\n    else:                               # -------- Unix\n        d['HOME'] = os.getenv('HOME', 'UNKNOWN')\n        d['PKG_CONFIG_PATH'] = join(prefix, 'lib', 'pkgconfig')\n        d['R'] = join(prefix, 'bin', 'R')\n\n    if sys.platform == 'darwin':         # -------- OSX\n        d['OSX_ARCH'] = 'i386' if cc.bits == 32 else 'x86_64'\n        d['CFLAGS'] = '-arch %(OSX_ARCH)s' % d\n        d['CXXFLAGS'] = d['CFLAGS']\n        d['LDFLAGS'] = d['CFLAGS']\n        d['MACOSX_DEPLOYMENT_TARGET'] = '10.6'\n\n    elif sys.platform.startswith('linux'):      # -------- Linux\n        d['LD_RUN_PATH'] = prefix + '/lib'\n\n    if m:\n        d['PKG_NAME'] = m.name()\n        d['PKG_VERSION'] = m.version()\n        d['PKG_BUILDNUM'] = str(m.build_number())\n        d['PKG_BUILD_STRING'] = str(m.build_id())\n        d['RECIPE_DIR'] = m.path\n\n    return d\n\n\nif __name__ == '__main__':\n    e = get_dict()\n    for k in sorted(e):\n        assert isinstance(e[k], str), k\n        print('%s=%s' % (k, e[k]))\n", "path": "conda_build/environ.py"}], "after_files": [{"content": "from __future__ import absolute_import, division, print_function\n\nimport os\nimport sys\nfrom os.path import join\nimport subprocess\nimport multiprocessing\n\nimport conda.config as cc\n\nfrom conda_build.config import config\n\nfrom conda_build import source\nfrom conda_build.scripts import prepend_bin_path\n\n\ndef get_perl_ver():\n    return str(config.CONDA_PERL)\n\ndef get_py_ver():\n    return '.'.join(str(config.CONDA_PY))\n\ndef get_npy_ver():\n    if config.CONDA_NPY:\n        # Convert int -> string, e.g.\n        #   17 -> '1.7'\n        #   110 -> '1.10'\n        conda_npy = str(config.CONDA_NPY)\n        return conda_npy[0] + '.' + conda_npy[1:]\n    return ''\n\ndef get_stdlib_dir():\n    return join(config.build_prefix, 'Lib' if sys.platform == 'win32' else\n                                'lib/python%s' % get_py_ver())\n\ndef get_sp_dir():\n    return join(get_stdlib_dir(), 'site-packages')\n\ndef get_git_build_info(src_dir):\n    env = os.environ.copy()\n    d = {}\n    git_dir = join(src_dir, '.git')\n    if os.path.exists(git_dir):\n        env['GIT_DIR'] = git_dir\n    else:\n        return d\n\n    # grab information from describe\n    key_name = lambda a: \"GIT_DESCRIBE_{}\".format(a)\n    keys = [key_name(\"TAG\"), key_name(\"NUMBER\"), key_name(\"HASH\")]\n    env = {str(key): str(value) for key, value in env.items()}\n    process = subprocess.Popen([\"git\", \"describe\", \"--tags\", \"--long\", \"HEAD\"],\n                               stdout=subprocess.PIPE, stderr=subprocess.PIPE,\n                               env=env)\n    output = process.communicate()[0].strip()\n    output = output.decode('utf-8')\n    parts = output.rsplit('-', 2)\n    parts_length = len(parts)\n    if parts_length == 3:\n        d.update(dict(zip(keys, parts)))\n    # get the _full_ hash of the current HEAD\n    process = subprocess.Popen([\"git\", \"rev-parse\", \"HEAD\"],\n                               stdout=subprocess.PIPE, stderr=subprocess.PIPE,\n                               env=env)\n    output = process.communicate()[0].strip()\n    output = output.decode('utf-8')\n    d['GIT_FULL_HASH'] = output\n    # set up the build string\n    if key_name('NUMBER') in d and key_name('HASH') in d:\n        d['GIT_BUILD_STR'] = '{}_{}'.format(d[key_name('NUMBER')],\n                                            d[key_name('HASH')])\n\n    return d\n\ndef get_dict(m=None, prefix=None):\n    if not prefix:\n        prefix = config.build_prefix\n\n    python = config.build_python\n    d = {'CONDA_BUILD': '1', 'PYTHONNOUSERSITE': '1'}\n    d['CONDA_DEFAULT_ENV'] = config.build_prefix\n    d['ARCH'] = str(cc.bits)\n    d['PREFIX'] = prefix\n    d['PYTHON'] = python\n    d['PY3K'] = str(config.PY3K)\n    d['STDLIB_DIR'] = get_stdlib_dir()\n    d['SP_DIR'] = get_sp_dir()\n    d['SYS_PREFIX'] = sys.prefix\n    d['SYS_PYTHON'] = sys.executable\n    d['PERL_VER'] = get_perl_ver()\n    d['PY_VER'] = get_py_ver()\n    if get_npy_ver():\n        d['NPY_VER'] = get_npy_ver()\n    d['SRC_DIR'] = source.get_dir()\n    if \"LANG\" in os.environ:\n        d['LANG'] = os.environ['LANG']\n    if \"HTTPS_PROXY\" in os.environ:\n        d['HTTPS_PROXY'] = os.environ['HTTPS_PROXY']\n    if \"HTTP_PROXY\" in os.environ:\n        d['HTTP_PROXY'] = os.environ['HTTP_PROXY']\n\n    if m:\n        for var_name in m.get_value('build/script_env', []):\n            value = os.getenv(var_name)\n            if value is None:\n                value = '<UNDEFINED>'\n            d[var_name] = value\n\n    if sys.platform == \"darwin\":\n        # multiprocessing.cpu_count() is not reliable on OSX\n        # See issue #645 on github.com/conda/conda-build\n        out, err = subprocess.Popen('sysctl -n hw.logicalcpu', shell=True, stdout=subprocess.PIPE).communicate()\n        d['CPU_COUNT'] = out.decode('utf-8').strip()\n    else:\n        try:\n            d['CPU_COUNT'] = str(multiprocessing.cpu_count())\n        except NotImplementedError:\n            d['CPU_COUNT'] = \"1\"\n\n    d.update(**get_git_build_info(d['SRC_DIR']))\n    d['PATH'] = dict(os.environ)['PATH']\n    d = prepend_bin_path(d, prefix)\n\n    if sys.platform == 'win32':         # -------- Windows\n        d['SCRIPTS'] = join(prefix, 'Scripts')\n        d['LIBRARY_PREFIX'] = join(prefix, 'Library')\n        d['LIBRARY_BIN'] = join(d['LIBRARY_PREFIX'], 'bin')\n        d['LIBRARY_INC'] = join(d['LIBRARY_PREFIX'], 'include')\n        d['LIBRARY_LIB'] = join(d['LIBRARY_PREFIX'], 'lib')\n        # This probably should be done more generally\n        d['CYGWIN_PREFIX'] = prefix.replace('\\\\', '/').replace('C:', '/cygdrive/c')\n\n        d['R'] = join(prefix, 'Scripts', 'R.exe')\n    else:                               # -------- Unix\n        d['HOME'] = os.getenv('HOME', 'UNKNOWN')\n        d['PKG_CONFIG_PATH'] = join(prefix, 'lib', 'pkgconfig')\n        d['R'] = join(prefix, 'bin', 'R')\n\n    if sys.platform == 'darwin':         # -------- OSX\n        d['OSX_ARCH'] = 'i386' if cc.bits == 32 else 'x86_64'\n        d['CFLAGS'] = '-arch %(OSX_ARCH)s' % d\n        d['CXXFLAGS'] = d['CFLAGS']\n        d['LDFLAGS'] = d['CFLAGS']\n        d['MACOSX_DEPLOYMENT_TARGET'] = '10.6'\n\n    elif sys.platform.startswith('linux'):      # -------- Linux\n        d['LD_RUN_PATH'] = prefix + '/lib'\n\n    if m:\n        d['PKG_NAME'] = m.name()\n        d['PKG_VERSION'] = m.version()\n        d['PKG_BUILDNUM'] = str(m.build_number())\n        d['PKG_BUILD_STRING'] = str(m.build_id())\n        d['RECIPE_DIR'] = m.path\n\n    return d\n\n\nif __name__ == '__main__':\n    e = get_dict()\n    for k in sorted(e):\n        assert isinstance(e[k], str), k\n        print('%s=%s' % (k, e[k]))\n", "path": "conda_build/environ.py"}]}