diff --git a/src/zc/buildout/buildout.py b/src/zc/buildout/buildout.py index e220ee7737a6b36b9b640290c7fa9d4654e3b62e..e8a4a319e085a5eca1679ed2d4375f119231077a 100644 --- a/src/zc/buildout/buildout.py +++ b/src/zc/buildout/buildout.py @@ -1618,6 +1618,17 @@ def _open(base, filename, seen, dl_options, override, downloaded): 'No-longer supported "extended-by" option found in %s.' % filename) + # find and expose _profile_base_location_ + for section, value in result.items(): + _profile_base_location_ = None + for k,v in value.items(): + if '${:_profile_base_location_}' in v: + _profile_base_location_ = base + if _profile_base_location_ is not None: + break + if _profile_base_location_ is not None: + value['_profile_base_location_'] = _profile_base_location_ + result = _annotate(result, filename) if root_config_file and 'buildout' in result: diff --git a/src/zc/buildout/buildout.txt b/src/zc/buildout/buildout.txt index 9a128b4de0127b850f48116191bec3a6d14fdcc5..b38ac850f89ba4f561e0b11cead3c91a838b0cfa 100644 --- a/src/zc/buildout/buildout.txt +++ b/src/zc/buildout/buildout.txt @@ -1003,6 +1003,102 @@ _buildout_section_name_ to get the current section name. my_name debug recipe recipes:debug +It is possible to have access to profile base url from section by +using ${:_profile_base_location_}: + + >>> write(sample_buildout, 'buildout.cfg', + ... """ + ... [buildout] + ... develop = recipes + ... parts = data-dir debug + ... log-level = INFO + ... + ... [debug] + ... recipe = recipes:debug + ... profile_base_location = ${:_profile_base_location_} + ... + ... [data-dir] + ... recipe = recipes:mkdir + ... path = mydata + ... """) + + >>> print_(system(buildout), end='') + Develop: '/sample-buildout/recipes' + Uninstalling debug. + Updating data-dir. + Installing debug. + _profile_base_location_ /sample-buildout + profile_base_location /sample-buildout + recipe recipes:debug + +Keep in mind that in case of sections spaning across multiple profiles, +the topmost value will be presented: + + >>> write(sample_buildout, 'extended.cfg', + ... """ + ... [debug] + ... profile_base_location = ${:_profile_base_location_} + ... """) + + >>> write(sample_buildout, 'buildout.cfg', + ... """ + ... [buildout] + ... extends = extended.cfg + ... develop = recipes + ... parts = data-dir debug + ... log-level = INFO + ... + ... [debug] + ... recipe = recipes:debug + ... profile_base_location = ${:_profile_base_location_} + ... + ... [data-dir] + ... recipe = recipes:mkdir + ... path = mydata + ... """) + + >>> print_(system(buildout), end='') + Develop: '/sample-buildout/recipes' + Updating data-dir. + Updating debug. + _profile_base_location_ /sample-buildout + profile_base_location /sample-buildout + recipe recipes:debug + +But of course, in case if accessing happens in extended profile's section, +this profile's location will be exposed: + + >>> write(sample_buildout, 'extended.cfg', + ... """ + ... [debug] + ... profile_base_location = ${:_profile_base_location_} + ... """) + + >>> write(sample_buildout, 'buildout.cfg', + ... """ + ... [buildout] + ... extends = extended.cfg + ... develop = recipes + ... parts = data-dir debug + ... log-level = INFO + ... + ... [debug] + ... recipe = recipes:debug + ... + ... [data-dir] + ... recipe = recipes:mkdir + ... path = mydata + ... """) + + >>> print_(system(buildout), end='') + Develop: '/sample-buildout/recipes' + Updating data-dir. + Updating debug. + _profile_base_location_ /sample-buildout + profile_base_location /sample-buildout + recipe recipes:debug + >>> remove(sample_buildout, 'extended.cfg') + Automatic part selection and ordering -------------------------------------