|
31 | 31 | import shutil |
32 | 32 | import subprocess |
33 | 33 | import sys |
| 34 | +import tempfile |
34 | 35 | import urllib.parse |
35 | 36 | import warnings |
36 | 37 | from collections.abc import Callable |
|
40 | 41 | from typing import Optional |
41 | 42 | from typing import Union |
42 | 43 |
|
| 44 | +import clonevirtualenv |
43 | 45 | import docstring_parser |
44 | 46 | import yaml |
45 | 47 |
|
@@ -150,7 +152,7 @@ def _affinity(self, other: "Provider"): |
150 | 152 | else: |
151 | 153 | return 0 |
152 | 154 |
|
153 | | - @functools.cache |
| 155 | + @functools.cache # pylint: disable=method-cache-max-size-none |
154 | 156 | def with_extra_dependencies(self, dependencies: Iterable[str]): |
155 | 157 | result = self._with_extra_dependencies(dependencies) |
156 | 158 | if not hasattr(result, 'to_json'): |
@@ -451,7 +453,7 @@ def _affinity(self, other: "Provider"): |
451 | 453 |
|
452 | 454 | def _with_extra_dependencies(self, dependencies: Iterable[str]): |
453 | 455 | return ExternalPythonProvider( |
454 | | - self._urns, None, set(self._packages) + set(dependencies)) |
| 456 | + self._urns, None, set(self._packages).union(set(dependencies))) |
455 | 457 |
|
456 | 458 |
|
457 | 459 | @ExternalProvider.register_provider_type('yaml') |
@@ -642,11 +644,11 @@ def requires_inputs(self, typ, args): |
642 | 644 | return super().requires_inputs(typ, args) |
643 | 645 |
|
644 | 646 | def _with_extra_dependencies(self, dependencies): |
645 | | - external_provider = ExternalPythonProvider( # |
| 647 | + external_provider = ExternalPythonProvider( # disable yapf |
646 | 648 | { |
647 | | - typ: 'apache_beam.yaml.yaml_provider.standard_inline_providers.' |
648 | | - + typ.replace('-', '_') |
649 | | - for typ in self._transform_factories.keys() |
| 649 | + typ: 'apache_beam.yaml.yaml_provider.standard_inline_providers.' + |
| 650 | + typ.replace('-', '_') |
| 651 | + for typ in self._transform_factories.keys() |
650 | 652 | }, |
651 | 653 | '__inline__', |
652 | 654 | dependencies) |
@@ -1120,7 +1122,14 @@ class PypiExpansionService: |
1120 | 1122 | """Expands transforms by fully qualified name in a virtual environment |
1121 | 1123 | with the given dependencies. |
1122 | 1124 | """ |
1123 | | - VENV_CACHE = os.path.expanduser("~/.apache_beam/cache/venvs") |
| 1125 | + if 'TOX_WORK_DIR' in os.environ: |
| 1126 | + VENV_CACHE = tempfile.mkdtemp( |
| 1127 | + prefix='test-venv-cache-', dir=os.environ['TOX_WORK_DIR']) |
| 1128 | + elif 'RUNNER_WORKDIR' in os.environ: |
| 1129 | + VENV_CACHE = tempfile.mkdtemp( |
| 1130 | + prefix='test-venv-cache-', dir=os.environ['RUNNER_WORKDIR']) |
| 1131 | + else: |
| 1132 | + VENV_CACHE = os.path.expanduser("~/.apache_beam/cache/venvs") |
1124 | 1133 |
|
1125 | 1134 | def __init__( |
1126 | 1135 | self, packages: Iterable[str], base_python: str = sys.executable): |
@@ -1182,10 +1191,7 @@ def _create_venv_from_clone( |
1182 | 1191 | if not os.path.exists(venv): |
1183 | 1192 | try: |
1184 | 1193 | clonable_venv = cls._create_venv_to_clone(base_python) |
1185 | | - clonable_python = os.path.join(clonable_venv, 'bin', 'python') |
1186 | | - subprocess.run( |
1187 | | - [clonable_python, '-m', 'clonevirtualenv', clonable_venv, venv], |
1188 | | - check=True) |
| 1194 | + clonevirtualenv.clone_virtualenv(clonable_venv, venv) |
1189 | 1195 | venv_pip = os.path.join(venv, 'bin', 'pip') |
1190 | 1196 | subprocess.run([venv_pip, 'install'] + packages, check=True) |
1191 | 1197 | with open(venv + '-requirements.txt', 'w') as fout: |
@@ -1475,8 +1481,7 @@ def __getattr__(self, name): |
1475 | 1481 | for provider in standard_providers()[typ]: |
1476 | 1482 | if isinstance(provider, InlineProvider): |
1477 | 1483 | return provider._transform_factories[typ] |
1478 | | - else: |
1479 | | - raise ValueError(f"No inline provider found for {name}") |
| 1484 | + raise ValueError(f"No inline provider found for {name}") |
1480 | 1485 |
|
1481 | 1486 |
|
1482 | 1487 | standard_inline_providers = _InlineProviderNamespace() |
0 commit comments