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

Let buildout run a script to create a constraints file. [5.2] #645

Merged
merged 2 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 7 additions & 5 deletions core.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ allow-hosts =
find-links += http://dist.plone.org/thirdparty/

extensions =
buildout.requirements
# Keep mr.developer as last one, because some jenkins scripts look for
# this and add a git-clone-depth after it.
mr.developer

# write a constraints file
dump-requirements-file = ${buildout:directory}/constraints.txt
overwrite-requirements-file = true

# require picked versions
show-picked-versions = true
allow-picked-versions = false
Expand All @@ -53,6 +48,7 @@ plone-user =

[buildout:python27]
parts =
constraints
instance
instance-archetypes
zopepy
Expand All @@ -67,6 +63,7 @@ extensions +=

[buildout:python3]
parts =
constraints
instance
zopepy
ploneversioncheck
Expand Down Expand Up @@ -158,3 +155,8 @@ recipe = zc.recipe.egg
eggs =
zodbupdate
${instance:eggs}

[constraints]
recipe = plone.recipe.command
command = bin/python create-constraints.py
update-command = ${:command}
27 changes: 27 additions & 0 deletions create-constraints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
"""
Parse versions from buildout.cfg and write them into constraints.txt.
This script is automatically called by buildout.

Manual usage: bin/python create-constraints.py
zc.buildout needs to be importable in that python.
"""
from zc.buildout import buildout


# We could read a buildout config filename from the command line arguments,
# but for now it is fine to hardcode it:
configfile = "buildout.cfg"
config = buildout.Buildout(configfile, [])

# Get the constraints from the version pins.
# Nice: the versions get set directly on the config.
# Note: this works like a dictionary, but is a class 'zc.buildout.buildout.Options'.
versions = config.versions
constraints_file = "constraints.txt"
with open(constraints_file, "w") as cfile:
cfile.write("# File created by {}\n".format(__file__))
cfile.write("# Constraints parsed from {}\n".format(configfile))
for package, version in sorted(versions.items()):
cfile.write("{}=={}\n".format(package, version))
print("Wrote all versions as constraints to {}.".format(constraints_file))
1 change: 1 addition & 0 deletions tests.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ oauthlib = 3.1.0
pathtools = 0.1.2
pdbpp = 0.10.2
pkginfo = 1.5.0.1
plone.recipe.command = 1.1
progress = 1.5
prompt-toolkit = 1.0.18
pycparser = 2.19
Expand Down