-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BEAM-4032]Support staging binary distributions of dependency packages (
- Loading branch information
1 parent
3ad0552
commit 7975127
Showing
7 changed files
with
299 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
sdks/python/apache_beam/runners/portability/requirements_cache_it_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
"""A pipeline to verify the installation of packages specified in the | ||
requirements.txt. A requirements text is created during runtime with | ||
package specified in _PACKAGE_IN_REQUIREMENTS_FILE. | ||
""" | ||
|
||
import argparse | ||
import logging | ||
import os | ||
import shutil | ||
import tempfile | ||
|
||
import pkg_resources as pkg | ||
|
||
import apache_beam as beam | ||
from apache_beam.options.pipeline_options import PipelineOptions | ||
from apache_beam.options.pipeline_options import SetupOptions | ||
|
||
_PACKAGE_IN_REQUIREMENTS_FILE = ['matplotlib', 'seaborn'] | ||
|
||
|
||
def verify_packages_from_requirements_file_are_installed(unused_element): | ||
_PACKAGE_NOT_IN_REQUIREMENTS_FILE = ['torch'] | ||
packages_to_test = _PACKAGE_IN_REQUIREMENTS_FILE + ( | ||
_PACKAGE_NOT_IN_REQUIREMENTS_FILE) | ||
for package_name in packages_to_test: | ||
try: | ||
output = pkg.get_distribution(package_name) | ||
except pkg.DistributionNotFound as e: # pylint: disable=unused-variable | ||
output = None | ||
if package_name in _PACKAGE_IN_REQUIREMENTS_FILE: | ||
assert output is not None, ('Please check if package %s is specified' | ||
' in requirements file' % package_name) | ||
if package_name in _PACKAGE_NOT_IN_REQUIREMENTS_FILE: | ||
assert output is None | ||
|
||
|
||
def run(argv=None, save_main_session=True): | ||
parser = argparse.ArgumentParser() | ||
_, pipeline_args = parser.parse_known_args(argv) | ||
pipeline_options = PipelineOptions(pipeline_args) | ||
pipeline_options.view_as(SetupOptions).save_main_session = save_main_session | ||
temp_dir = tempfile.mkdtemp() | ||
requirements_text_path = os.path.join(temp_dir, 'requirements.txt') | ||
with open(requirements_text_path, 'w') as f: | ||
f.write('\n'.join(_PACKAGE_IN_REQUIREMENTS_FILE)) | ||
pipeline_options.view_as( | ||
SetupOptions).requirements_file = requirements_text_path | ||
|
||
with beam.Pipeline(options=pipeline_options) as p: | ||
( # pylint: disable=expression-not-assigned | ||
p | ||
| beam.Create([None]) | ||
| beam.Map(verify_packages_from_requirements_file_are_installed)) | ||
shutil.rmtree(temp_dir) | ||
|
||
|
||
if __name__ == '__main__': | ||
logging.getLogger().setLevel(logging.INFO) | ||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.