Repository: conda/conda-build

Issue:
CB 3.5.0 Error building on Windows
<!--
Thanks for opening an issue! A few things to keep in mind:

- This issue tracker is for issues with or enhancements for conda-build.

For conda issues, you should open an issue at https://github.com/conda/conda/issues
For Anaconda issues, you should open an issue at https://github.com/ContinuumIO/anaconda-issues/issues
For an issue with a particular conda-forge package, you should open an issue on the 
corresponding feedstock: https://github.com/conda-forge
-->

### Actual Behavior

<!-- What actually happens? -->
```
(base) C:\ci\pymc3_1519190526629\work>set "SRC_DIR=C:\ci\pymc3_1519190526629\work" 
Traceback (most recent call last):
  File "C:\ci\containers\00000bhtonk\tmp\build\80754af9\mc\Scripts\conda-build-script.py", line 10, in <module>
    sys.exit(main())
  File "C:\ci\containers\00000bhtonk\tmp\build\80754af9\mc\lib\site-packages\conda_build\cli\main_build.py", line 415, in main
    execute(sys.argv[1:])
  File "C:\ci\containers\00000bhtonk\tmp\build\80754af9\mc\lib\site-packages\conda_build\cli\main_build.py", line 406, in execute
    verify=args.verify)
  File "C:\ci\containers\00000bhtonk\tmp\build\80754af9\mc\lib\site-packages\conda_build\api.py", line 199, in build
    notest=notest, need_source_download=need_source_download, variants=variants)
  File "C:\ci\containers\00000bhtonk\tmp\build\80754af9\mc\lib\site-packages\conda_build\build.py", line 2023, in build_tree
    notest=notest,
  File "C:\ci\containers\00000bhtonk\tmp\build\80754af9\mc\lib\site-packages\conda_build\build.py", line 1266, in build
    windows.build(m, build_file)
  File "C:\ci\containers\00000bhtonk\tmp\build\80754af9\mc\lib\site-packages\conda_build\windows.py", line 273, in build
    check_call_env(cmd, cwd=src_dir)
  File "C:\ci\containers\00000bhtonk\tmp\build\80754af9\mc\lib\site-packages\conda_build\utils.py", line 249, in check_call_env
    return _func_defaulting_env_to_os_environ('call', *popenargs, **kwargs)
  File "C:\ci\containers\00000bhtonk\tmp\build\80754af9\mc\lib\site-packages\conda_build\utils.py", line 228, in _func_defaulting_env_to_os_environ
    proc = PopenWrapper(_args, **kwargs)
  File "C:\ci\containers\00000bhtonk\tmp\build\80754af9\mc\lib\site-packages\conda_build\utils.py", line 126, in __init__
    self.out, self.err = self._execute(*args, **kwargs)
  File "C:\ci\containers\00000bhtonk\tmp\build\80754af9\mc\lib\site-packages\conda_build\utils.py", line 178, in _execute
    self.disk = max(directory_size(disk_usage_dir), self.disk)
  File "C:\ci\containers\00000bhtonk\tmp\build\80754af9\mc\lib\site-packages\conda_build\utils.py", line 96, in directory_size
    if path.is_file():
OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\\ci\\pymc3_1519190526629\\work\\notebooks'
```
### Expected Behavior

Don't error out :stuck_out_tongue_winking_eye: 
<!-- What do you think should happen? -->

### Steps to Reproduce

<!-- Steps to reproduce issue. -->

Try building pymc3 on windows using Conda Build 3.5




Discussion:

Resolving patch:
diff --git a/conda_build/convert.py b/conda_build/convert.py
--- a/conda_build/convert.py
+++ b/conda_build/convert.py
@@ -18,7 +18,7 @@
 import tarfile
 import tempfile
 
-from conda_build.utils import filter_info_files
+from conda_build.utils import filter_info_files, walk
 
 
 def retrieve_c_extensions(file_path, show_imports=False):
@@ -522,7 +522,7 @@ def update_files_file(temp_dir, verbose):
 
     with open(files_file, 'w') as files:
         file_paths = []
-        for dirpath, dirnames, filenames in os.walk(temp_dir):
+        for dirpath, dirnames, filenames in walk(temp_dir):
             relative_dir = os.path.relpath(dirpath, temp_dir)
             filenames = [os.path.join(relative_dir, f) for f in filenames]
             for filename in filter_info_files(filenames, ''):
@@ -552,7 +552,7 @@ def create_target_archive(file_path, temp_dir, platform, output_dir):
     destination = os.path.join(output_directory, os.path.basename(file_path))
 
     with tarfile.open(destination, 'w:bz2') as target:
-        for dirpath, dirnames, filenames in os.walk(temp_dir):
+        for dirpath, dirnames, filenames in walk(temp_dir):
             relative_dir = os.path.relpath(dirpath, temp_dir)
             filenames = [os.path.join(relative_dir, f) for f in filenames]
             for filename in filenames:
diff --git a/conda_build/environ.py b/conda_build/environ.py
--- a/conda_build/environ.py
+++ b/conda_build/environ.py
@@ -619,7 +619,7 @@ def _load_all_json(path):
     Load all json files in a directory.  Return dictionary with filenames mapped to json
     dictionaries.
     """
-    root, _, files = next(os.walk(path))
+    root, _, files = next(utils.walk(path))
     result = {}
     for f in files:
         if f.endswith('.json'):
diff --git a/conda_build/utils.py b/conda_build/utils.py
--- a/conda_build/utils.py
+++ b/conda_build/utils.py
@@ -48,14 +48,12 @@
     # NOQA because it is not used in this file.
     from contextlib import ExitStack  # NOQA
     PermissionError = PermissionError  # NOQA
-    scandir = os.scandir
 else:
     import urlparse
     import urllib
     # NOQA because it is not used in this file.
     from contextlib2 import ExitStack  # NOQA
     PermissionError = OSError
-    from scandir import scandir
 
 
 on_win = (sys.platform == 'win32')
@@ -80,6 +78,11 @@
     sys.exit(%(func)s())
 """
 
+try:
+    from os import scandir, walk  # NOQA
+except ImportError:
+    from scandir import walk
+
 
 @memoized
 def stat_file(path):
@@ -92,10 +95,10 @@ def directory_size(path):
     total_size = 0
     seen = set()
 
-    for path in scandir(path):
-        if path.is_file():
+    for root, _, files in walk(path):
+        for f in files:
             try:
-                stat = stat_file(path.path)
+                stat = stat_file(os.path.join(root, f))
             except OSError:
                 continue
 
@@ -691,7 +694,7 @@ def safe_print_unicode(*args, **kwargs):
 
 def rec_glob(path, patterns):
     result = []
-    for d_f in os.walk(path):
+    for d_f in walk(path):
         # ignore the .git folder
         # if '.git' in d_f[0]:
         #     continue
@@ -843,7 +846,7 @@ def create_entry_points(items, config):
 
 # Return all files in dir, and all its subdirectories, ending in pattern
 def get_ext_files(start_path, pattern):
-    for root, _, files in os.walk(start_path):
+    for root, _, files in walk(start_path):
         for f in files:
             if f.endswith(pattern):
                 yield os.path.join(root, f)
@@ -927,7 +930,7 @@ def expand_globs(path_list, root_dir):
         elif os.path.islink(path):
             files.append(path)
         elif os.path.isdir(path):
-            files.extend(os.path.join(root, f) for root, _, fs in os.walk(path) for f in fs)
+            files.extend(os.path.join(root, f) for root, _, fs in walk(path) for f in fs)
         else:
             # File compared to the globs use / as separator indenpendently of the os
             glob_files = glob(path)
@@ -1357,7 +1360,7 @@ def prefix_files(prefix):
     Returns a set of all files in prefix.
     '''
     res = set()
-    for root, dirs, files in os.walk(prefix):
+    for root, dirs, files in walk(prefix):
         for fn in files:
             res.add(join(root, fn)[len(prefix) + 1:])
         for dn in dirs:


Test patch:
diff --git a/tests/test_api_build.py b/tests/test_api_build.py
--- a/tests/test_api_build.py
+++ b/tests/test_api_build.py
@@ -30,7 +30,8 @@
 from conda_build.build import VersionOrder
 from conda_build.render import finalize_metadata
 from conda_build.utils import (copy_into, on_win, check_call_env, convert_path_for_cygwin_or_msys2,
-                               package_has_file, check_output_env, get_conda_operation_locks, rm_rf)
+                               package_has_file, check_output_env, get_conda_operation_locks, rm_rf,
+                               walk)
 from conda_build.os_utils.external import find_executable
 from conda_build.exceptions import DependencyNeedsBuildingError
 
@@ -1136,7 +1137,7 @@ def test_source_cache_build(testing_workdir):
     git_cache_directory = '{}/git_cache' .format(testing_workdir)
     assert os.path.isdir(git_cache_directory)
 
-    files = [filename for _, _, filenames in os.walk(git_cache_directory)
+    files = [filename for _, _, filenames in walk(git_cache_directory)
              for filename in filenames]
 
     assert len(files) > 0