From 64baaf815138789a0fe87b857747050f71ab4714 Mon Sep 17 00:00:00 2001 From: Lino Galiana Date: Mon, 3 Jul 2023 17:05:53 +0000 Subject: [PATCH] Script for branch deploy (#367) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * script * Automated changes * Automated changes * change also keys * write * Automated changes * Automated changes * force chapters * tweak project * Tweak project delete entry * Automated changes * Automated changes * cat file * Automated changes * Automated changes * tweak chapters in case * Automated changes * Automated changes * essaye comme ça * forcing value * Automated changes * Automated changes * try * Automated changes * Automated changes --------- Co-authored-by: github-actions[bot] Co-authored-by: root --- .github/workflows/netlify-test.yaml | 83 +------------------ build/tweak_chapters.py | 21 +++++ build/tweak_project.py | 10 ++- build/tweak_render.py | 16 ++-- .../02a_pandas_tutorial/index.qmd | 1 + 5 files changed, 42 insertions(+), 89 deletions(-) create mode 100644 build/tweak_chapters.py diff --git a/.github/workflows/netlify-test.yaml b/.github/workflows/netlify-test.yaml index 3b68d5366..e176c65aa 100644 --- a/.github/workflows/netlify-test.yaml +++ b/.github/workflows/netlify-test.yaml @@ -28,7 +28,9 @@ jobs: - name: Render website run: | git diff --name-only origin/master origin/${GITHUB_HEAD_REF} >> diff + python build/tweak_chapters.py python build/tweak_render.py + cat _quarto.yml quarto render --to html python build/wc_website.py python build/tweak_markdown.py @@ -98,14 +100,11 @@ jobs: run: | git config user.name 'github-actions[bot]' git config user.email 'github-actions[bot]@users.noreply.github.com' - # git config user.email github-actions@github.com - #git checkout ${BRANCHE_REF} git status find notebooks -type f -name "*.ipynb" | xargs git add git commit -m "Automated changes"; git pull git push - git push corrections: name: Render-Blog runs-on: ubuntu-latest @@ -144,8 +143,6 @@ jobs: run: | git config user.name 'github-actions[bot]' git config user.email 'github-actions[bot]@users.noreply.github.com' - # git config user.email github-actions@github.com - #git checkout ${BRANCHE_REF} git status find corrections -type f -name "*.ipynb" | xargs git add git commit -m "Automated changes"; @@ -155,79 +152,3 @@ jobs: -# corrections: -# runs-on: ubuntu-latest -# container: linogaliana/python-datascientist:latest -# steps: -# - uses: actions/checkout@v2 -# with: -# submodules: true -# fetch-depth: 0 -# ref: ${{ github.event.pull_request.head.ref }} -# repository: ${{github.event.pull_request.head.repo.full_name}} -# - name: Install rmarkdown -# env: -# GITHUB_PAT: ${{ secrets.PAT_GITHUB }} -# run: | -# Rscript -e 'remotes::install_github("yihui/xfun")' -# Rscript -e 'remotes::install_github("yihui/knitr")' -# Rscript -e 'install.packages(c("rmarkdown"))' -# - name: Install Python -# run: | -# Rscript -e "install.packages(c('remotes', 'reticulate'))" -# Rscript -e "install.packages(c('here'))" -# - shell: bash -l {0} -# run: | -# conda info -# conda list -# - name: Modif Rmd echo status -# run: | -# python build/modifmd.py -# - name: Build to md -# run: | -# git diff --name-only origin/master origin/${GITHUB_HEAD_REF} >> diff.txt -# cat diff.txt -# Rscript -e 'source("./build/build_light.R")' -# - name: Clean files with Python function -# run: | -# rm -rf "./temp" -# mkdir -p temp -# mkdir -p corrections -# python build/cleanmd.py -# - name: Convert in ipynb with Jupytext -# run: | -# pip install jupytext -# cd ./temp -# for i in $(find . -type f \( -iname "*.Rmd" \)); do \ -# j="${i%.Rmd}.md" ; -# echo "$j" ; -# if [ -e $j ] -# then -# echo "Converting $j"; \ -# #jupytext --to py --execute "$i" -# jupytext --to ipynb "$j" ; -# k="${j%.md}.ipynb" ; -# fi -# done -# mkdir -p ../corrections -# cp -R . ../corrections -# cd .. -# - uses: actions/upload-artifact@v2 -# with: -# name: Corrections -# path: corrections/ -# - name: Commit new notebooks -# if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} -# env: -# BRANCHE_REF: ${{ github.event.pull_request.head.ref }} -# run: | -# git config user.name 'github-actions[bot]' -# git config user.email 'github-actions[bot]@users.noreply.github.com' -# # git config user.email github-actions@github.com -# #git checkout ${BRANCHE_REF} -# git status -# git add corrections/**/*.ipynb; -# git commit -m "Automated changes"; -# git pull -# git push - diff --git a/build/tweak_chapters.py b/build/tweak_chapters.py new file mode 100644 index 000000000..88afeec0d --- /dev/null +++ b/build/tweak_chapters.py @@ -0,0 +1,21 @@ +import yaml + +# Specify the file to be modified +file_path = "_quarto.yml" + +# Load the YAML file +with open(file_path, 'r') as file: + data = yaml.safe_load(file) + +# Define the replacement mappings +replacements = { + "book": "website", + "Book": "Website", + "BOOK": "WEBSITE" +} + +del data['book']['chapters'] + +# Write the modified data back to the YAML file +with open(file_path, 'w') as file: + yaml.dump(data, file) \ No newline at end of file diff --git a/build/tweak_project.py b/build/tweak_project.py index d7987a4a4..96a3d20bb 100644 --- a/build/tweak_project.py +++ b/build/tweak_project.py @@ -14,24 +14,28 @@ "BOOK": "WEBSITE" } +del data['book']['chapters'] + # Function to recursively replace values in a dictionary def replace_values(data): if isinstance(data, dict): - for key, value in data.items(): + for key, value in list(data.items()): if isinstance(value, str): for old, new in replacements.items(): value = value.replace(old, new) data[key] = value - elif isinstance(value, (dict, list)): + else: replace_values(value) + if key in replacements: + data[replacements[key]] = data.pop(key) elif isinstance(data, list): for i in range(len(data)): replace_values(data[i]) - # Replace the values in the loaded data replace_values(data) + # Write the modified data back to the YAML file with open(file_path, 'w') as file: yaml.dump(data, file) \ No newline at end of file diff --git a/build/tweak_render.py b/build/tweak_render.py index 1972744d0..5471fa282 100644 --- a/build/tweak_render.py +++ b/build/tweak_render.py @@ -2,7 +2,9 @@ import glob import yaml -with open("_quarto.yml", "r") as stream: +file_path = "_quarto.yml" + +with open(file_path, "r") as stream: config = yaml.load(stream, Loader=yaml.FullLoader) if os.path.exists('diff'): @@ -16,13 +18,17 @@ for dir in ["manipulation", "visualisation", "modelisation", "NLP", "modern-ds"] ] lines += [f"content/course/index.qmd"] -lines += [f"!content/slides/intro/index.qmd"] lines += [f"index.qmd"] -print(lines) -config['project']['render'] = lines +config.setdefault('book', {})['chapters'] = lines + +lines2 = lines + ["!content/slides/intro/index.qmd"] + + +print(lines2) +config['project']['render'] = lines2 -with open('_quarto_temp.yml', 'w') as outfile: +with open(file_path, 'w') as outfile: yaml.dump(config, outfile, default_flow_style=False) print("Done") diff --git a/content/course/manipulation/02a_pandas_tutorial/index.qmd b/content/course/manipulation/02a_pandas_tutorial/index.qmd index 0e1263f3f..779cd0048 100644 --- a/content/course/manipulation/02a_pandas_tutorial/index.qmd +++ b/content/course/manipulation/02a_pandas_tutorial/index.qmd @@ -1154,6 +1154,7 @@ L'utilisation des `pipe` rend le code très lisible et peut être très pratique lorsqu'on enchaine des opérations sur le même _dataset_. + # Quelques enjeux de performance La librairie `Dask` intègre la structure de `numpy`, `pandas` et `sklearn`.