Skip to content

Commit

Permalink
Merge pull request #93 from emmo-repo/dev
Browse files Browse the repository at this point in the history
modify directory structure
  • Loading branch information
jsimonclark authored Sep 8, 2024
2 parents ad22065 + c195bef commit bc20a4b
Show file tree
Hide file tree
Showing 8 changed files with 1,285 additions and 416 deletions.
37 changes: 26 additions & 11 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,32 @@ jobs:
- name: Run EMMO Check - electrochemistry
run: |
emmocheck --verbose --url-from-catalog \
--skip test_namespace \
--skip test_quantity_dimension \
--configfile=.github/utils/emmocheck_config.yml \
electrochemistry.ttl
if [ -f "electrochemistry.ttl" ]; then
emmocheck --verbose --url-from-catalog \
--skip test_namespace \
--skip test_quantity_dimension \
--configfile=.github/utils/emmocheck_config.yml \
electrochemistry.ttl
else
echo "electrochemistry.ttl not found!"
exit 1
fi
- name: Run EMMO Check - electrochemicalquantities
run: |
emmocheck --verbose --url-from-catalog \
--skip test_namespace \
--skip test_quantity_dimension \
--configfile=.github/utils/emmocheck_config.yml \
electrochemicalquantities.ttl
if [ -f "electrochemicalquantities.ttl" ]; then
emmocheck --verbose --url-from-catalog \
--skip test_namespace \
--skip test_quantity_dimension \
--configfile=.github/utils/emmocheck_config.yml \
electrochemicalquantities.ttl
elif [ -f "modules/quantities.ttl" ]; then
emmocheck --verbose --url-from-catalog \
--skip test_namespace \
--skip test_quantity_dimension \
--configfile=.github/utils/emmocheck_config.yml \
modules/quantities.ttl
else
echo "electrochemicalquantities.ttl or modules/quantities.ttl not found!"
exit 1
fi
72 changes: 40 additions & 32 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ on:
push:
branches:
- 'master'

pull_request:
branches:
- '*' # To ensure it runs on all PRs

env:
GIT_USER_NAME: BattINFO Developers
GIT_USER_EMAIL: "[email protected]"
Expand All @@ -23,14 +26,14 @@ jobs:
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4 #Uses python install action from here: https://github.com/marketplace?type=actions
uses: actions/setup-python@v4
with:
python-version: '3.10' # Replace with the desired Python version
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install Markdown==3.4.3 rdflib==6.3.2 pandoc # Add any other dependencies if needed
pip install Markdown==3.4.3 rdflib==6.3.2 pandoc
- name: Render documentation from ttl
run: python docs/scripts/ttl_to_rst.py
Expand All @@ -47,24 +50,13 @@ jobs:
- name: Check if HTML context directory exists
run: |
if [ ! -d "docs/_build/html/context/" ]; then
echo "Creating HTML context directory"
sudo mkdir -p docs/_build/html/context/
else
echo "HTML context directory already exists"
fi
if [ ! -d "docs/_build/html/assets/" ]; then
echo "Creating HTML context directory"
sudo mkdir -p docs/_build/html/assets/
else
echo "HTML assets directory already exists"
fi
if [ ! -d "docs/_build/html/versions/" ]; then
echo "Creating HTML versions directory"
sudo mkdir -p docs/_build/html/versions/
else
echo "HTML version directory already exists"
fi
- name: Copy assets directory to HTML directory
Expand All @@ -78,40 +70,58 @@ jobs:
git config --local user.email "${{ env.GIT_USER_EMAIL }}"
git config --local user.name "${{ env.GIT_USER_NAME }}"
git add context/context.json
# Check for any changes to commit
git diff --staged --quiet || git commit -m "Update context.json file"
- name: Pull latest changes
if: github.event_name == 'push' # Only pull changes during push events
run: git pull origin master --rebase

- name: Push changes
if: github.event_name == 'push' && github.ref == 'refs/heads/master' # Only push during push events on master
run: git push origin HEAD:master

- name: Fetch all tags and create version directories
run: |
git fetch --tags
git tag | while read TAG; do
sudo mkdir -p "docs/_build/html/versions/$TAG"
if [ -f "electrochemicalquantities.ttl" ]; then
python docs/scripts/apply_foops_recommendations.py electrochemicalquantities.ttl electrochemicalquantities-foops.ttl
sudo cp "electrochemicalquantities-foops.ttl" "docs/_build/html/versions/$TAG/electrochemicalquantities.ttl"
elif [ -f "modules/quantities.ttl" ]; then
python docs/scripts/apply_foops_recommendations.py modules/quantities.ttl quantities-foops.ttl
sudo cp "quantities-foops.ttl" "docs/_build/html/versions/$TAG/quantities.ttl"
else
echo "File not found!"
exit 1
fi
python docs/scripts/apply_foops_recommendations.py electrochemistry.ttl electrochemistry-foops.ttl
python docs/scripts/apply_foops_recommendations.py electrochemicalquantities.ttl electrochemicalquantities-foops.ttl
sudo cp "electrochemistry-foops.ttl" "docs/_build/html/versions/$TAG/electrochemistry.ttl"
sudo cp "electrochemicalquantities-foops.ttl" "docs/_build/html/versions/$TAG/electrochemicalquantities.ttl"
sudo cp "electrochemistry-inferred.ttl" "docs/_build/html/versions/$TAG/"
if [ -d "context" ]; then
echo "Context directory exists, copying context.json to $TAG"
# Make sure the context directory exists in the version-specific directory
sudo mkdir -p "docs/_build/html/versions/$TAG/context"
# Copy context.json to the tag-specific context directory
sudo cp "context/context.json" "docs/_build/html/versions/$TAG/context"
else
echo "No context directory found in the source directory."
fi
if [ -d "context" ]; then
sudo mkdir -p "docs/_build/html/versions/$TAG/context"
sudo cp "context/context.json" "docs/_build/html/versions/$TAG/context"
fi
done
- name: Copy TTL files to HTML directory
run: |
if [ -f "electrochemicalquantities.ttl" ]; then
python docs/scripts/apply_foops_recommendations.py electrochemicalquantities.ttl electrochemicalquantities-foops.ttl
sudo cp "electrochemicalquantities-foops.ttl" "docs/_build/html/electrochemicalquantities.ttl"
elif [ -f "modules/quantities.ttl" ]; then
python docs/scripts/apply_foops_recommendations.py modules/quantities.ttl quantities-foops.ttl
sudo cp "quantities-foops.ttl" "docs/_build/html/quantities.ttl"
else
echo "Electrochemical quantities file not found!"
exit 1
fi
python docs/scripts/apply_foops_recommendations.py electrochemistry.ttl electrochemistry-foops.ttl
python docs/scripts/apply_foops_recommendations.py electrochemicalquantities.ttl electrochemicalquantities-foops.ttl
sudo cp "electrochemistry-foops.ttl" "docs/_build/html/electrochemistry.ttl"
sudo cp "electrochemicalquantities-foops.ttl" "docs/_build/html/electrochemicalquantities.ttl"
sudo cp "electrochemistry-inferred.ttl" "docs/_build/html/electrochemistry-inferred.ttl"

- name: Upload artifacts
Expand All @@ -121,10 +131,8 @@ jobs:
path: docs/_build/html/

- name: Deploy
if: github.ref == 'refs/heads/master' && github.event_name == 'push' # Only deploy during push events on master
uses: peaceiris/actions-gh-pages@v3
if: github.ref == 'refs/heads/master'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/_build/html


4 changes: 2 additions & 2 deletions catalog-v001.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<group id="Folder Repository, directory=, recursive=true, Auto-Update=false, version=2" prefer="public" xml:base="">
<uri name="https://w3id.org/emmo/domain/chemical-substance/0.8.0-beta/chemical-substance" uri="https://raw.githubusercontent.com/emmo-repo/domain-chemical-substance/main/chemical-substance.ttl"/>
<uri name="https://w3id.org/emmo/domain/characterisation-methodology/chameo" uri="https://raw.githubusercontent.com/emmo-repo/domain-characterisation-methodology/main/chameo.ttl"/>
<uri name="https://w3id.org/emmo/domain/electrochemistry/0.21.0-beta/electrochemistry" uri="./electrochemistry.ttl"/>
<uri name="https://w3id.org/emmo/domain/electrochemistry/0.21.0-beta/electrochemicalquantities" uri="./electrochemicalquantities.ttl"/>
<uri name="https://w3id.org/emmo/domain/electrochemistry/0.22.0-beta/electrochemistry" uri="./electrochemistry.ttl"/>
<uri name="https://w3id.org/emmo/domain/electrochemistry/0.22.0-beta/modules/quantities" uri="./modules/quantities.ttl"/>

<uri name="https://w3id.org/emmo/1.0.0-beta7/mereocausality" uri="https://raw.githubusercontent.com/emmo-repo/EMMO/1.0.0-beta7/mereocausality/mereocausality.ttl"/>

Expand Down
35 changes: 19 additions & 16 deletions docs/scripts/ttl_to_rst.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rdflib import Graph
import os



Expand Down Expand Up @@ -135,38 +136,40 @@ def render_rst_bottom() -> str:

########### RUN THE RENDERING WORKFLOW ##############


def rendering_workflow():

# PAGES
ttl_modules = [
{"section title": "Quantities used in Electrochemistry",
"path": "./electrochemicalquantities.ttl"},
{"section title": "Electrochemistry Concepts",
"path": "./electrochemistry.ttl"}
]
# Adapt based on file structure
ttl_modules = []

# Check for old structure (root directory)
if os.path.isfile("./electrochemicalquantities.ttl"):
ttl_modules.append({"section title": "Quantities used in Electrochemistry", "path": "./electrochemicalquantities.ttl"})
elif os.path.isfile("./modules/quantities.ttl"):
ttl_modules.append({"section title": "Quantities used in Electrochemistry", "path": "./modules/quantities.ttl"})
else:
raise FileNotFoundError("No suitable TTL file found for electrochemical quantities.")

# Check for the electrochemistry file in the correct directory
if os.path.isfile("./electrochemistry.ttl"):
ttl_modules.append({"section title": "Electrochemistry Concepts", "path": "./electrochemistry.ttl"})
else:
raise FileNotFoundError("No suitable TTL file found for electrochemistry concepts.")

# GENERATE PAGES
rst_filename = "electrochemistry.rst"

rst = render_rst_top()

for module in ttl_modules:

g = load_ttl_from_url(module["path"])

entities_list = extract_terms_info_sparql(g)

page_title = module["section title"]
rst += page_title + "\n"
for ind in range(len(page_title)):
rst += "="
rst += "\n\n"
rst += "=" * len(page_title) + "\n\n"
rst += entities_to_rst(entities_list)

rst += render_rst_bottom()

with open("./docs/"+ rst_filename, "w+", encoding="utf-8") as f:
with open("./docs/" + rst_filename, "w+", encoding="utf-8") as f:
f.write(rst)


Expand Down
Loading

0 comments on commit bc20a4b

Please sign in to comment.