OpenStack Orchestration (Heat)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.5 KiB

#!/usr/bin/env python
# Licensed 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
# 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.
"""Generate and install requirements from stub file and source files."""
import argparse
import subprocess
import sys
import pip
parser = argparse.ArgumentParser(description='Sync requirements.')
parser.add_argument('--stub', metavar='STUBFILE',
help="File with requirements stubs.")
parser.add_argument('--source', metavar='SOURCE',
required=True, action='append',
help="Source file to sync requirements from. "
"May be supplied several times.")
parser.add_argument('-t', '--target', metavar='TARGET',
help="Target file to write synced requirements to.")
parser.add_argument('pipopts', metavar='PIP OPTIONS',
help='Options to pass to "pip install".')
args = parser.parse_args()
sources = {}
for requirements_file in args.source:
rqs = pip.req.req_file.parse_requirements(requirements_file,
sources.update({ s for s in rqs})
stubs = list(pip.req.req_file.parse_requirements(args.stub,
reqs = []
for r in stubs:
if in sources:
# safe-guard for future additions to stub file
if r.specifier:
sys.exit("ERROR: package '%(pkg)s' in stub file %(stub)s "
"has version specified but is also present "
"in provided sources requirements. "
"Please remove version from the stub file." % {
'pkg':, 'stub': args.stub})
with open(, 'w') as target:
target.write('\n'.join([str(r.req) for r in reqs]))
pip_install = ['pip', 'install', '-r',]