|
1 | 1 | #!/usr/bin/env python
|
2 | 2 | from __future__ import print_function
|
3 | 3 |
|
4 |
| -import os, sys, time, errno, platform, subprocess, glob |
| 4 | +import os, sys, time, errno, platform, subprocess |
5 | 5 | from distutils.core import setup, DistutilsSetupError
|
6 | 6 |
|
7 | 7 | def excepthook(*exc):
|
@@ -641,35 +641,63 @@ def run_cythonize():
|
641 | 641 |
|
642 | 642 |
|
643 | 643 | #########################################################
|
644 |
| -### Clean |
| 644 | +### Install Jupyter kernel spec and clean stale files |
645 | 645 | #########################################################
|
646 | 646 |
|
647 |
| -print('Cleaning up stale installed files....') |
648 |
| -t = time.time() |
649 |
| -from sage_setup.clean import clean_install_dir |
650 |
| -output_dirs = SITE_PACKAGES + glob.glob(os.path.join(build_base, 'lib*')) |
651 |
| -for output_dir in output_dirs: |
652 |
| - print('- cleaning {0}'.format(output_dir)) |
653 |
| - clean_install_dir(output_dir, python_packages, python_modules, |
654 |
| - ext_modules, python_data_files) |
655 |
| -print('Finished cleaning, time: %.2f seconds.' % (time.time() - t)) |
656 |
| - |
657 |
| - |
658 |
| -######################################################### |
659 |
| -### Install also Jupyter kernel spec |
660 |
| -######################################################### |
661 |
| - |
662 |
| -# We cannot just add the installation of the kernel spec to data_files |
663 |
| -# since the file is generated, not copied. |
664 | 647 | class sage_install(install):
|
665 | 648 | def run(self):
|
666 | 649 | install.run(self)
|
667 | 650 | self.install_kernel_spec()
|
| 651 | + log.warn('Cleaning up stale installed files....') |
| 652 | + t = time.time() |
| 653 | + self.clean_stale_files() |
| 654 | + log.warn('Finished cleaning, time: %.2f seconds.' % (time.time() - t)) |
668 | 655 |
|
669 | 656 | def install_kernel_spec(self):
|
| 657 | + """ |
| 658 | + Install the Jupyter kernel spec. |
| 659 | +
|
| 660 | + .. NOTE:: |
| 661 | +
|
| 662 | + The files are generated, not copied. Therefore, we cannot |
| 663 | + use ``data_files`` for this. |
| 664 | + """ |
670 | 665 | from sage.repl.ipython_kernel.install import SageKernelSpec
|
671 | 666 | SageKernelSpec.update()
|
672 | 667 |
|
| 668 | + def clean_stale_files(self): |
| 669 | + """ |
| 670 | + Remove stale installed files. |
| 671 | +
|
| 672 | + This removes files which are built/installed but which do not |
| 673 | + exist in the Sage sources (typically because some source file |
| 674 | + has been deleted). Files are removed from the build directory |
| 675 | + ``build/lib-*`` and from the install directory ``site-packages``. |
| 676 | + """ |
| 677 | + dist = self.distribution |
| 678 | + cmd_build_py = dist.command_obj["build_py"] |
| 679 | + |
| 680 | + # Determine all Python modules inside all packages |
| 681 | + py_modules = [] |
| 682 | + for package in dist.packages: |
| 683 | + package_dir = cmd_build_py.get_package_dir(package) |
| 684 | + py_modules += cmd_build_py.find_package_modules(package, package_dir) |
| 685 | + # modules is a list of triples (package, module, module_file). |
| 686 | + # Construct the complete module name from this. |
| 687 | + py_modules = ["{0}.{1}".format(*m) for m in py_modules] |
| 688 | + |
| 689 | + # Clean install directory (usually, purelib and platlib are the same) |
| 690 | + # and build directory. |
| 691 | + output_dirs = [self.install_purelib, self.install_platlib, self.build_lib] |
| 692 | + from sage_setup.clean import clean_install_dir |
| 693 | + for output_dir in set(output_dirs): |
| 694 | + log.warn('- cleaning {0}'.format(output_dir)) |
| 695 | + clean_install_dir(output_dir, |
| 696 | + dist.packages, |
| 697 | + py_modules, |
| 698 | + dist.ext_modules, |
| 699 | + dist.data_files) |
| 700 | + |
673 | 701 |
|
674 | 702 | #########################################################
|
675 | 703 | ### Distutils
|
|
0 commit comments