From 1132037d0a7b316a7877bd32dabec015f0f5b984 Mon Sep 17 00:00:00 2001 From: Sandro Campos Date: Fri, 16 Feb 2024 16:14:48 -0500 Subject: [PATCH] Update imports in notebooks --- .copier-answers.yml | 2 +- .github/workflows/code_style.yml | 42 -------------------- .github/workflows/pre-commit-ci.yml | 18 +++++---- .pre-commit-config.yaml | 35 +++++++++------- docs/conf.py | 10 +++++ docs/notebooks/catalog_size_inspection.ipynb | 10 ++--- docs/notebooks/cone_search.ipynb | 10 ++--- docs/requirements.txt | 1 + src/hipscat/__init__.py | 2 +- 9 files changed, 52 insertions(+), 78 deletions(-) delete mode 100644 .github/workflows/code_style.yml diff --git a/.copier-answers.yml b/.copier-answers.yml index 0e93755d..66eeea9a 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,5 +1,5 @@ # Changes here will be overwritten by Copier -_commit: v1.5.2 +_commit: v1.5.3 _src_path: gh:lincc-frameworks/python-project-template author_email: lincc-frameworks-team@lists.lsst.org author_name: LINCC Frameworks diff --git a/.github/workflows/code_style.yml b/.github/workflows/code_style.yml deleted file mode 100644 index 23442fdd..00000000 --- a/.github/workflows/code_style.yml +++ /dev/null @@ -1,42 +0,0 @@ -# This workflow will install Python dependencies, then perform static analysis for code style and type checking. -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: Code Style analysis - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ['3.9', '3.10', '3.11'] - - steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - sudo apt-get update - python -m pip install --upgrade pip - pip install .[dev] - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Analyze code for black formatting - run: | - black --check . - - name: Analyze code with pylint - run: | - pylint -rn -sn --recursive=y ./src --rcfile=./src/.pylintrc - pylint -rn -sn --recursive=y ./tests --rcfile=./tests/.pylintrc - pylint -rn -sn --recursive=y ./benchmarks --rcfile=./tests/.pylintrc \ No newline at end of file diff --git a/.github/workflows/pre-commit-ci.yml b/.github/workflows/pre-commit-ci.yml index 025909ca..a57e2219 100644 --- a/.github/workflows/pre-commit-ci.yml +++ b/.github/workflows/pre-commit-ci.yml @@ -1,17 +1,17 @@ -# This workflow runs pre-commit hooks on pull requests to enforce coding style. -# To ensure correct configuration, please refer to: -# https://lincc-ppt.readthedocs.io/en/latest/practices/ci_precommit.html - +# This workflow runs pre-commit hooks on pushes and pull requests to main +# to enforce coding style. To ensure correct configuration, please refer to: +# https://lincc-ppt.readthedocs.io/en/latest/practices/ci_precommit.html name: Run pre-commit hooks on: + push: + branches: [ main ] pull_request: + branches: [ main ] jobs: pre-commit-ci: runs-on: ubuntu-latest - env: - SKIP: "check-lincc-frameworks-template-version,pytest-check,no-commit-to-branch,validate-pyproject,check-added-large-files,sphinx-build" steps: - uses: actions/checkout@v4 with: @@ -28,6 +28,8 @@ jobs: if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - uses: pre-commit/action@v3.0.1 with: - extra_args: --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }} + extra_args: --all-files --verbose + env: + SKIP: "check-lincc-frameworks-template-version,no-commit-to-branch,check-added-large-files,validate-pyproject,sphinx-build,pytest-check" - uses: pre-commit-ci/lite-action@v1.0.2 - if: always() \ No newline at end of file + if: failure() && github.event_name == 'pull_request' && github.event.pull_request.draft == false \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 52100a6a..385b6a6e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,3 @@ -fail_fast: true repos: # Compare the local template version to the latest remote template version # This hook should always pass. It will print a message if the local version @@ -38,6 +37,12 @@ repos: - id: validate-pyproject name: Validate pyproject.toml description: Verify that pyproject.toml adheres to the established schema. + # Verify that GitHub workflows are well formed + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.28.0 + hooks: + - id: check-github-workflows + args: ["--verbose"] # Automatically sort the imports used in .py files - repo: https://github.com/pycqa/isort rev: 5.12.0 @@ -88,20 +93,6 @@ repos: # pre-commit's default_language_version, see # https://pre-commit.com/#top_level-default_language_version language_version: python3.10 - # Run unit tests, verify that they pass. Note that coverage is run against - # the ./src directory here because that is what will be committed. In the - # github workflow script, the coverage is run against the installed package - # and uploaded to Codecov by calling pytest like so: - # `python -m pytest --cov= --cov-report=xml` - - repo: local - hooks: - - id: pytest-check - name: Run unit tests - description: Run unit tests with pytest. - entry: bash -c "if python -m pytest --co -qq; then python -m pytest --cov=./src --cov-report=html; fi" - language: system - pass_filenames: false - always_run: true # Make sure Sphinx can build the documentation while explicitly omitting # notebooks from the docs, so users don't have to wait through the execution # of each notebook or each commit. By default, these will be checked in the @@ -128,3 +119,17 @@ repos: "-D", # Flag to override settings in conf.py "exclude_patterns=notebooks/*", # Exclude our notebooks from pre-commit ] + # Run unit tests, verify that they pass. Note that coverage is run against + # the ./src directory here because that is what will be committed. In the + # github workflow script, the coverage is run against the installed package + # and uploaded to Codecov by calling pytest like so: + # `python -m pytest --cov= --cov-report=xml` + - repo: local + hooks: + - id: pytest-check + name: Run unit tests + description: Run unit tests with pytest. + entry: bash -c "if python -m pytest --co -qq; then python -m pytest --cov=./src --cov-report=html; fi" + language: system + pass_filenames: false + always_run: true diff --git a/docs/conf.py b/docs/conf.py index 6fcb5db1..00c3450b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -30,6 +30,16 @@ extensions.append("nbsphinx") extensions.append("myst_parser") +# -- sphinx-copybutton configuration ---------------------------------------- +extensions.append("sphinx_copybutton") +## sets up the expected prompt text from console blocks, and excludes it from +## the text that goes into the clipboard. +copybutton_exclude = ".linenos, .gp" +copybutton_prompt_text = ">> " + +## lets us suppress the copy button on select code blocks. +copybutton_selector = "div:not(.no-copybutton) > div.highlight > pre" + templates_path = [] exclude_patterns = ["_build", "**.ipynb_checkpoints"] diff --git a/docs/notebooks/catalog_size_inspection.ipynb b/docs/notebooks/catalog_size_inspection.ipynb index f578c184..421b9a55 100644 --- a/docs/notebooks/catalog_size_inspection.ipynb +++ b/docs/notebooks/catalog_size_inspection.ipynb @@ -33,23 +33,23 @@ "metadata": {}, "outputs": [], "source": [ + "import hipscat\n", "import os\n", "\n", - "from hipscat.loaders import read_from_hipscat\n", - "from hipscat.io import paths\n", - "\n", "### Change this path!!!\n", "catalog_dir = \"../../tests/data/small_sky_order1\"\n", "\n", "### ----------------\n", "### You probably won't have to change anything from here.\n", "\n", - "catalog = read_from_hipscat(catalog_dir)\n", + "catalog = hipscat.read_from_hipscat(catalog_dir)\n", "\n", "info_frame = catalog.partition_info.as_dataframe()\n", "\n", "for index, partition in info_frame.iterrows():\n", - " file_name = result = paths.pixel_catalog_file(catalog_dir, partition[\"Norder\"], partition[\"Npix\"])\n", + " file_name = result = hipscat.io.paths.pixel_catalog_file(\n", + " catalog_dir, partition[\"Norder\"], partition[\"Npix\"]\n", + " )\n", " info_frame.loc[index, \"size_on_disk\"] = os.path.getsize(file_name)\n", "\n", "info_frame = info_frame.astype(int)\n", diff --git a/docs/notebooks/cone_search.ipynb b/docs/notebooks/cone_search.ipynb index afab7c96..0f301151 100644 --- a/docs/notebooks/cone_search.ipynb +++ b/docs/notebooks/cone_search.ipynb @@ -16,12 +16,10 @@ "metadata": {}, "outputs": [], "source": [ + "import hipscat\n", "import healpy as hp\n", "import numpy as np\n", "\n", - "from hipscat.loaders import read_from_hipscat\n", - "from hipscat import inspection\n", - "\n", "## Fill in these variables with what's relevant in your use case:\n", "\n", "### Change this path!!!\n", @@ -40,7 +38,7 @@ "source": [ "## Load catalog\n", "\n", - "catalog = read_from_hipscat(catalog_path)" + "catalog = hipscat.read_from_hipscat(catalog_path)" ] }, { @@ -51,7 +49,7 @@ "source": [ "## Plot catalog pixels\n", "\n", - "inspection.plot_pixels(catalog)" + "hipscat.inspection.plot_pixels(catalog)" ] }, { @@ -82,7 +80,7 @@ "\n", "filtered_catalog = catalog.filter_by_cone(ra, dec, radius)\n", "\n", - "inspection.plot_pixels(filtered_catalog)" + "hipscat.inspection.plot_pixels(filtered_catalog)" ] } ], diff --git a/docs/requirements.txt b/docs/requirements.txt index c51204ca..d50b9a73 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,6 +1,7 @@ sphinx sphinx-rtd-theme sphinx-autoapi +sphinx-copybutton nbsphinx ipykernel ipython diff --git a/src/hipscat/__init__.py b/src/hipscat/__init__.py index 375f038a..a1e23d3a 100644 --- a/src/hipscat/__init__.py +++ b/src/hipscat/__init__.py @@ -1,4 +1,4 @@ """High-level namespace, hipscat""" -from . import catalog, io, pixel_math +from . import catalog, inspection, io, pixel_math from .loaders import read_from_hipscat