From f1c68837cc83a0414a7efdabdfecfac8aa7f09ab Mon Sep 17 00:00:00 2001 From: Kyle Scully Date: Thu, 31 Aug 2023 15:48:22 -0700 Subject: [PATCH] ci: add tasks to check options and casing --- .github/workflows/checks.yml | 30 ++ .../call_graph_data_grid.ipynb | 503 +++++++++++++++++- .../{ => dev}/parse_failure_analysis.ipynb | 0 pyproject.toml | 6 +- scripts/check_options.py | 41 ++ scripts/check_sentence_casing.py | 73 +++ 6 files changed, 643 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/checks.yml rename moderne_visualizations_misc/{ => dev}/parse_failure_analysis.ipynb (100%) create mode 100644 scripts/check_options.py create mode 100644 scripts/check_sentence_casing.py diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000..f63629a --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,30 @@ +name: Run quality checks + +# on all branches +on: + push: + branches: + - '*' + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ".[ci]" + + - name: Check sentence casing + run: | + poe check-sentence-casing + + - name: Check options + run: | + poe check-options diff --git a/moderne_visualizations_misc/call_graph_data_grid.ipynb b/moderne_visualizations_misc/call_graph_data_grid.ipynb index b124a69..6ef268d 100644 --- a/moderne_visualizations_misc/call_graph_data_grid.ipynb +++ b/moderne_visualizations_misc/call_graph_data_grid.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "tags": [ "parameters" @@ -10,7 +10,7 @@ }, "outputs": [], "source": [ - "filter_by_fqn: str = \"\"\n", + "filter_by_fqn: str = \"org.openrewrite.sql.SqlDetector\"\n", "filter_by_method_name: str = \"\"" ] }, @@ -23,13 +23,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "from code_data_science import data_table as dt\n", "\n", - "df = dt.read_csv(\"../samples/call_graph.csv\")\n", + "df = dt.read_csv(\"../samples/OsMDywKkw.csv\")\n", "\n", "if filter_by_fqn:\n", " df = df[(df[\"fromClass\"] == filter_by_fqn) | (df[\"toClass\"] == filter_by_fqn)]\n", @@ -61,18 +61,505 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
OriginPathBranchFrom classFrom methodFrom argumentsFrom typeActionTo classTo methodTo argumentsTo typereturnType
8676github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlDetectorrowsorg.openrewrite.SourceFile,java.lang.String,in...METHODCALLorg.openrewrite.sql.SqlDetectorprobablySqljava.lang.StringMETHODboolean
8677github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlDetectorrowsorg.openrewrite.SourceFile,java.lang.String,in...METHODCALLnet.sf.jsqlparser.parser.CCJSqlParserUtilparsejava.lang.StringMETHODnet.sf.jsqlparser.statement.Statement
8678github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlDetectorrowsorg.openrewrite.SourceFile,java.lang.String,in...METHODCALLorg.openrewrite.sql.SqlDetector$1<constructor>NaNCONSTRUCTORorg.openrewrite.sql.SqlDetector$1
8696github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlDetector$1visitnet.sf.jsqlparser.statement.delete.DeleteMETHODCALLorg.openrewrite.sql.SqlDetectoraddRowNaNMETHODUnknown
8697github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlDetectorrowsorg.openrewrite.SourceFile,java.lang.String,in...METHODCALLnet.sf.jsqlparser.statement.Statementacceptnet.sf.jsqlparser.statement.StatementVisitorMETHODvoid
8698github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlDetectorisSqljava.lang.StringMETHODCALLorg.openrewrite.sql.SqlDetectorprobablySqljava.lang.StringMETHODboolean
8699github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlDetectorisSqljava.lang.StringMETHODCALLorg.openrewrite.sql.SqlDetectorprobablyDdljava.lang.StringMETHODboolean
8700github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlDetectorisSqljava.lang.StringMETHODCALLnet.sf.jsqlparser.parser.CCJSqlParserUtilparsejava.lang.StringMETHODnet.sf.jsqlparser.statement.Statement
8704github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlDetector$ColumnDetectorvisitnet.sf.jsqlparser.schema.ColumnMETHODCALLorg.openrewrite.sql.SqlDetectoraddRowjava.util.concurrent.atomic.AtomicReference<ja...METHODvoid
8710github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlTextBlockFormatVisitor<init>NaNMETHODCALLorg.openrewrite.sql.SqlDetector<constructor>NaNCONSTRUCTORorg.openrewrite.sql.SqlDetector
8720github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlTextBlockFormatVisitorvisitLiteralorg.openrewrite.java.tree.J$Literal,org.openre...METHODCALLorg.openrewrite.sql.SqlDetectorisSqljava.lang.StringMETHODboolean
8746github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.FindSqlgetVisitorNaNMETHODCALLorg.openrewrite.sql.SqlDetector<constructor>NaNCONSTRUCTORorg.openrewrite.sql.SqlDetector
8802github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.FindSql$1findorg.openrewrite.ExecutionContext,int,org.openr...METHODCALLorg.openrewrite.sql.SqlDetectorrowsorg.openrewrite.SourceFile,java.lang.String,in...METHODjava.util.List<org.openrewrite.sql.table.Datab...
8814github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlDetectorTest<init>NaNMETHODCALLorg.openrewrite.sql.SqlDetector<constructor>NaNCONSTRUCTORorg.openrewrite.sql.SqlDetector
8817github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlDetectorTestisSqljava.lang.StringMETHODCALLorg.openrewrite.sql.SqlDetectorisSqljava.lang.StringMETHODboolean
8820github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlDetectorTestisNotSqljava.lang.StringMETHODCALLorg.openrewrite.sql.SqlDetectorisSqljava.lang.StringMETHODboolean
8823github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlDetectorTestisExoticSqljava.lang.StringMETHODCALLorg.openrewrite.sql.SqlDetectorisSqljava.lang.StringMETHODboolean
8826github.comopenrewrite/rewrite-sqlmainorg.openrewrite.sql.SqlDetectorTestisDdljava.lang.StringMETHODCALLorg.openrewrite.sql.SqlDetectorisSqljava.lang.StringMETHODboolean
\n", + "
" + ], + "text/plain": [ + " Origin Path Branch \\\n", + "8676 github.com openrewrite/rewrite-sql main \n", + "8677 github.com openrewrite/rewrite-sql main \n", + "8678 github.com openrewrite/rewrite-sql main \n", + "8696 github.com openrewrite/rewrite-sql main \n", + "8697 github.com openrewrite/rewrite-sql main \n", + "8698 github.com openrewrite/rewrite-sql main \n", + "8699 github.com openrewrite/rewrite-sql main \n", + "8700 github.com openrewrite/rewrite-sql main \n", + "8704 github.com openrewrite/rewrite-sql main \n", + "8710 github.com openrewrite/rewrite-sql main \n", + "8720 github.com openrewrite/rewrite-sql main \n", + "8746 github.com openrewrite/rewrite-sql main \n", + "8802 github.com openrewrite/rewrite-sql main \n", + "8814 github.com openrewrite/rewrite-sql main \n", + "8817 github.com openrewrite/rewrite-sql main \n", + "8820 github.com openrewrite/rewrite-sql main \n", + "8823 github.com openrewrite/rewrite-sql main \n", + "8826 github.com openrewrite/rewrite-sql main \n", + "\n", + " From class From method \\\n", + "8676 org.openrewrite.sql.SqlDetector rows \n", + "8677 org.openrewrite.sql.SqlDetector rows \n", + "8678 org.openrewrite.sql.SqlDetector rows \n", + "8696 org.openrewrite.sql.SqlDetector$1 visit \n", + "8697 org.openrewrite.sql.SqlDetector rows \n", + "8698 org.openrewrite.sql.SqlDetector isSql \n", + "8699 org.openrewrite.sql.SqlDetector isSql \n", + "8700 org.openrewrite.sql.SqlDetector isSql \n", + "8704 org.openrewrite.sql.SqlDetector$ColumnDetector visit \n", + "8710 org.openrewrite.sql.SqlTextBlockFormatVisitor \n", + "8720 org.openrewrite.sql.SqlTextBlockFormatVisitor visitLiteral \n", + "8746 org.openrewrite.sql.FindSql getVisitor \n", + "8802 org.openrewrite.sql.FindSql$1 find \n", + "8814 org.openrewrite.sql.SqlDetectorTest \n", + "8817 org.openrewrite.sql.SqlDetectorTest isSql \n", + "8820 org.openrewrite.sql.SqlDetectorTest isNotSql \n", + "8823 org.openrewrite.sql.SqlDetectorTest isExoticSql \n", + "8826 org.openrewrite.sql.SqlDetectorTest isDdl \n", + "\n", + " From arguments From type Action \\\n", + "8676 org.openrewrite.SourceFile,java.lang.String,in... METHOD CALL \n", + "8677 org.openrewrite.SourceFile,java.lang.String,in... METHOD CALL \n", + "8678 org.openrewrite.SourceFile,java.lang.String,in... METHOD CALL \n", + "8696 net.sf.jsqlparser.statement.delete.Delete METHOD CALL \n", + "8697 org.openrewrite.SourceFile,java.lang.String,in... METHOD CALL \n", + "8698 java.lang.String METHOD CALL \n", + "8699 java.lang.String METHOD CALL \n", + "8700 java.lang.String METHOD CALL \n", + "8704 net.sf.jsqlparser.schema.Column METHOD CALL \n", + "8710 NaN METHOD CALL \n", + "8720 org.openrewrite.java.tree.J$Literal,org.openre... METHOD CALL \n", + "8746 NaN METHOD CALL \n", + "8802 org.openrewrite.ExecutionContext,int,org.openr... METHOD CALL \n", + "8814 NaN METHOD CALL \n", + "8817 java.lang.String METHOD CALL \n", + "8820 java.lang.String METHOD CALL \n", + "8823 java.lang.String METHOD CALL \n", + "8826 java.lang.String METHOD CALL \n", + "\n", + " To class To method \\\n", + "8676 org.openrewrite.sql.SqlDetector probablySql \n", + "8677 net.sf.jsqlparser.parser.CCJSqlParserUtil parse \n", + "8678 org.openrewrite.sql.SqlDetector$1 \n", + "8696 org.openrewrite.sql.SqlDetector addRow \n", + "8697 net.sf.jsqlparser.statement.Statement accept \n", + "8698 org.openrewrite.sql.SqlDetector probablySql \n", + "8699 org.openrewrite.sql.SqlDetector probablyDdl \n", + "8700 net.sf.jsqlparser.parser.CCJSqlParserUtil parse \n", + "8704 org.openrewrite.sql.SqlDetector addRow \n", + "8710 org.openrewrite.sql.SqlDetector \n", + "8720 org.openrewrite.sql.SqlDetector isSql \n", + "8746 org.openrewrite.sql.SqlDetector \n", + "8802 org.openrewrite.sql.SqlDetector rows \n", + "8814 org.openrewrite.sql.SqlDetector \n", + "8817 org.openrewrite.sql.SqlDetector isSql \n", + "8820 org.openrewrite.sql.SqlDetector isSql \n", + "8823 org.openrewrite.sql.SqlDetector isSql \n", + "8826 org.openrewrite.sql.SqlDetector isSql \n", + "\n", + " To arguments To type \\\n", + "8676 java.lang.String METHOD \n", + "8677 java.lang.String METHOD \n", + "8678 NaN CONSTRUCTOR \n", + "8696 NaN METHOD \n", + "8697 net.sf.jsqlparser.statement.StatementVisitor METHOD \n", + "8698 java.lang.String METHOD \n", + "8699 java.lang.String METHOD \n", + "8700 java.lang.String METHOD \n", + "8704 java.util.concurrent.atomic.AtomicReference,,CONSTRUCTOR,org.openrewrite.sql.SqlDetector$1", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.SqlDetector$1,visit,net.sf.jsqlparser.statement.delete.Delete,METHOD,CALL,org.openrewrite.sql.SqlDetector,addRow,,METHOD,Unknown", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.SqlDetector,rows,\"org.openrewrite.SourceFile,java.lang.String,int,java.lang.String\",METHOD,CALL,net.sf.jsqlparser.statement.Statement,accept,net.sf.jsqlparser.statement.StatementVisitor,METHOD,void", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.SqlDetector,isSql,java.lang.String,METHOD,CALL,org.openrewrite.sql.SqlDetector,probablySql,java.lang.String,METHOD,boolean", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.SqlDetector,isSql,java.lang.String,METHOD,CALL,org.openrewrite.sql.SqlDetector,probablyDdl,java.lang.String,METHOD,boolean", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.SqlDetector,isSql,java.lang.String,METHOD,CALL,net.sf.jsqlparser.parser.CCJSqlParserUtil,parse,java.lang.String,METHOD,net.sf.jsqlparser.statement.Statement", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.SqlDetector$ColumnDetector,visit,net.sf.jsqlparser.schema.Column,METHOD,CALL,org.openrewrite.sql.SqlDetector,addRow,\"java.util.concurrent.atomic.AtomicReference>,org.openrewrite.sql.table.DatabaseColumnsUsed$Row\",METHOD,void", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.SqlTextBlockFormatVisitor,,,METHOD,CALL,org.openrewrite.sql.SqlDetector,,,CONSTRUCTOR,org.openrewrite.sql.SqlDetector", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.SqlTextBlockFormatVisitor,visitLiteral,\"org.openrewrite.java.tree.J$Literal,org.openrewrite.ExecutionContext\",METHOD,CALL,org.openrewrite.sql.SqlDetector,isSql,java.lang.String,METHOD,boolean", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.FindSql,getVisitor,,METHOD,CALL,org.openrewrite.sql.SqlDetector,,,CONSTRUCTOR,org.openrewrite.sql.SqlDetector", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.FindSql$1,find,\"org.openrewrite.ExecutionContext,int,org.openrewrite.Cursor,java.lang.String\",METHOD,CALL,org.openrewrite.sql.SqlDetector,rows,\"org.openrewrite.SourceFile,java.lang.String,int,java.lang.String\",METHOD,java.util.List", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.SqlDetectorTest,,,METHOD,CALL,org.openrewrite.sql.SqlDetector,,,CONSTRUCTOR,org.openrewrite.sql.SqlDetector", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.SqlDetectorTest,isSql,java.lang.String,METHOD,CALL,org.openrewrite.sql.SqlDetector,isSql,java.lang.String,METHOD,boolean", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.SqlDetectorTest,isNotSql,java.lang.String,METHOD,CALL,org.openrewrite.sql.SqlDetector,isSql,java.lang.String,METHOD,boolean", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.SqlDetectorTest,isExoticSql,java.lang.String,METHOD,CALL,org.openrewrite.sql.SqlDetector,isSql,java.lang.String,METHOD,boolean", + "github.com,openrewrite/rewrite-sql,main,org.openrewrite.sql.SqlDetectorTest,isDdl,java.lang.String,METHOD,CALL,org.openrewrite.sql.SqlDetector,isSql,java.lang.String,METHOD,boolean" + ] + } + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "from code_data_science import data_grid as moderne_data_grid\n", "\n", diff --git a/moderne_visualizations_misc/parse_failure_analysis.ipynb b/moderne_visualizations_misc/dev/parse_failure_analysis.ipynb similarity index 100% rename from moderne_visualizations_misc/parse_failure_analysis.ipynb rename to moderne_visualizations_misc/dev/parse_failure_analysis.ipynb diff --git a/pyproject.toml b/pyproject.toml index bea99f0..cf8025b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ # @see https://packaging.python.org/en/latest/specifications/declaring-project-metadata/ [project] name = "moderne_visualizations_misc" -version = "0.18.1" +version = "0.17.4" description = "Miscellaneous visualizations for the Moderne platform" authors = [ { name = "Jonathan Schneider", email = "jonathan@moderne.io" }, @@ -21,7 +21,7 @@ dependencies = [ [project.optional-dependencies] dev = ["poethepoet", "nbqa", "black", "nb_mypy"] -ci = ["python-semantic-release"] +ci = ["poethepoet", "python-semantic-release", "papermill"] [project.urls] "Homepage" = "https://github.com/moderneinc/visualizations-misc" @@ -38,6 +38,8 @@ exclude = ["samples", "scripts"] [tool.poe.tasks] check-types = "nbqa mypy --ignore-missing-imports ./moderne_visualizations_misc" format = "nbqa black ./moderne_visualizations_misc" +check-options = "python3 scripts/check_options.py" +check-sentence-casing = "python3 scripts/check_sentence_casing.py" [tool.semantic_release] version_toml = ["pyproject.toml:project.version"] diff --git a/scripts/check_options.py b/scripts/check_options.py new file mode 100644 index 0000000..352e708 --- /dev/null +++ b/scripts/check_options.py @@ -0,0 +1,41 @@ +import os +import papermill as pm +import yaml + + +def check_notebook_options(notebook_filename): + notebook_path = f"/Users/kylescully/Repos/visualizations-misc/moderne_visualizations_misc/{notebook_filename}" + notebook_options = pm.inspect_notebook(notebook_path) + option_names = list(notebook_options.keys()) + + spec__path = f"/Users/kylescully/Repos/visualizations-misc/moderne_visualizations_misc/specs/{notebook_filename.replace('.ipynb', '.yml')}" + + result = None + with open(spec__path, 'r') as stream: + try: + spec = yaml.safe_load(stream) + options = spec.get("options", []) + result = [list(item.keys())[0] for item in options] + except yaml.YAMLError as exc: + print(exc) + + return set(option_names) == set(result) + + +print("\nCheck notebook options and spec file options match") +print("-----------------------------------------------------------------------------") + +# get list of all notebooks in the moderne_visualizations_misc directory +notebook_filenames = [ + filename for filename in os.listdir('./moderne_visualizations_misc') if filename.endswith(".ipynb")] + +exit_code = 0 + +for notebook_filename in notebook_filenames: + if check_notebook_options(notebook_filename): + print(f"✅ {notebook_filename}") + else: + print(f"❌ {notebook_filename}") + exit_code = 1 + +exit(exit_code) diff --git a/scripts/check_sentence_casing.py b/scripts/check_sentence_casing.py new file mode 100644 index 0000000..6350063 --- /dev/null +++ b/scripts/check_sentence_casing.py @@ -0,0 +1,73 @@ +import os +import yaml + + +def sentence_case(sentence: str): + """ + Capitalize the first letter of the first word unless the word is all caps. + """ + words = sentence.split() + + for index, word in enumerate(words): + # if word is ALL UPPER then leave it alone + if word.isupper(): + pass + # if word ends in lowercase s but rest is uppercase then leave it alone + elif word[:-1].isupper() and word[-1] == 's': + pass + # title the first word + elif index == 0: + words[index] = word.title() + else: + words[index] = word.lower() + + return " ".join(words) + + +def check_sentence_casing(spec_filename): + check_status = True + + with open(f"./moderne_visualizations_misc/specs/{spec_filename}", 'r') as stream: + try: + spec = yaml.safe_load(stream) + # check any value or nested value named "displayName" + display_names = [] + + display_names.append(spec.get('displayName')) + + for option in spec.get('options', []): + option_dict = option.get(next(iter(option))) + if option_dict: + display_names.append(option_dict.get('displayName')) + + for display_name in display_names: + if sentence_case(display_name) == display_name: + print(f" ✅ {display_name}") + else: + print( + f" ❌ {display_name} --> {sentence_case(display_name)}") + check_status = False + + except yaml.YAMLError as exc: + print(exc) + return False + return check_status + + +print("\nCheck if display names are sentence case") +print("-----------------------------------------------------------------------------") + +# get list of all notebooks in the moderne_visualizations_misc directory +spec_filenames = [ + filename for filename in os.listdir('./moderne_visualizations_misc/specs') if filename.endswith(".yml")] + +exit_code = 0 + +for spec_filename in spec_filenames: + print(spec_filename) + if check_sentence_casing(spec_filename): + pass + else: + exit_code = 1 + +exit(exit_code)