git_submodule_helpers.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. from __future__ import absolute_import
  2. import textwrap
  3. def _create_test_package_submodule(env):
  4. env.scratch_path.join("version_pkg_submodule").mkdir()
  5. submodule_path = env.scratch_path / 'version_pkg_submodule'
  6. env.run('touch', 'testfile', cwd=submodule_path)
  7. env.run('git', 'init', cwd=submodule_path)
  8. env.run('git', 'add', '.', cwd=submodule_path)
  9. env.run('git', 'commit', '-q',
  10. '--author', 'pip <pypa-dev@googlegroups.com>',
  11. '-am', 'initial version / submodule', cwd=submodule_path)
  12. return submodule_path
  13. def _change_test_package_submodule(env, submodule_path):
  14. submodule_path.join("testfile").write("this is a changed file")
  15. submodule_path.join("testfile2").write("this is an added file")
  16. env.run('git', 'add', '.', cwd=submodule_path)
  17. env.run('git', 'commit', '-q',
  18. '--author', 'pip <pypa-dev@googlegroups.com>',
  19. '-am', 'submodule change', cwd=submodule_path)
  20. def _pull_in_submodule_changes_to_module(env, module_path):
  21. env.run(
  22. 'git',
  23. 'pull',
  24. '-q',
  25. 'origin',
  26. 'master',
  27. cwd=module_path / 'testpkg/static/',
  28. )
  29. env.run('git', 'commit', '-q',
  30. '--author', 'pip <pypa-dev@googlegroups.com>',
  31. '-am', 'submodule change', cwd=module_path)
  32. def _create_test_package_with_submodule(env):
  33. env.scratch_path.join("version_pkg").mkdir()
  34. version_pkg_path = env.scratch_path / 'version_pkg'
  35. version_pkg_path.join("testpkg").mkdir()
  36. pkg_path = version_pkg_path / 'testpkg'
  37. pkg_path.join("__init__.py").write("# hello there")
  38. pkg_path.join("version_pkg.py").write(textwrap.dedent('''\
  39. def main():
  40. print('0.1')
  41. '''))
  42. version_pkg_path.join("setup.py").write(textwrap.dedent('''\
  43. from setuptools import setup, find_packages
  44. setup(name='version_pkg',
  45. version='0.1',
  46. packages=find_packages(),
  47. )
  48. '''))
  49. env.run('git', 'init', cwd=version_pkg_path, expect_error=True)
  50. env.run('git', 'add', '.', cwd=version_pkg_path, expect_error=True)
  51. env.run('git', 'commit', '-q',
  52. '--author', 'pip <pypa-dev@googlegroups.com>',
  53. '-am', 'initial version', cwd=version_pkg_path,
  54. expect_error=True)
  55. submodule_path = _create_test_package_submodule(env)
  56. env.run(
  57. 'git',
  58. 'submodule',
  59. 'add',
  60. submodule_path,
  61. 'testpkg/static',
  62. cwd=version_pkg_path,
  63. expect_error=True,
  64. )
  65. env.run('git', 'commit', '-q',
  66. '--author', 'pip <pypa-dev@googlegroups.com>',
  67. '-am', 'initial version w submodule', cwd=version_pkg_path,
  68. expect_error=True)
  69. return version_pkg_path, submodule_path