clean.py 942 B

1234567891011121314151617181920212223242526
  1. import os
  2. import subprocess
  3. here = os.path.abspath(os.path.dirname(__file__))
  4. # Workaround for https://github.com/git-for-windows/git/issues/607
  5. if os.name == 'nt':
  6. for (root, dnames, files) in os.walk(here):
  7. if 'node_modules' in dnames:
  8. subprocess.check_call(['rmdir', '/s', '/q', 'node_modules'],
  9. cwd=root, shell=True)
  10. dnames.remove('node_modules')
  11. subprocess.check_call('python -m pip uninstall -y jupyterlab'.split(), cwd=here)
  12. # get the exclude patterns listed in .cleanignore
  13. with open(os.path.join(here, '.cleanignore')) as f:
  14. git_clean_exclude = [f'--exclude={stripped}'
  15. for stripped in
  16. (line.strip() for line in f)
  17. if stripped and not stripped.startswith('#')]
  18. git_clean_command = ['git', 'clean', '-dfx'] + git_clean_exclude
  19. subprocess.check_call(git_clean_command, cwd=here)