def test_freeze_git_clone(script, tmpdir): """ Test freezing a Git clone. """ # Returns path to a generated package called "version_pkg" pkg_version = _create_test_package(script) result = script.run( 'git', 'clone', pkg_version, 'pip-test-package', expect_stderr=True, ) repo_dir = script.scratch_path / 'pip-test-package' result = script.run( 'python', 'setup.py', 'develop', cwd=repo_dir, expect_stderr=True, ) result = script.pip('freeze', expect_stderr=True) expected = textwrap.dedent( """ ...-e git+...#egg=version_pkg ... """ ).strip() _check_output(result.stdout, expected) result = script.pip( 'freeze', '-f', '%s#egg=pip_test_package' % repo_dir, expect_stderr=True, ) expected = textwrap.dedent( """ -f %(repo)s#egg=pip_test_package... -e git+...#egg=version_pkg ... """ % {'repo': repo_dir}, ).strip() _check_output(result.stdout, expected) # Check that slashes in branch or tag names are translated. # See also issue #1083: https://github.com/pypa/pip/issues/1083 script.run( 'git', 'checkout', '-b', 'branch/name/with/slash', cwd=repo_dir, expect_stderr=True, ) # Create a new commit to ensure that the commit has only one branch # or tag name associated to it (to avoid the non-determinism reported # in issue #1867). script.run('touch', 'newfile', cwd=repo_dir) script.run('git', 'add', 'newfile', cwd=repo_dir) _git_commit(script, repo_dir, message='...') result = script.pip('freeze', expect_stderr=True) expected = textwrap.dedent( """ ...-e ...@...#egg=version_pkg ... """ ).strip() _check_output(result.stdout, expected)
def test_freeze_git_clone(script, tmpdir): """ Test freezing a Git clone. """ # Returns path to a generated package called "version_pkg" pkg_version = _create_test_package(script) result = script.run( 'git', 'clone', pkg_version, 'pip-test-package', expect_stderr=True, ) repo_dir = script.scratch_path / 'pip-test-package' result = script.run( 'python', 'setup.py', 'develop', cwd=repo_dir, expect_stderr=True, ) result = script.pip('freeze', expect_stderr=True) expected = textwrap.dedent( """ ...-e git+...#egg=version_pkg ... """ ).strip() _check_output(result.stdout, expected) result = script.pip( 'freeze', '-f', '{repo_dir}#egg=pip_test_package'.format(**locals()), expect_stderr=True, ) expected = textwrap.dedent( """ -f {repo}#egg=pip_test_package... -e git+...#egg=version_pkg ... """.format(repo=repo_dir), ).strip() _check_output(result.stdout, expected) # Check that slashes in branch or tag names are translated. # See also issue #1083: https://github.com/pypa/pip/issues/1083 script.run( 'git', 'checkout', '-b', 'branch/name/with/slash', cwd=repo_dir, expect_stderr=True, ) # Create a new commit to ensure that the commit has only one branch # or tag name associated to it (to avoid the non-determinism reported # in issue #1867). (repo_dir / 'newfile').touch() script.run('git', 'add', 'newfile', cwd=repo_dir) _git_commit(script, repo_dir, message='...') result = script.pip('freeze', expect_stderr=True) expected = textwrap.dedent( """ ...-e ...@...#egg=version_pkg ... """ ).strip() _check_output(result.stdout, expected)
def _create_test_package_submodule(env): env.scratch_path.joinpath("version_pkg_submodule").mkdir() submodule_path = env.scratch_path / "version_pkg_submodule" env.run("touch", "testfile", cwd=submodule_path) env.run("git", "init", cwd=submodule_path) env.run("git", "add", ".", cwd=submodule_path) _git_commit(env, submodule_path, message="initial version / submodule") return submodule_path
def _pull_in_submodule_changes_to_module(env, module_path, rel_path): """ Args: rel_path: the location of the submodule relative to the superproject. """ submodule_path = module_path / rel_path env.run('git', 'pull', '-q', 'origin', 'master', cwd=submodule_path) # Pass -a to stage the submodule changes that were just pulled in. _git_commit(env, module_path, message='submodule change', args=['-a'])
def _create_test_package_submodule(env): env.scratch_path.joinpath("version_pkg_submodule").mkdir() submodule_path = env.scratch_path / 'version_pkg_submodule' env.run('touch', 'testfile', cwd=submodule_path) env.run('git', 'init', cwd=submodule_path) env.run('git', 'add', '.', cwd=submodule_path) _git_commit(env, submodule_path, message='initial version / submodule') return submodule_path
def _create_test_package_submodule(env): env.scratch_path.join("version_pkg_submodule").mkdir() submodule_path = env.scratch_path / 'version_pkg_submodule' env.run('touch', 'testfile', cwd=submodule_path) env.run('git', 'init', cwd=submodule_path) env.run('git', 'add', '.', cwd=submodule_path) _git_commit(env, submodule_path, message='initial version / submodule') return submodule_path
def _pull_in_submodule_changes_to_module(env, module_path, rel_path): """ Args: rel_path: the location of the submodule relative to the superproject. """ submodule_path = module_path / rel_path env.run("git", "pull", "-q", "origin", "master", cwd=submodule_path) # Pass -a to stage the submodule changes that were just pulled in. _git_commit(env, module_path, message="submodule change", stage_modified=True)
def test_freeze_git_clone(script: PipTestEnvironment) -> None: """ Test freezing a Git clone. """ # Returns path to a generated package called "version_pkg" pkg_version = _create_test_package(script) result = script.run( "git", "clone", pkg_version, "pip-test-package", expect_stderr=True, ) repo_dir = script.scratch_path / "pip-test-package" result = script.run( "python", "setup.py", "develop", cwd=repo_dir, expect_stderr=True, ) result = script.pip("freeze", expect_stderr=True) expected = textwrap.dedent(""" ...-e git+...#egg=version_pkg ... """).strip() _check_output(result.stdout, expected) # Check that slashes in branch or tag names are translated. # See also issue #1083: https://github.com/pypa/pip/issues/1083 script.run( "git", "checkout", "-b", "branch/name/with/slash", cwd=repo_dir, expect_stderr=True, ) # Create a new commit to ensure that the commit has only one branch # or tag name associated to it (to avoid the non-determinism reported # in issue #1867). (repo_dir / "newfile").touch() script.run("git", "add", "newfile", cwd=repo_dir) _git_commit(script, repo_dir, message="...") result = script.pip("freeze", expect_stderr=True) expected = textwrap.dedent(""" ...-e ...@...#egg=version_pkg ... """).strip() _check_output(result.stdout, expected)
def _create_test_package_with_submodule(env: PipTestEnvironment, rel_path: str) -> Tuple[Path, Path]: """ Args: rel_path: the location of the submodule relative to the superproject. """ env.scratch_path.joinpath("version_pkg").mkdir() version_pkg_path = env.scratch_path / "version_pkg" version_pkg_path.joinpath("testpkg").mkdir() pkg_path = version_pkg_path / "testpkg" pkg_path.joinpath("__init__.py").write_text("# hello there") _create_main_file(pkg_path, name="version_pkg", output="0.1") version_pkg_path.joinpath("setup.py").write_text( textwrap.dedent("""\ from setuptools import setup, find_packages setup(name='version_pkg', version='0.1', packages=find_packages(), ) """)) env.run("git", "init", cwd=version_pkg_path) env.run("git", "add", ".", cwd=version_pkg_path) _git_commit(env, version_pkg_path, message="initial version") submodule_path = _create_test_package_submodule(env) env.run( "git", "submodule", "add", submodule_path, rel_path, cwd=version_pkg_path, ) _git_commit(env, version_pkg_path, message="initial version w submodule") return version_pkg_path, submodule_path
def _create_test_package_with_submodule(env, rel_path): """ Args: rel_path: the location of the submodule relative to the superproject. """ env.scratch_path.joinpath("version_pkg").mkdir() version_pkg_path = env.scratch_path / 'version_pkg' version_pkg_path.joinpath("testpkg").mkdir() pkg_path = version_pkg_path / 'testpkg' pkg_path.joinpath("__init__.py").write_text("# hello there") _create_main_file(pkg_path, name="version_pkg", output="0.1") version_pkg_path.joinpath("setup.py").write_text( textwrap.dedent('''\ from setuptools import setup, find_packages setup(name='version_pkg', version='0.1', packages=find_packages(), ) ''')) env.run('git', 'init', cwd=version_pkg_path, expect_error=True) env.run('git', 'add', '.', cwd=version_pkg_path, expect_error=True) _git_commit(env, version_pkg_path, message='initial version') submodule_path = _create_test_package_submodule(env) env.run( 'git', 'submodule', 'add', submodule_path, rel_path, cwd=version_pkg_path, expect_error=True, ) _git_commit(env, version_pkg_path, message='initial version w submodule') return version_pkg_path, submodule_path
def _create_test_package_with_submodule(env, rel_path): """ Args: rel_path: the location of the submodule relative to the superproject. """ env.scratch_path.join("version_pkg").mkdir() version_pkg_path = env.scratch_path / 'version_pkg' version_pkg_path.join("testpkg").mkdir() pkg_path = version_pkg_path / 'testpkg' pkg_path.join("__init__.py").write("# hello there") _create_main_file(pkg_path, name="version_pkg", output="0.1") version_pkg_path.join("setup.py").write(textwrap.dedent('''\ from setuptools import setup, find_packages setup(name='version_pkg', version='0.1', packages=find_packages(), ) ''')) env.run('git', 'init', cwd=version_pkg_path, expect_error=True) env.run('git', 'add', '.', cwd=version_pkg_path, expect_error=True) _git_commit(env, version_pkg_path, message='initial version') submodule_path = _create_test_package_submodule(env) env.run( 'git', 'submodule', 'add', submodule_path, rel_path, cwd=version_pkg_path, expect_error=True, ) _git_commit(env, version_pkg_path, message='initial version w submodule') return version_pkg_path, submodule_path
def do_commit(script, dest): _git_commit(script, dest, message='test commit', args=['--allow-empty']) return get_head_sha(script, dest)
def do_commit(script: PipTestEnvironment, dest: str) -> str: _git_commit(script, dest, message="test commit", allow_empty=True) return get_head_sha(script, dest)
def _change_test_package_submodule(env, submodule_path): submodule_path.joinpath("testfile").write_text("this is a changed file") submodule_path.joinpath("testfile2").write_text("this is an added file") env.run('git', 'add', '.', cwd=submodule_path) _git_commit(env, submodule_path, message='submodule change')
def do_commit(script, dest): _git_commit(script, dest, message='test commit', allow_empty=True) return get_head_sha(script, dest)
def _change_test_package_submodule(env, submodule_path): submodule_path.joinpath("testfile").write_text("this is a changed file") submodule_path.joinpath("testfile2").write_text("this is an added file") env.run("git", "add", ".", cwd=submodule_path) _git_commit(env, submodule_path, message="submodule change")
def _change_test_package_submodule(env, submodule_path): submodule_path.join("testfile").write("this is a changed file") submodule_path.join("testfile2").write("this is an added file") env.run('git', 'add', '.', cwd=submodule_path) _git_commit(env, submodule_path, message='submodule change')