Skip to content

Commit

Permalink
Merge pull request #645 from plone/maurits/script-constraints-file
Browse files Browse the repository at this point in the history
Let buildout run a script to create a constraints file. [5.2]
  • Loading branch information
mauritsvanrees authored Mar 5, 2020
2 parents 2ff4ce0 + 53f6b41 commit ee7290b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
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 = ${buildout:executable} 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

0 comments on commit ee7290b

Please sign in to comment.