From f572a16284d57b5878bbd09209d2568e4684d067 Mon Sep 17 00:00:00 2001 From: Geoff Boeing Date: Sat, 15 Jul 2023 12:01:05 -0700 Subject: [PATCH 1/9] add prettier and nbconvert hooks --- .pre-commit-config.yaml | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index eb96a40..8e02da0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,10 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: "v4.4.0" hooks: - id: check-added-large-files args: [--maxkb=50] - - id: check-builtin-literals - id: check-case-conflict - - id: check-json - id: check-merge-conflict args: [--assume-in-merge] - id: check-yaml @@ -15,18 +13,32 @@ repos: - id: mixed-line-ending - id: no-commit-to-branch args: [--branch, main] - - id: requirements-txt-fixer - id: trailing-whitespace + - repo: https://github.com/pre-commit/mirrors-prettier + rev: "v3.0.0" + hooks: + - id: prettier + types_or: [markdown, yaml] + - repo: https://github.com/nbQA-dev/nbQA - rev: 1.7.0 + rev: "1.7.0" + hooks: + - id: nbqa-isort + additional_dependencies: [isort] + args: [--line-length=100, --sl] + - id: nbqa-black + additional_dependencies: [black] + args: [--line-length=100] + - id: nbqa-flake8 + additional_dependencies: [flake8] + args: [--max-line-length=100] + + - repo: local hooks: - - id: nbqa-isort - additional_dependencies: [isort] - args: [--line-length=100, --sl, --check-only] - - id: nbqa-black - additional_dependencies: [black] - args: [--line-length=100, --check] - - id: nbqa-flake8 - additional_dependencies: [flake8] - args: [--max-line-length=100] + - id: nbconvert + name: clear notebook output + entry: jupyter nbconvert + language: system + types: [jupyter] + args: ["--clear-output", "--inplace"] From 9c69cd8fa878031b7549881ba2985860d93cf501 Mon Sep 17 00:00:00 2001 From: Geoff Boeing Date: Sat, 15 Jul 2023 12:01:25 -0700 Subject: [PATCH 2/9] update arg --- tests/lint_format.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lint_format.sh b/tests/lint_format.sh index 5d5f4af..3b6d85a 100644 --- a/tests/lint_format.sh +++ b/tests/lint_format.sh @@ -1,4 +1,4 @@ #!/bin/bash set -e pre-commit run --all-files -jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace ./notebooks/*.ipynb +jupyter nbconvert --clear-output --inplace ./notebooks/*.ipynb From 3703a3d5d210a247ffcc9a952d1e29d8fd43df0a Mon Sep 17 00:00:00 2001 From: Geoff Boeing Date: Sat, 15 Jul 2023 12:01:33 -0700 Subject: [PATCH 3/9] lint --- .github/workflows/tests.yml | 3 --- CONTRIBUTING.md | 4 ++-- README.md | 9 +++++---- notebooks/06-stats-indicators-centrality.ipynb | 4 ++-- notebooks/12-node-elevations-edge-grades.ipynb | 6 +++--- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index caa24e8..6309c78 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,9 +7,7 @@ on: branches: [main] jobs: - build: - name: ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: @@ -22,7 +20,6 @@ jobs: shell: bash -elo pipefail {0} steps: - - name: Checkout repo uses: actions/checkout@v3 with: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 55d2e8f..916a44d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,7 +8,7 @@ Thanks for using OSMnx and for considering contributing to it! This issue tracke ## Contribute an example/demo - - post your proposal in the [issue tracker](https://github.com/gboeing/osmnx-examples/issues) or submit a PR with the new Jupyter notebook - - respond to code review +- post your proposal in the [issue tracker](https://github.com/gboeing/osmnx-examples/issues) or submit a PR with the new Jupyter notebook +- respond to code review Every piece of software is a work in progress. This project is the result of many hours of work contributed freely by myself and the many people that build the projects it depends on. Thank you for contributing! diff --git a/README.md b/README.md index d283e7b..b5eb06d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ This gallery contains step-by-step usage tutorials and feature demonstrations as Jupyter notebooks. You can run these notebooks interactively online with [Binder](https://mybinder.org/v2/gh/gboeing/osmnx-examples/main?urlpath=lab) or locally with the official OSMnx [Docker image](https://hub.docker.com/r/gboeing/osmnx). All of the examples are in this repo's [notebooks](notebooks) folder. Note that this repo's main branch generally tracks the functionality of the OSMnx repo's main branch. For examples corresponding to previously released versions of OSMnx, use this repo's tags to browse by release. ### More info: - - [Overview of OSMnx](https://geoffboeing.com/2016/11/osmnx-python-street-networks/) - - [OSMnx repo](https://github.com/gboeing/osmnx) - - [Documentation](https://osmnx.readthedocs.io/) - - [Journal article and citation info](https://geoffboeing.com/publications/osmnx-complex-street-networks/) + +- [Overview of OSMnx](https://geoffboeing.com/2016/11/osmnx-python-street-networks/) +- [OSMnx repo](https://github.com/gboeing/osmnx) +- [Documentation](https://osmnx.readthedocs.io/) +- [Journal article and citation info](https://geoffboeing.com/publications/osmnx-complex-street-networks/) diff --git a/notebooks/06-stats-indicators-centrality.ipynb b/notebooks/06-stats-indicators-centrality.ipynb index a911c44..6cef368 100644 --- a/notebooks/06-stats-indicators-centrality.ipynb +++ b/notebooks/06-stats-indicators-centrality.ipynb @@ -94,9 +94,9 @@ "# unpack dicts into individiual keys:values\n", "stats = ox.basic_stats(G, area=area)\n", "for k, count in stats[\"streets_per_node_counts\"].items():\n", - " stats[\"{}way_int_count\".format(k)] = count\n", + " stats[f\"{k}way_int_count\"] = count\n", "for k, proportion in stats[\"streets_per_node_proportions\"].items():\n", - " stats[\"{}way_int_prop\".format(k)] = proportion\n", + " stats[f\"{k}way_int_prop\"] = proportion\n", "\n", "# delete the no longer needed dict elements\n", "del stats[\"streets_per_node_counts\"]\n", diff --git a/notebooks/12-node-elevations-edge-grades.ipynb b/notebooks/12-node-elevations-edge-grades.ipynb index e67e02a..fa09e15 100644 --- a/notebooks/12-node-elevations-edge-grades.ipynb +++ b/notebooks/12-node-elevations-edge-grades.ipynb @@ -159,10 +159,10 @@ "outputs": [], "source": [ "avg_grade = np.mean(grades)\n", - "print(\"Average street grade in {} is {:.1f}%\".format(place, avg_grade * 100))\n", + "print(f\"Average street grade in {place} is {avg_grade * 100:.1f}%\")\n", "\n", "med_grade = np.median(grades)\n", - "print(\"Median street grade in {} is {:.1f}%\".format(place, med_grade * 100))" + "print(f\"Median street grade in {place} is {med_grade * 100:.1f}%\")" ] }, { @@ -304,7 +304,7 @@ " print(msg.format(np.sum(route_rises), ascent, abs(descent)))\n", "\n", " route_lengths = ox.utils_graph.route_to_gdf(G, route, weight=\"length\")[\"length\"]\n", - " print(\"Total trip distance: {:,.0f} meters\".format(np.sum(route_lengths)))" + " print(f\"Total trip distance: {np.sum(route_lengths):,.0f} meters\")" ] }, { From 54e303378001473258d156d35015613fb268c77f Mon Sep 17 00:00:00 2001 From: Geoff Boeing Date: Sat, 15 Jul 2023 12:07:20 -0700 Subject: [PATCH 4/9] ignore py files --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a03ff5b..790fda0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ *.vrt -keys.py +*.py notebooks/cache/* notebooks/data/* notebooks/logs/* From 4060d1c15b7aa5b3b1664e4b31d9a9895bbe0ca5 Mon Sep 17 00:00:00 2001 From: Geoff Boeing Date: Sat, 15 Jul 2023 12:07:37 -0700 Subject: [PATCH 5/9] delete script --- tests/lint_format.sh | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 tests/lint_format.sh diff --git a/tests/lint_format.sh b/tests/lint_format.sh deleted file mode 100644 index 3b6d85a..0000000 --- a/tests/lint_format.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -e -pre-commit run --all-files -jupyter nbconvert --clear-output --inplace ./notebooks/*.ipynb From cd98b06a5ba226c7f96544db34b7082394eac79a Mon Sep 17 00:00:00 2001 From: Geoff Boeing Date: Sat, 15 Jul 2023 12:07:53 -0700 Subject: [PATCH 6/9] update reqs --- tests/environment-tests.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/environment-tests.yml b/tests/environment-tests.yml index b9f9bc7..d6b015b 100644 --- a/tests/environment-tests.yml +++ b/tests/environment-tests.yml @@ -2,11 +2,7 @@ name: osmnx-examples channels: - conda-forge dependencies: - - black - - flake8 - - isort - - jupyterlab - - nbqa + - nbconvert - osmnx=1.5.1 - pillow - pre-commit From 4a8b3e2ccdc3d26d06b613b0fc6dff3308486f8f Mon Sep 17 00:00:00 2001 From: Geoff Boeing Date: Sat, 15 Jul 2023 12:13:00 -0700 Subject: [PATCH 7/9] use python --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6309c78..c43779e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -42,5 +42,5 @@ jobs: cd ./notebooks rm -r -f *.py jupyter nbconvert --to python *.ipynb - for f in *.py; do ipython "$f"; done + for f in *.py; do python "$f"; done rm -r -f *.py From 06354ce6538294bb69010061011903c153572f6e Mon Sep 17 00:00:00 2001 From: Geoff Boeing Date: Sat, 15 Jul 2023 12:16:42 -0700 Subject: [PATCH 8/9] use ipython --- .github/workflows/tests.yml | 2 +- tests/environment-tests.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c43779e..6309c78 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -42,5 +42,5 @@ jobs: cd ./notebooks rm -r -f *.py jupyter nbconvert --to python *.ipynb - for f in *.py; do python "$f"; done + for f in *.py; do ipython "$f"; done rm -r -f *.py diff --git a/tests/environment-tests.yml b/tests/environment-tests.yml index d6b015b..62d5551 100644 --- a/tests/environment-tests.yml +++ b/tests/environment-tests.yml @@ -2,6 +2,7 @@ name: osmnx-examples channels: - conda-forge dependencies: + - ipython - nbconvert - osmnx=1.5.1 - pillow From 25231cef6cfd18a617272048b12d091f3021e7ff Mon Sep 17 00:00:00 2001 From: Geoff Boeing Date: Sat, 15 Jul 2023 12:21:18 -0700 Subject: [PATCH 9/9] require jupyter --- tests/environment-tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/environment-tests.yml b/tests/environment-tests.yml index 62d5551..1c91a2c 100644 --- a/tests/environment-tests.yml +++ b/tests/environment-tests.yml @@ -2,8 +2,7 @@ name: osmnx-examples channels: - conda-forge dependencies: - - ipython - - nbconvert + - jupyter - osmnx=1.5.1 - pillow - pre-commit