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

Spreadsheet fixes #181

Merged
merged 24 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
08ca810
rlds_schema: Fix codelist filename in Classification.scheme
duncandewhurst Aug 8, 2023
cf97be7
docs/conf.py: Copy codelists directory to built docs
duncandewhurst Aug 8, 2023
be603ff
docs/conf.py: Use html_extra_path to copy codelists to build directory
duncandewhurst Aug 8, 2023
1ef82f4
codelists: Move to schema/codelists
duncandewhurst Aug 8, 2023
e8a1322
docs/conf.py: Fix schema processing
duncandewhurst Aug 8, 2023
9530696
docs/conf.py: Print Read the Docs version
duncandewhurst Aug 8, 2023
84216e4
docs/conf.py: Print rtd_version
duncandewhurst Aug 8, 2023
2be4634
docs/conf.py: Add print debugging for read the docs build
duncandewhurst Aug 8, 2023
fa5216f
rdls_schema: Fix codelist links in schema descriptions
duncandewhurst Aug 8, 2023
d5c3bf1
docs/conf.py: Update schema processing logic
duncandewhurst Aug 8, 2023
74d04a5
docs/conf.py: Update schema processing logic
duncandewhurst Aug 8, 2023
1b75303
docs/conf.py: Update schema processing logic
duncandewhurst Aug 8, 2023
769311a
docs/conf.py: Update schema processing logic
duncandewhurst Aug 8, 2023
92b716a
Merge branch 'dev' into spreadsheet-fixes
duncandewhurst Aug 8, 2023
85dbaae
rdls_schema: Make version of type string, per description
duncandewhurst Aug 9, 2023
7f88a68
rdls_schema.json: Correct required fields for in Event_set
duncandewhurst Aug 9, 2023
ad67c47
rdls_schema: Replace identifier with id
duncandewhurst Aug 9, 2023
cbd1363
rlds_schema: Correct required fields for Hazard
duncandewhurst Aug 9, 2023
cfda35b
rdls_schema: Correct required fields for Footprint
duncandewhurst Aug 9, 2023
b73bd04
rdls_schema: Fix markdown syntax in Attribution.role description
duncandewhurst Aug 9, 2023
3ece5e0
Update changelog
duncandewhurst Aug 10, 2023
3b3cf12
manage.py: Update pre-commit for new codelist directory location
duncandewhurst Aug 11, 2023
aad0ab2
Run ./manage.py pre-commit
duncandewhurst Aug 11, 2023
153935b
Merge branch 'dev' into spreadsheet-fixes
duncandewhurst Aug 13, 2023
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
6 changes: 6 additions & 0 deletions docs/about/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ This page lists changes to the Risk Data Library Standard.
- [#168](https://github.com/GFDRR/rdl-standard/pull/168) - Add version number and `links` field.
- [#163](https://github.com/GFDRR/rdl-standard/pull/163) - fix typos within rdl_schema_0.1.json
- [#180](https://github.com/GFDRR/rdl-standard/pull/180) - Refactors schema, moves `hazard`, `exposure`, `vulnerability` and `loss` to top level and removes 'anyOf'.
- [#181](https://github.com/GFDRR/rdl-standard/pull/181) - Various fixes:
- Codelist filename in `Classification.scheme`
- {\{version}} placeholder replacement in built schema
- `version` type
- Required fields in `Event_set`, `Hazard` and `Footprint`
- Markdown syntax in `Attribution.role` description
- [#190](https://github.com/GFDRR/rdl-standard/pull/190) - Deletes type key from properties with `$ref` components.

### Codelists
Expand Down
39 changes: 26 additions & 13 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
# sys.path.insert(0, os.path.abspath('.'))
import json
import os
import shutil

from distutils.dir_util import copy_tree
from pygit2 import Repository

# -- General configuration ------------------------------------------------
Expand Down Expand Up @@ -177,13 +180,13 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static', '../schema']
html_static_path = ['_static']

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
#
# html_extra_path = []
html_extra_path = ['../.temp']

# If not None, a 'Last updated on:' timestamp is inserted at every page
# bottom, using the given strftime format.
Expand Down Expand Up @@ -368,6 +371,10 @@
togglebutton_hint = ""


def create_directory(path):
output_dir = os.path.dirname(path)
os.makedirs(output_dir, exist_ok=True)

def replace_substring_in_json(file_path, search_substring, replace_string, output_path=None):
# Read the JSON file
with open(file_path, 'r') as file:
Expand All @@ -381,14 +388,12 @@ def replace_substring_in_json(file_path, search_substring, replace_string, outpu
output_path = file_path

# Create the directory if it does not exist
output_dir = os.path.dirname(output_path)
os.makedirs(output_dir, exist_ok=True)
create_directory(output_path)

# Write the modified JSON data to the output file
with open(output_path, 'w') as file:
json.dump(data, file, indent=4)


def _replace_substring_in_json(data, search_substring, replace_string):
if isinstance(data, dict):
for key, value in data.items():
Expand All @@ -406,17 +411,25 @@ def _replace_substring_in_json(data, search_substring, replace_string):

def setup(app):
# Connect handlers to events
app.connect('config-inited', config_inited)
app.connect('env-before-read-docs', env_before_read_docs)
app.connect('build-finished', build_finished)


def env_before_read_docs(app, env, docnames):
def config_inited(app, config):
shutil.copytree('../schema', '../.temp')

rtd_version = os.getenv('READTHEDOCS_VERSION')

# Process schema and write to _readthedocs/html
# Replace {{version}} placeholders
if rtd_version is not None:
# Replace {{version}} placeholders
replace_substring_in_json('../schema/rdls_schema.json', '{{version}}', rtd_version, output_path='_readthedocs/html/rdls_schema.json')
else:
# Don't replace {{version}} placeholders
replace_substring_in_json('../schema/rdls_schema.json', 'https://rdl-standard.readthedocs.io/en/{{version}}', 'https://rdl-standard.readthedocs.io/en/{{version}}', output_path='_readthedocs/html/rdls_schema.json')

replace_substring_in_json('../.temp/rdls_schema.json', '{{version}}', rtd_version)


def env_before_read_docs(app, env, docnames):
create_directory('_readthedocs/html/')
shutil.copyfile('../.temp/rdls_schema.json', '_readthedocs/html/rdls_schema.json')


def build_finished(app, exception):
shutil.rmtree('../.temp')
2 changes: 1 addition & 1 deletion docs/reference/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

This page presents the schema in an interactive browser. Click on schema elements to expand the tree, or use the '+' icon to expand all elements. Use { } to view the underlying schema for any section. Required fields are indicated in **bold**. You can also [view the schema in reference tables](schema.md).

<script src="../../_static/docson/widget.js" data-schema="../rdls_schema.json"></script>
<script src="../../_static/docson/widget.js" data-schema="../../rdls_schema.json"></script>
58 changes: 29 additions & 29 deletions docs/reference/codelists.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/open/IMT.csv
file: ../../schema/codelists/open/IMT.csv
---
```

Expand All @@ -43,7 +43,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/open/classification_scheme.csv
file: ../../schema/codelists/open/classification_scheme.csv
---
```

Expand All @@ -55,7 +55,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/open/damage_scale_name.csv
file: ../../schema/codelists/open/damage_scale_name.csv
---
```

Expand All @@ -67,7 +67,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/open/data_formats.csv
file: ../../schema/codelists/open/data_formats.csv
---
```

Expand All @@ -83,7 +83,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/open/engineering_demand_parameter.csv
file: ../../schema/codelists/open/engineering_demand_parameter.csv
---
```

Expand All @@ -99,7 +99,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/open/impact_metric.csv
file: ../../schema/codelists/open/impact_metric.csv
---
```

Expand All @@ -115,7 +115,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/open/impact_unit.csv
file: ../../schema/codelists/open/impact_unit.csv
---
```

Expand All @@ -131,7 +131,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/open/license.csv
file: ../../schema/codelists/open/license.csv
---
```

Expand All @@ -143,7 +143,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/open/location_gazetteers.csv
file: ../../schema/codelists/open/location_gazetteers.csv
---
```

Expand All @@ -155,7 +155,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/open/media_type.csv
file: ../../schema/codelists/open/media_type.csv
---
```

Expand All @@ -173,7 +173,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/open/roles.csv
file: ../../schema/codelists/open/roles.csv
---
```

Expand All @@ -191,7 +191,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/analysis_type.csv
file: ../../schema/codelists/closed/analysis_type.csv
---
```

Expand All @@ -208,7 +208,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/cost_type.csv
file: ../../schema/codelists/closed/cost_type.csv
---
```

Expand All @@ -220,7 +220,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/country.csv
file: ../../schema/codelists/closed/country.csv
---
```

Expand All @@ -234,7 +234,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/currency.csv
file: ../../schema/codelists/closed/currency.csv
---
```

Expand All @@ -250,7 +250,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/data_calculation_type.csv
file: ../../schema/codelists/closed/data_calculation_type.csv
---
```

Expand All @@ -267,7 +267,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/exposure_category.csv
file: ../../schema/codelists/closed/exposure_category.csv
---
```

Expand All @@ -279,7 +279,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/frequency_distribution.csv
file: ../../schema/codelists/closed/frequency_distribution.csv
---
```

Expand All @@ -298,7 +298,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/function_approach.csv
file: ../../schema/codelists/closed/function_approach.csv
---
```

Expand All @@ -310,7 +310,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/geometry_type.csv
file: ../../schema/codelists/closed/geometry_type.csv
---
```

Expand All @@ -326,7 +326,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/hazard_type.csv
file: ../../schema/codelists/closed/hazard_type.csv
---
```

Expand All @@ -342,7 +342,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/impact_type.csv
file: ../../schema/codelists/closed/impact_type.csv
---
```

Expand All @@ -354,7 +354,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/loss_type.csv
file: ../../schema/codelists/closed/loss_type.csv
---
```

Expand All @@ -368,7 +368,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/process_type.csv
file: ../../schema/codelists/closed/process_type.csv
---
```

Expand All @@ -387,7 +387,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/relationship_type.csv
file: ../../schema/codelists/closed/relationship_type.csv
---
```

Expand All @@ -399,7 +399,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/risk_data_type.csv
file: ../../schema/codelists/closed/risk_data_type.csv
---
```

Expand All @@ -411,7 +411,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/seasonality.csv
file: ../../schema/codelists/closed/seasonality.csv
---
```

Expand All @@ -427,7 +427,7 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/source_type.csv
file: ../../schema/codelists/closed/source_type.csv
---
```

Expand All @@ -443,6 +443,6 @@ This codelist has the following codes:
---
header-rows: 1
widths: auto
file: ../../codelists/closed/spatial_scale.csv
file: ../../schema/codelists/closed/spatial_scale.csv
---
```
4 changes: 2 additions & 2 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from pathlib import Path

basedir = Path(__file__).resolve().parent
codelistdir = basedir / 'codelists'
referencedir = basedir / 'docs' / 'reference'
schemadir = basedir / 'schema'
codelistdir = schemadir / 'codelists'


def read_lines(filename):
Expand Down Expand Up @@ -164,7 +164,7 @@ def generate_codelist_markdown(codelist, type, references, definitions, defs_pat
"```{csv-table-no-translate}\n",
":header-rows: 1\n",
":widths: auto\n",
f":file: ../../codelists/{type}/{codelist}.csv\n",
f":file: ../../schema/codelists/{type}/{codelist}.csv\n",
"```\n\n"
])

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading