Kirill Simonov avatar Kirill Simonov committed 8303a10

setup.py: run `download_vendor` from `egg_info`.

Comments (0)

Files changed (3)

 
 
 from setuptools import setup, find_packages
-from setuptools.command.develop import develop as setuptools_develop
-from distutils.command.build import build as setuptools_build
+from setuptools.command.egg_info import egg_info as setuptools_egg_info
 from distutils.cmd import Command
 from distutils.dir_util import remove_tree
 from distutils import log
     ]
 
 
-class build_vendor(Command):
+class download_vendor(Command):
     # Download vendor packages.
 
     user_options = []
         pass
 
     def run(self):
-        build_cmd = self.get_finalized_command('build')
+        info_cmd = self.get_finalized_command('egg_info')
         for url, md5_hash, target in get_vendors():
             if os.path.exists(target):
                 continue
             data = stream.read()
             stream.close()
             assert hashlib.md5(data).hexdigest() == md5_hash
-            build_dir = os.path.join(build_cmd.build_base,
+            build_dir = os.path.join(info_cmd.egg_info,
                                      os.path.basename(target))
             if os.path.exists(build_dir):
                 remove_tree(build_dir)
             os.rename(build_dir, target)
 
 
-class build(setuptools_build):
+class egg_info(setuptools_egg_info):
+    # Make sure `download_vendor` is executed as early as possible.
 
-    sub_commands = [('build_vendor', None)] + setuptools_build.sub_commands
-
-
-class develop(setuptools_develop):
-
-    def install_for_development(self):
-        self.run_command('build_vendor')
-        setuptools_develop.install_for_development(self)
+    def find_sources(self):
+        self.run_command('download_vendor')
+        setuptools_egg_info.find_sources(self)
 
 
 if __name__ == '__main__':
               'htsql.routines': get_routines(),
               'htsql.addons': get_addons()},
           cmdclass={
-              'build_vendor': build_vendor,
-              'build': build,
-              'develop': develop})
+              'download_vendor': download_vendor,
+              'egg_info': egg_info})
 
 
     """
     if os.path.exists("./build"):
         rmtree("./build")
+    if os.path.exists("./dist"):
+        rmtree("./dist")
     for dirpath, dirnames, filenames in os.walk("."):
         for filename in filenames:
             if filename.endswith(".pyc") or filename.endswith(".pyo"):
                 filename = os.path.join(dirpath, filename)
                 rm(filename)
+        for dirname in dirnames:
+            if dirname == "vendor":
+                dirname = os.path.join(dirpath, dirname)
+                rmtree(dirname)
     for filename in ls("./HTSQL-*"):
         if os.path.isdir(filename):
             rmtree(filename)
             mktree("./build/tmp")
             run("hg archive ./build/tmp/htsql")
             if with_doc:
-                setup_py("build_vendor", cd="./build/tmp/htsql")
+                setup_py("-q download_vendor", cd="./build/tmp/htsql")
             for dirname in ls("./build/tmp/htsql/src/*"):
                 if os.path.basename(dirname) not in packages:
                     rmtree(dirname)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.