Exemple #1
0
 def venv(self, reason):
     path = self.useFixture(fixtures.TempDir()).path
     virtualenv.create_environment(path, clear=True)
     python = os.path.join(path, 'bin', 'python')
     self.useFixture(
         base.CapturedSubprocess('mkvenv-' + reason, [python] + PIP_CMD +
                                 ['-U', PIPVERSION, 'wheel', PBRVERSION]))
     return path, python
    def test_install_without_pbr(self):
        # Test easy-install of a thing that depends on a thing using pbr
        tempdir = self.useFixture(fixtures.TempDir()).path
        # A directory containing sdists of the things we're going to depend on
        # in using-package.
        dist_dir = os.path.join(tempdir, 'distdir')
        os.mkdir(dist_dir)
        self._run_cmd(sys.executable, ('setup.py', 'sdist', '-d', dist_dir),
                      allow_fail=False,
                      cwd=PBR_ROOT)
        # testpkg - this requires a pbr-using package
        test_pkg_dir = os.path.join(tempdir, 'testpkg')
        os.mkdir(test_pkg_dir)
        pkgs = {
            'pkgTest': {
                'setup.py':
                textwrap.dedent("""\
                    #!/usr/bin/env python
                    import setuptools
                    setuptools.setup(
                        name = 'pkgTest',
                        tests_require = ['pkgReq'],
                        test_suite='pkgReq'
                    )
                """),
                'setup.cfg':
                textwrap.dedent("""\
                    [easy_install]
                    find_links = %s
                """ % dist_dir)
            },
            'pkgReq': {
                'requirements.txt':
                textwrap.dedent("""\
                    pbr
                """),
                'pkgReq/__init__.py':
                textwrap.dedent("""\
                    print("FakeTest loaded and ran")
                """)
            },
        }
        pkg_dirs = self.useFixture(
            test_packaging.CreatePackages(pkgs)).package_dirs
        test_pkg_dir = pkg_dirs['pkgTest']
        req_pkg_dir = pkg_dirs['pkgReq']

        self._run_cmd(sys.executable, ('setup.py', 'sdist', '-d', dist_dir),
                      allow_fail=False,
                      cwd=req_pkg_dir)
        # A venv to test within
        venv = self.useFixture(test_packaging.Venv('nopbr', ['pip', 'wheel']))
        python = venv.python
        # Run the depending script
        self.useFixture(
            base.CapturedSubprocess('nopbr', [python] + ['setup.py', 'test'],
                                    cwd=test_pkg_dir))
Exemple #3
0
 def test_integration(self):
     # Test that we can:
     # - run sdist from the repo in a venv
     # - install the resulting tarball in a new venv
     # - pip install the repo
     # - pip install -e the repo
     # We don't break these into separate tests because we'd need separate
     # source dirs to isolate from side effects of running pip, and the
     # overheads of setup would start to beat the benefits of parallelism.
     self.useFixture(
         base.CapturedSubprocess('sync-req', [
             'python', 'update.py',
             os.path.join(REPODIR, self.short_name)
         ],
                                 cwd=os.path.join(REPODIR, 'requirements')))
     self.useFixture(
         base.CapturedSubprocess(
             'commit-requirements',
             'git diff --quiet || git commit -amrequirements',
             cwd=os.path.join(REPODIR, self.short_name),
             shell=True))
     path = os.path.join(
         self.useFixture(fixtures.TempDir()).path, 'project')
     self.useFixture(
         base.CapturedSubprocess(
             'clone',
             ['git', 'clone',
              os.path.join(REPODIR, self.short_name), path]))
     venv = self.useFixture(Venv('sdist'))
     python = venv.python
     self.useFixture(
         base.CapturedSubprocess('sdist', [python, 'setup.py', 'sdist'],
                                 cwd=path))
     venv = self.useFixture(Venv('tarball'))
     python = venv.python
     filename = os.path.join(path, 'dist',
                             os.listdir(os.path.join(path, 'dist'))[0])
     self.useFixture(
         base.CapturedSubprocess('tarball',
                                 [python] + PIP_CMD + [filename]))
     venv = self.useFixture(Venv('install-git'))
     root = venv.path
     python = venv.python
     self.useFixture(
         base.CapturedSubprocess('install-git', [python] + PIP_CMD +
                                 ['git+file://' + path]))
     if self.short_name == 'nova':
         found = False
         for _, _, filenames in os.walk(root):
             if 'migrate.cfg' in filenames:
                 found = True
         self.assertTrue(found)
     venv = self.useFixture(Venv('install-e'))
     root = venv.path
     python = venv.python
     self.useFixture(
         base.CapturedSubprocess('install-e',
                                 [python] + PIP_CMD + ['-e', path]))
Exemple #4
0
 def _setUp(self):
     path = self.useFixture(fixtures.TempDir()).path
     virtualenv.create_environment(path, clear=True)
     python = os.path.join(path, 'bin', 'python')
     command = [python] + self.pip_cmd + ['-U']
     if self.modules and len(self.modules) > 0:
         command.extend(self.modules)
         self.useFixture(base.CapturedSubprocess(
             'mkvenv-' + self._reason, command))
     self.addCleanup(delattr, self, 'path')
     self.addCleanup(delattr, self, 'python')
     self.path = path
     self.python = python
     return path, python
Exemple #5
0
 def _setUp(self):
     path = self.useFixture(fixtures.TempDir()).path
     virtualenv.create_environment(path, clear=True)
     python = os.path.join(path, 'bin', 'python')
     command = [python] + PIP_CMD + ['-U', PIPVERSION, 'wheel']
     if self._install_pbr:
         command.append(PBRVERSION)
     self.useFixture(
         base.CapturedSubprocess('mkvenv-' + self._reason, command))
     self.addCleanup(delattr, self, 'path')
     self.addCleanup(delattr, self, 'python')
     self.path = path
     self.python = python
     return path, python
Exemple #6
0
 def test_install_without_pbr(self):
     # Test easy-install of a thing that depends on a thing using pbr
     tempdir = self.useFixture(fixtures.TempDir()).path
     # A directory containing sdists of the things we're going to depend on
     # in using-package.
     dist_dir = os.path.join(tempdir, 'distdir')
     os.mkdir(dist_dir)
     self._run_cmd(sys.executable, ('setup.py', 'sdist', '-d', dist_dir),
                   allow_fail=False,
                   cwd=PBR_ROOT)
     # testpkg - this requires a pbr-using package
     test_pkg_dir = os.path.join(tempdir, 'testpkg')
     os.mkdir(test_pkg_dir)
     with open(os.path.join(test_pkg_dir, 'setup.py'), 'wt') as f:
         f.write(
             textwrap.dedent("""\
             #!/usr/bin/env python
             import setuptools
             setuptools.setup(
                 name = 'pkgTest',
                 tests_require = ['pkgReq'],
                 test_suite='pkgReq'
             )
             """))
     with open(os.path.join(test_pkg_dir, 'setup.cfg'), 'wt') as f:
         f.write(
             textwrap.dedent("""\
             [easy_install]
             find_links = %s
             """ % dist_dir))
     repoTest = self.useFixture(TestRepo(test_pkg_dir))
     repoTest.commit()
     # reqpkg - this is a package that requires pbr
     req_pkg_dir = os.path.join(tempdir, 'reqpkg')
     pkg_req_module = os.path.join(req_pkg_dir, 'pkgReq/')
     os.makedirs(pkg_req_module)
     with open(os.path.join(req_pkg_dir, 'setup.py'), 'wt') as f:
         f.write(
             textwrap.dedent("""\
             #!/usr/bin/env python
             import setuptools
             setuptools.setup(
                 setup_requires=['pbr'],
                 pbr=True
             )
             """))
     with open(os.path.join(req_pkg_dir, 'setup.cfg'), 'wt') as f:
         f.write(
             textwrap.dedent("""\
             [metadata]
             name = pkgReq
             """))
     with open(os.path.join(req_pkg_dir, 'requirements.txt'), 'wt') as f:
         f.write(
             textwrap.dedent("""\
             pbr
             """))
     with open(os.path.join(req_pkg_dir, 'pkgReq/__init__.py'), 'wt') as f:
         f.write(
             textwrap.dedent("""\
             print("FakeTest loaded and ran")
             """))
     repoReq = self.useFixture(TestRepo(req_pkg_dir))
     repoReq.commit()
     self._run_cmd(sys.executable, ('setup.py', 'sdist', '-d', dist_dir),
                   allow_fail=False,
                   cwd=req_pkg_dir)
     # A venv to test within
     venv = self.useFixture(Venv('nopbr', install_pbr=False))
     python = venv.python
     # Run the depending script
     self.useFixture(
         base.CapturedSubprocess('nopbr', [python] + ['setup.py', 'test'],
                                 cwd=test_pkg_dir))
    def test_integration(self):
        # Test that we can:
        # - run sdist from the repo in a venv
        # - install the resulting tarball in a new venv
        # - pip install the repo
        # - pip install -e the repo
        # We don't break these into separate tests because we'd need separate
        # source dirs to isolate from side effects of running pip, and the
        # overheads of setup would start to beat the benefits of parallelism.
        path = os.path.join(REPODIR, self.short_name)
        setup_cfg = os.path.join(path, 'setup.cfg')
        project_name = pkg_resources.safe_name(self.short_name).lower()
        # These projects should all have setup.cfg files but we'll be careful
        if os.path.exists(setup_cfg):
            config = configparser.ConfigParser()
            config.read(setup_cfg)
            if config.has_section('metadata'):
                raw_name = config.get('metadata',
                                      'name',
                                      fallback='notapackagename')
                # Technically we should really only need to use the raw
                # name because all our projects should be good and use
                # normalized names but they don't...
                project_name = pkg_resources.safe_name(raw_name).lower()
        constraints = os.path.join(REPODIR, 'requirements',
                                   'upper-constraints.txt')
        tmp_constraints = os.path.join(
            self.useFixture(fixtures.TempDir()).path, 'upper-constraints.txt')
        # We need to filter out the package we are installing to avoid
        # conflicts with the constraints.
        with open(constraints, 'r') as src:
            with open(tmp_constraints, 'w') as dest:
                for line in src:
                    constraint = line.split('===')[0]
                    if project_name != constraint:
                        dest.write(line)
        pip_cmd = PIP_CMD + ['-c', tmp_constraints]

        venv = self.useFixture(
            test_packaging.Venv('sdist',
                                modules=['pip', 'wheel', PBRVERSION],
                                pip_cmd=PIP_CMD))
        python = venv.python
        self.useFixture(
            base.CapturedSubprocess('sdist', [python, 'setup.py', 'sdist'],
                                    cwd=path))
        venv = self.useFixture(
            test_packaging.Venv('tarball',
                                modules=['pip', 'wheel', PBRVERSION],
                                pip_cmd=PIP_CMD))
        python = venv.python
        filename = os.path.join(path, 'dist',
                                os.listdir(os.path.join(path, 'dist'))[0])
        self.useFixture(
            base.CapturedSubprocess('tarball',
                                    [python] + pip_cmd + [filename]))
        venv = self.useFixture(
            test_packaging.Venv('install-git',
                                modules=['pip', 'wheel', PBRVERSION],
                                pip_cmd=PIP_CMD))
        root = venv.path
        python = venv.python
        self.useFixture(
            base.CapturedSubprocess('install-git', [python] + pip_cmd +
                                    ['git+file://' + path]))
        if self.short_name == 'nova':
            found = False
            for _, _, filenames in os.walk(root):
                if 'migrate.cfg' in filenames:
                    found = True
            self.assertTrue(found)
        venv = self.useFixture(
            test_packaging.Venv('install-e',
                                modules=['pip', 'wheel', PBRVERSION],
                                pip_cmd=PIP_CMD))
        root = venv.path
        python = venv.python
        self.useFixture(
            base.CapturedSubprocess('install-e',
                                    [python] + pip_cmd + ['-e', path]))