Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pyopenssl, parametrized, and wheel dependencies #10023

Merged
merged 3 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions 3rdparty/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ mypy==0.780

Markdown==2.1.1
packaging==20.3
parameterized==0.6.1
pathspec==0.8.0
pex==2.1.11
psutil==5.7.0
Pygments==2.6.1
pyopenssl==19.1.0
pystache==0.5.4
python-Levenshtein==0.12.0
pywatchman==1.4.1
Expand Down
1 change: 0 additions & 1 deletion contrib/go/src/python/pants/contrib/go/subsystems/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
python_library(
dependencies=[
'3rdparty/python:requests',
'3rdparty/python:pyopenssl',
'contrib/go/src/python/pants/contrib/go/targets',
'src/python/pants/base:workunit',
'src/python/pants/binaries',
Expand Down
1 change: 0 additions & 1 deletion src/python/pants/goal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ python_library(
':artifact_cache_stats',
':pantsd_stats',
'3rdparty/python:requests',
'3rdparty/python:pyopenssl',
'src/python/pants/auth',
'src/python/pants/base:build_environment',
'src/python/pants/base:run_info',
Expand Down
1 change: 0 additions & 1 deletion src/python/pants/net/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ python_library(
sources = ['**/*.py'],
dependencies = [
'3rdparty/python:requests',
'3rdparty/python:pyopenssl',
'src/python/pants/util:dirutil',
],
tags = {"partially_type_checked"},
Expand Down
1 change: 0 additions & 1 deletion tests/python/pants_test/init/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
python_tests(
dependencies = [
'3rdparty/python:dataclasses',
'3rdparty/python:parameterized',
'3rdparty/python:pex',
'3rdparty/python:setuptools',
'src/python/pants/base:exceptions',
Expand Down
312 changes: 157 additions & 155 deletions tests/python/pants_test/init/test_plugin_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes made to this file beyond converting from unitTest-style to Pytest-style.

import os
import shutil
import unittest
from abc import ABCMeta, abstractmethod
from contextlib import contextmanager
from pathlib import Path
from textwrap import dedent

from parameterized import parameterized
import pytest
from pex.interpreter import PythonInterpreter
from pex.resolver import Unsatisfiable
from pkg_resources import Requirement, WorkingSet
Expand Down Expand Up @@ -57,164 +56,167 @@ def _create_dist(self, runner: SetupPyRunner):

INSTALLERS = [("sdist", SdistInstaller), ("whl", WheelInstaller)]

DEFAULT_VERSION = "0.0.0"

class PluginResolverTest(unittest.TestCase):

DEFAULT_VERSION = "0.0.0"
def create_plugin(distribution_repo_dir, plugin, version=None, packager_cls=None):
distribution_repo_dir = Path(distribution_repo_dir)
source_dir = distribution_repo_dir.joinpath(plugin)
source_dir.mkdir(parents=True)
source_dir.joinpath("setup.py").write_text(
dedent(
f"""
from setuptools import setup

@classmethod
def create_plugin(cls, distribution_repo_dir, plugin, version=None, packager_cls=None):
distribution_repo_dir = Path(distribution_repo_dir)

source_dir = distribution_repo_dir.joinpath(plugin)
source_dir.mkdir(parents=True)
source_dir.joinpath("setup.py").write_text(
dedent(
f"""
from setuptools import setup


setup(name="{plugin}", version="{version or cls.DEFAULT_VERSION}")
"""
)
setup(name="{plugin}", version="{version or DEFAULT_VERSION}")
"""
)
packager_cls = packager_cls or SdistInstaller
packager = packager_cls(source_dir=source_dir, install_dir=distribution_repo_dir)
packager.run()
)
packager_cls = packager_cls or SdistInstaller
packager = packager_cls(source_dir=source_dir, install_dir=distribution_repo_dir)
packager.run()


@contextmanager
def plugin_resolution(*, interpreter=None, chroot=None, plugins=None, packager_cls=None):
@contextmanager
def plugin_resolution(self, *, interpreter=None, chroot=None, plugins=None, packager_cls=None):
@contextmanager
def provide_chroot(existing):
if existing:
yield existing, False
else:
with temporary_dir() as new_chroot:
yield new_chroot, True

with provide_chroot(chroot) as (root_dir, create_artifacts):
env = {}
repo_dir = None
if plugins:
repo_dir = os.path.join(root_dir, "repo")
env.update(
PANTS_PYTHON_REPOS_REPOS=f"[{repo_dir!r}]",
PANTS_PYTHON_REPOS_INDEXES="[]",
PANTS_PYTHON_SETUP_RESOLVER_CACHE_TTL="1",
def provide_chroot(existing):
if existing:
yield existing, False
else:
with temporary_dir() as new_chroot:
yield new_chroot, True

with provide_chroot(chroot) as (root_dir, create_artifacts):
env = {}
repo_dir = None
if plugins:
repo_dir = os.path.join(root_dir, "repo")
env.update(
PANTS_PYTHON_REPOS_REPOS=f"[{repo_dir!r}]",
PANTS_PYTHON_REPOS_INDEXES="[]",
PANTS_PYTHON_SETUP_RESOLVER_CACHE_TTL="1",
)
plugin_list = []
for plugin in plugins:
version = None
if isinstance(plugin, tuple):
plugin, version = plugin
plugin_list.append(f"{plugin}=={version}" if version else plugin)
if create_artifacts:
create_plugin(repo_dir, plugin, version, packager_cls=packager_cls)
env["PANTS_PLUGINS"] = f"[{','.join(map(repr, plugin_list))}]"
env["PANTS_PLUGIN_CACHE_DIR"] = os.path.join(root_dir, "plugin-cache")

configpath = os.path.join(root_dir, "pants.toml")
if create_artifacts:
touch(configpath)
args = [f"--pants-config-files=['{configpath}']"]

options_bootstrapper = OptionsBootstrapper.create(env=env, args=args)
plugin_resolver = PluginResolver(options_bootstrapper, interpreter=interpreter)
cache_dir = plugin_resolver.plugin_cache_dir

working_set = plugin_resolver.resolve(WorkingSet(entries=[]))
for dist in working_set:
assert Path(cache_dir) in Path(dist.location).parents

yield working_set, root_dir, repo_dir, cache_dir


def test_no_plugins():
with plugin_resolution() as (working_set, _, _, _):
assert [] == list(working_set)


@pytest.mark.parametrize("unused_test_name,packager_cls", INSTALLERS)
def test_plugins(unused_test_name, packager_cls):
with plugin_resolution(plugins=[("jake", "1.2.3"), "jane"], packager_cls=packager_cls) as (
working_set,
_,
_,
cache_dir,
):

def assert_dist_version(name, expected_version):
dist = working_set.find(req(name))
assert expected_version == dist.version

assert 2 == len(working_set.entries)

assert_dist_version(name="jake", expected_version="1.2.3")
assert_dist_version(name="jane", expected_version=DEFAULT_VERSION)


@pytest.mark.parametrize("unused_test_name,packager_cls", INSTALLERS)
def test_exact_requirements(unused_test_name, packager_cls):
with plugin_resolution(
plugins=[("jake", "1.2.3"), ("jane", "3.4.5")], packager_cls=packager_cls
) as results:
working_set, chroot, repo_dir, cache_dir = results

# Kill the repo source dir and re-resolve. If the PluginResolver truly detects exact
# requirements it should skip any resolves and load directly from the still in-tact cache.
safe_rmtree(repo_dir)

with plugin_resolution(
chroot=chroot, plugins=[("jake", "1.2.3"), ("jane", "3.4.5")]
) as results2:

working_set2, _, _, _ = results2

assert list(working_set) == list(working_set2)


@pytest.mark.parametrize("unused_test_name,packager_cls", INSTALLERS)
@skip_unless_python36_and_python37_present
def test_exact_requirements_interpreter_change(unused_test_name, packager_cls):
python36 = PythonInterpreter.from_binary(python_interpreter_path(PY_36))
python37 = PythonInterpreter.from_binary(python_interpreter_path(PY_37))

with plugin_resolution(
interpreter=python36,
plugins=[("jake", "1.2.3"), ("jane", "3.4.5")],
packager_cls=packager_cls,
) as results:

working_set, chroot, repo_dir, cache_dir = results

safe_rmtree(repo_dir)
with pytest.raises(Unsatisfiable):
with plugin_resolution(
interpreter=python37, chroot=chroot, plugins=[("jake", "1.2.3"), ("jane", "3.4.5")],
):
pytest.fail(
"Plugin re-resolution is expected for an incompatible interpreter and it is "
"expected to fail since we removed the dist `repo_dir` above."
)
plugin_list = []
for plugin in plugins:
version = None
if isinstance(plugin, tuple):
plugin, version = plugin
plugin_list.append(f"{plugin}=={version}" if version else plugin)
if create_artifacts:
self.create_plugin(repo_dir, plugin, version, packager_cls=packager_cls)
env["PANTS_PLUGINS"] = f"[{','.join(map(repr, plugin_list))}]"
env["PANTS_PLUGIN_CACHE_DIR"] = os.path.join(root_dir, "plugin-cache")

configpath = os.path.join(root_dir, "pants.toml")
if create_artifacts:
touch(configpath)
args = [f"--pants-config-files=['{configpath}']"]

options_bootstrapper = OptionsBootstrapper.create(env=env, args=args)
plugin_resolver = PluginResolver(options_bootstrapper, interpreter=interpreter)
cache_dir = plugin_resolver.plugin_cache_dir

working_set = plugin_resolver.resolve(WorkingSet(entries=[]))
for dist in working_set:
self.assertIn(Path(cache_dir), Path(dist.location).parents)

yield working_set, root_dir, repo_dir, cache_dir

def test_no_plugins(self):
with self.plugin_resolution() as (working_set, _, _, _):
self.assertEqual([], list(working_set))

@parameterized.expand(INSTALLERS)
def test_plugins(self, unused_test_name, packager_cls):
with self.plugin_resolution(
plugins=[("jake", "1.2.3"), "jane"], packager_cls=packager_cls
) as (working_set, _, _, cache_dir):

def assert_dist_version(name, expected_version):
dist = working_set.find(req(name))
self.assertEqual(expected_version, dist.version)

self.assertEqual(2, len(working_set.entries))

assert_dist_version(name="jake", expected_version="1.2.3")
assert_dist_version(name="jane", expected_version=self.DEFAULT_VERSION)

@parameterized.expand(INSTALLERS)
def test_exact_requirements(self, unused_test_name, packager_cls):
with self.plugin_resolution(
plugins=[("jake", "1.2.3"), ("jane", "3.4.5")], packager_cls=packager_cls
) as results:
working_set, chroot, repo_dir, cache_dir = results

# Kill the repo source dir and re-resolve. If the PluginResolver truly detects exact
# requirements it should skip any resolves and load directly from the still in-tact cache.
safe_rmtree(repo_dir)

with self.plugin_resolution(
chroot=chroot, plugins=[("jake", "1.2.3"), ("jane", "3.4.5")]
) as results2:

working_set2, _, _, _ = results2

self.assertEqual(list(working_set), list(working_set2))

@parameterized.expand(INSTALLERS)
@skip_unless_python36_and_python37_present
def test_exact_requirements_interpreter_change(self, unused_test_name, packager_cls):
python36 = PythonInterpreter.from_binary(python_interpreter_path(PY_36))
python37 = PythonInterpreter.from_binary(python_interpreter_path(PY_37))

with self.plugin_resolution(
interpreter=python36,
plugins=[("jake", "1.2.3"), ("jane", "3.4.5")],
packager_cls=packager_cls,
) as results:

working_set, chroot, repo_dir, cache_dir = results

safe_rmtree(repo_dir)
with self.assertRaises(Unsatisfiable):
with self.plugin_resolution(
interpreter=python37,
chroot=chroot,
plugins=[("jake", "1.2.3"), ("jane", "3.4.5")],
):
self.fail(
"Plugin re-resolution is expected for an incompatible interpreter and it is "
"expected to fail since we removed the dist `repo_dir` above."
)

# But for a compatible interpreter the exact resolve results should be re-used and load
# directly from the still in-tact cache.
with self.plugin_resolution(
interpreter=python36, chroot=chroot, plugins=[("jake", "1.2.3"), ("jane", "3.4.5")]
) as results2:

working_set2, _, _, _ = results2
self.assertEqual(list(working_set), list(working_set2))

@parameterized.expand(INSTALLERS)
def test_inexact_requirements(self, unused_test_name, packager_cls):
with self.plugin_resolution(
plugins=[("jake", "1.2.3"), "jane"], packager_cls=packager_cls
) as results:

working_set, chroot, repo_dir, cache_dir = results

# Kill the cache and the repo source dir and wait past our 1s test TTL, if the PluginResolver
# truly detects inexact plugin requirements it should skip perma-caching and fall through to
# a pex resolve and then fail.
safe_rmtree(repo_dir)
safe_rmtree(cache_dir)

with self.assertRaises(Unsatisfiable):
with self.plugin_resolution(chroot=chroot, plugins=[("jake", "1.2.3"), "jane"]):
self.fail("Should not reach here, should raise first.")

# But for a compatible interpreter the exact resolve results should be re-used and load
# directly from the still in-tact cache.
with plugin_resolution(
interpreter=python36, chroot=chroot, plugins=[("jake", "1.2.3"), ("jane", "3.4.5")]
) as results2:

working_set2, _, _, _ = results2
assert list(working_set) == list(working_set2)


@pytest.mark.parametrize("unused_test_name,packager_cls", INSTALLERS)
def test_inexact_requirements(unused_test_name, packager_cls):
with plugin_resolution(
plugins=[("jake", "1.2.3"), "jane"], packager_cls=packager_cls
) as results:

working_set, chroot, repo_dir, cache_dir = results

# Kill the cache and the repo source dir and wait past our 1s test TTL, if the PluginResolver
# truly detects inexact plugin requirements it should skip perma-caching and fall through to
# a pex resolve and then fail.
safe_rmtree(repo_dir)
safe_rmtree(cache_dir)

with pytest.raises(Unsatisfiable):
with plugin_resolution(chroot=chroot, plugins=[("jake", "1.2.3"), "jane"]):
pytest.fail("Should not reach here, should raise first.")
1 change: 0 additions & 1 deletion tests/python/pants_test/net/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
python_tests(
dependencies = [
'3rdparty/python:requests',
'3rdparty/python:pyopenssl',
'src/python/pants/net',
'src/python/pants/util:contextutil',
'src/python/pants/util:dirutil',
Expand Down
3 changes: 1 addition & 2 deletions tests/python/pants_test/reporting/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ python_tests(
name = 'reporting_integration',
sources = ['test_reporting_integration.py'],
dependencies = [
'3rdparty/python:parameterized',
'3rdparty/python:py-zipkin',
'3rdparty/python:psutil',
'src/python/pants/util:contextutil',
'src/python/pants/testutil:int-test',
'examples/src/java/org/pantsbuild/example:hello_directory',
Expand Down
Loading