-
-
Notifications
You must be signed in to change notification settings - Fork 629
Closed
Labels
cliRelated to command line interface thingsRelated to command line interface thingsfeatureRequest for a new featureRequest for a new feature
Description
What's the problem this feature will solve?
There are 2 projects:
lib
is an internal library. It hassetup.py
with dependencies of the library.srv
is an internal service that useslib
. It has a lock filerequirements.txt
.
The goal is to generate lib/requirements.txt
which has only packages from lib/setup.py
but the same versions as specified in srv/requirements.txt
. Motivation:
- The same version is needed to make sure that if the tests have passed for
lib
, it will work as expected in the environment ofsrv
. - Running tests for
lib
in the environment ofsrv
is complicated on CI: the env ofsrv
is too big, and we want to avoid making it for pipelines inlib
.
Describe the solution you'd like
The idea is the same as in pip's Constraints Files (-c/--constraint
option). So, it makes sense to introduce the same key for pip-tools.
Alternative Solutions
pip-tools already uses the output file as the constraint. So, a workaround I found is to specify the constraint file as the output file and then restore it. The PoC:
import sys
import shutil
import subprocess
from argparse import ArgumentParser
def main():
parser = ArgumentParser()
parser.add_argument('-c', '--constraint', required=True)
parser.add_argument('--output-file', default='requirements.txt')
args, rest = parser.parse_known_args()
shutil.copy(args.constraint, '/tmp/c.txt')
cmd = [sys.executable, '-m', 'piptools', 'compile', '--output-file', args.constraint]
try:
code = subprocess.call(cmd + rest)
shutil.copy(args.constraint, args.output_file)
finally:
shutil.copy('/tmp/c.txt', args.constraint)
sys.exit(code)
if __name__ == '__main__':
main()
Additional context
ssbarnea and borisnaydis
Metadata
Metadata
Assignees
Labels
cliRelated to command line interface thingsRelated to command line interface thingsfeatureRequest for a new featureRequest for a new feature