Ejemplo n.º 1
0
def update():
    """
    Update the profile to the latest versions of extensions. If conf.py sets managed_codelist to True, regenerate
    docs/reference/codelists.md to list all codelists from OCDS and extensions.
    """

    import conf

    path_prefix = conf.html_theme_options['root_url']
    ref = conf.release.replace('-', '__').replace('.', '__')
    schema_base_url = f'https://standard.open-contracting.org{path_prefix}/schema/{ref}/'
    build_profile(basedir / 'schema',
                  conf.standard_tag,
                  conf.extension_versions,
                  schema_base_url=schema_base_url,
                  update_codelist_urls=update_codelist_urls)

    if not getattr(conf, 'managed_codelist', False):
        return

    file = basedir / 'docs' / 'reference' / 'codelists.md'
    with file.open('w+') as f:
        filenames = glob(
            str(basedir / 'schema' / 'patched' / 'codelists' / '*.csv'))
        codelists = [os.path.basename(filename) for filename in filenames]

        f.write(
            dedent(f"""\
        # Codelists

        <!-- Do not edit this file. This file is managed by manage.py -->

        For more information on codelists, refer to the [codelists reference](https://standard.open-contracting.org/1.1/en/schema/codelists/) in the OCDS documentation.

        The codelists below are from the OCDS and its extensions, and are provided here for convenience only.

        The codelists can be downloaded as CSV files from <https://standard.open-contracting.org/profiles/{conf.profile_identifier}/latest/en/_static/patched/codelists/>.
        """))  # noqa: E501

        for filename in sorted(codelists):
            heading = re.sub(r'(?<=[a-z])(?=[A-Z])', ' ',
                             filename.replace('.csv', '')).title()

            f.write(f'\n## {heading}\n\n')

            f.write(
                dedent(f"""\
            ```{{csv-table-no-translate}}
            :header-rows: 1
            :class: codelist-table
            :file: ../_static/patched/codelists/{filename}
            ```
            """))
def test_build_profile(tmpdir):
    basedir = tmpdir.mkdir('schema')
    profile = basedir.mkdir('profile')
    profile.join('extension.json').write(
        '{"codelists":[],"dependencies":[],"testDependencies":[]}')

    build_profile(basedir, '1__1__5', {
        "bidOpening": "master",
        "lots": "v1.1.5",
        "options": "master",
    })

    patched_codelists = basedir.join('patched').join('codelists')
    profile_codelists = basedir.join('profile').join('codelists')

    assert len(basedir.listdir()) == 2
    assert len(basedir.join('patched').listdir()) == 3
    assert len(patched_codelists.listdir()) == 19
    assert len(basedir.join('profile').listdir()) == 2
    assert not profile_codelists.exists()

    assert profile.join('extension.json').read() == dedent("""\
    {
      "dependencies": [
        "https://raw.githubusercontent.com/open-contracting-extensions/ocds_location_extension/master/extension.json"
      ],
      "testDependencies": [
        "https://raw.githubusercontent.com/open-contracting-extensions/ocds_bid_extension/master/extension.json",
        "https://raw.githubusercontent.com/open-contracting-extensions/ocds_finance_extension/master/extension.json"
      ]
    }
    """)

    codelist = patched_codelists.join('awardCriteria.csv').read()

    assert ',Deprecated' not in codelist
    assert 'lowestCost' not in codelist
    assert ',Extension\n' in codelist
    assert ',OCDS Core\n' in codelist
def test_build_profile_codelists(tmpdir):
    def update_codelist_urls(text, codelists):
        url = 'https://standard.open-contracting.org/{{version}}/{{lang}}/schema/codelists/#release-tag'
        return text.replace(url, 'https://www.example.com')

    basedir = tmpdir.mkdir('schema')
    profile = basedir.mkdir('profile')
    profile.join('extension.json').write('{}')

    build_profile(basedir,
                  '1__1__5', {
                      "location": "v1.1.5",
                  },
                  update_codelist_urls=update_codelist_urls)

    patched_codelists = basedir.join('patched').join('codelists')
    profile_codelists = basedir.join('profile').join('codelists')

    assert len(basedir.listdir()) == 2
    assert len(basedir.join('patched').listdir()) == 3
    assert len(patched_codelists.listdir()) == 21
    assert len(basedir.join('profile').listdir()) == 3
    assert len(profile_codelists.listdir()) == 2

    assert profile.join('extension.json').read() == dedent("""\
    {
      "codelists": [
        "locationGazetteers.csv",
        "geometryType.csv"
      ]
    }
    """)

    schema = basedir.join('patched').join('release-schema.json').read()

    assert 'https://standard.open-contracting.org/{{version}}/{{lang}}/schema/codelists/#release-tag' not in schema
    assert 'https://www.example.com' in schema
Ejemplo n.º 4
0
# Update this file from a profile with:
# curl https://raw.githubusercontent.com/open-contracting/standard_profile_template/master/schema/build-profile.py -o schema/build-profile.py  # noqa

import os
import sys

from ocdsextensionregistry import build_profile

basedir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(basedir, '..', 'docs'))

from conf import standard_tag, standard_version, extension_versions, schema_base_url  # noqa

build_profile(basedir,
              standard_tag,
              extension_versions,
              schema_base_url=schema_base_url)