Skip to content

Commit

Permalink
Add a update_codelist_urls parameter to ocdsextensionregistry.api.bui…
Browse files Browse the repository at this point in the history
…ld_profile to modify codelist reference URLs
  • Loading branch information
jpmckinney committed Oct 1, 2019
1 parent c9aa34d commit afab516
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
15 changes: 10 additions & 5 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
Changelog
=========

0.0.15 (2019-09-30)
~~~~~~~~~~~~~~~~~~~

- Add a ``update_codelist_urls`` parameter to ``ocdsextensionregistry.api.build_profile`` to modify codelist reference URLs.

0.0.14 (2019-09-18)
~~~~~~~~~~~~~~~~~~~

- Use in-memory HTTP requests cache.
- Use in-memory HTTP requests cache.

0.0.13 (2019-08-29)
~~~~~~~~~~~~~~~~~~~

- Add a ``schema`` parameter to ``ProfileBuilder``'s ``patched_release_schema()`` and ``release_package_schema()`` methods to override the release schema or release package schema.
- Add a ``schema`` parameter to ``ProfileBuilder``'s ``patched_release_schema()`` and ``release_package_schema()`` methods to override the release schema or release package schema.

0.0.12 (2019-08-29)
~~~~~~~~~~~~~~~~~~~

- Unregistered extensions are now supported by the profile builder. The ``extension_versions`` argument to ``ProfileBuilder`` can be a list of extensions' metadata URLs, base URLs and/or download URLs.
- Add an ``extension_field`` parameter to ``ProfileBuilder``'s ``release_schema_patch()`` and ``patched_release_schema()`` methods to annotate all definitions and properties with extension names.
- Add a ``get_latest_version()`` method to ``ocdsextensionregistry.utils``, to return the identifier of the latest version from a list of versions of the same extension.
- Unregistered extensions are now supported by the profile builder. The ``extension_versions`` argument to ``ProfileBuilder`` can be a list of extensions' metadata URLs, base URLs and/or download URLs.
- Add an ``extension_field`` parameter to ``ProfileBuilder``'s ``release_schema_patch()`` and ``patched_release_schema()`` methods to annotate all definitions and properties with extension names.
- Add a ``get_latest_version()`` method to ``ocdsextensionregistry.utils``, to return the identifier of the latest version from a list of versions of the same extension.

0.0.11 (2019-06-26)
~~~~~~~~~~~~~~~~~~~
Expand Down
27 changes: 25 additions & 2 deletions ocdsextensionregistry/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
VALID_FIELDNAMES = ('Code', 'Title', 'Description', 'Extension')


def build_profile(basedir, standard_tag, extension_versions, registry_base_url=None, schema_base_url=None):
def identity(text, *args, **kwargs):
return text


def build_profile(basedir, standard_tag, extension_versions, registry_base_url=None, schema_base_url=None,
update_codelist_urls=None):
"""
Pulls extensions into a profile.
Expand All @@ -22,7 +27,15 @@ def build_profile(basedir, standard_tag, extension_versions, registry_base_url=N
The profile's codelists exclude deprecated codes and add an Extension column.
`basedir` is the profile's schema/ directory.
:param str basedir: the profile's ``schema/`` directory
:param str standard_tag: the OCDS version tag, e.g. ``'1__1__3'``
:param extension_versions: the extension versions
:param str registry_base_url: the registry's base URL, defaults to
``'https://raw.githubusercontent.com/open-contracting/extension_registry/master/'``
:param str schema_base_url: the schema's base URL, e.g.
``'https://standard.open-contracting.org/profiles/ppp/schema/1__0__0__beta/'``
:param update_codelist_urls: a function that accepts a schema as text and a list of names of codelists and replaces
the OCDS documentation's codelist page URLs with the profile's codelist page URLs
"""
@contextmanager
def open_file(name, mode='r'):
Expand Down Expand Up @@ -88,3 +101,13 @@ def write_codelist_file(codelist, fieldnames, *parts):
metadata.pop('codelists', None)

write_json_file(metadata, 'profile', 'extension.json')

if update_codelist_urls:
codelists = [codelist.basename for codelist in extension_codelists]
for directory, schemas in directories_and_schemas.items():
for filename, schema in schemas.items():
path = os.path.join(basedir, directory, filename)
with open(path) as f:
content = f.read()
with open(path, 'w') as f:
f.write(update_codelist_urls(content, codelists))

0 comments on commit afab516

Please sign in to comment.