Skip to content

Commit

Permalink
Merge pull request #24 from lincc-frameworks/update-template
Browse files Browse the repository at this point in the history
Update template to consolidate pre-commit logic
  • Loading branch information
camposandro authored Feb 13, 2024
2 parents a617e0a + 3f22415 commit 5e29e36
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: v1.4.6-59-g4c84e58
_commit: v1.5.1-11-g34358f1
_src_path: gh:lincc-frameworks/python-project-template
author_email: [email protected]
author_name: Sandro Campos
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/asv-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ jobs:

steps:
- name: Checkout main branch of the repository
uses: actions/checkout@main
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Cache Python ${{ env.PYTHON_VERSION }}
uses: actions/cache@main
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: python-${{ env.PYTHON_VERSION }}

- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@main
uses: actions/setup-python@v5
with:
python-version: "${{ env.PYTHON_VERSION }}"

Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
echo "today=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Use last nightly commit hash from cache
uses: actions/cache@main
uses: actions/cache@v4
with:
path: ${{ env.WORKING_DIR }}
key: nightly-results-${{ steps.nightly-dates.outputs.yesterday }}
Expand All @@ -87,7 +87,7 @@ jobs:
echo $CURRENT_HASH > $HASH_FILE
- name: Update last nightly hash in cache
uses: actions/cache@main
uses: actions/cache@v4
with:
path: ${{ env.WORKING_DIR }}
key: nightly-results-${{ steps.nightly-dates.outputs.today }}
12 changes: 6 additions & 6 deletions .github/workflows/asv-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Cache Python ${{ env.PYTHON_VERSION }}
uses: actions/cache@main
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: python-${{ env.PYTHON_VERSION }}
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@main
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
asv-pr:
Expand All @@ -40,14 +40,14 @@ jobs:
working-directory: ${{ env.WORKING_DIR }}
steps:
- name: Checkout PR branch of the repository
uses: actions/checkout@main
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Display Workflow Run Information
run: |
echo "Workflow Run ID: ${{ github.run_id }}"
- name: Cache Python ${{ env.PYTHON_VERSION }}
uses: actions/cache@main
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: python-${{ env.PYTHON_VERSION }}
Expand All @@ -61,7 +61,7 @@ jobs:
- name: Save pull request number
run: echo ${{ github.event.pull_request.number }} > ${{ env.ARTIFACTS_DIR }}/pr
- name: Get current job logs URL
uses: Tiryoh/gha-jobid-action@main
uses: Tiryoh/gha-jobid-action@v1
id: jobs
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -80,7 +80,7 @@ jobs:
env:
STEP_URL: "${{ steps.jobs.outputs.html_url }}#step:11:1"
- name: Upload artifacts (PR number and benchmarks output)
uses: actions/upload-artifact@main
uses: actions/upload-artifact@v4
with:
name: benchmark-artifacts
path: ${{ env.ARTIFACTS_DIR }}
4 changes: 2 additions & 2 deletions .github/workflows/build-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@main
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@main
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
Expand Down
40 changes: 0 additions & 40 deletions .github/workflows/code_style.yml

This file was deleted.

20 changes: 11 additions & 9 deletions .github/workflows/pre-commit-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,32 @@
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@main
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@main
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: |
sudo apt-get update
python -m pip install --upgrade pip
pip install .
pip install .[dev]
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- uses: pre-commit/action@main # Still using Node 16
- 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 }}
- uses: pre-commit-ci/lite-action@main
if: always()
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/[email protected]
if: failure() && github.event_name == 'pull_request' && github.event.pull_request.draft == false
4 changes: 2 additions & 2 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
permissions:
id-token: write
steps:
- uses: actions/checkout@main
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@main
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
Expand Down
24 changes: 21 additions & 3 deletions .prepare_project.sh → .initialize_new_project.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
#!/usr/bin/env bash

echo "Checking virtual environment"
if [ -z "${VIRTUAL_ENV}" ] && [ -z "${CONDA_PREFIX}" ]; then
echo 'No virtual environment detected: none of $VIRTUAL_ENV or $CONDA_PREFIX is set.'
echo
echo "=== This script is going to install the project in the system python environment ==="
echo "Proceed? [y/N]"
read -r RESPONCE
if [ "${RESPONCE}" != "y" ]; then
echo "See https://lincc-ppt.readthedocs.io/ for details."
echo "Exiting."
exit 1
fi

fi

echo "Checking pip version"
MINIMUM_PIP_VERSION=22
pipversion=( $(pip --version | awk '{print $2}' | sed 's/\./ /g') )
pipversion=( $(python -m pip --version | awk '{print $2}' | sed 's/\./ /g') )
if let "${pipversion[0]}<${MINIMUM_PIP_VERSION}"; then
echo "Insufficient version of pip found. Requires at least version ${MINIMUM_PIP_VERSION}."
echo "See https://lincc-ppt.readthedocs.io/ for details."
Expand All @@ -25,10 +40,13 @@ echo "Initializing local git repository"
} > /dev/null

echo "Installing package and runtime dependencies in local environment"
pip install -e . > /dev/null
python -m pip install -e . > /dev/null

echo "Installing developer dependencies in local environment"
pip install -e .'[dev]' > /dev/null
python -m pip install -e .'[dev]' > /dev/null

echo "Installing pre-commit"
pre-commit install > /dev/null

echo "Committing initial files"
git add . && SKIP="no-commit-to-branch" git commit -m "Initial commit"
31 changes: 15 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
fail_fast: true
repos:

# Compare the local template version to the latest remote template version
Expand All @@ -23,21 +22,6 @@ repos:
language: system
entry: jupyter nbconvert --clear-output

# 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=<package_name> --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

# Prevents committing directly branches named 'main' and 'master'.
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand Down Expand Up @@ -128,3 +112,18 @@ 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=<package_name> --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
41 changes: 41 additions & 0 deletions .setup_dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

# This script should be run by new developers to install this package in
# editable mode and configure their local environment

echo "Checking virtual environment"
if [ -z "${VIRTUAL_ENV}" ] && [ -z "${CONDA_PREFIX}" ]; then
echo 'No virtual environment detected: none of $VIRTUAL_ENV or $CONDA_PREFIX is set.'
echo
echo "=== This script is going to install the project in the system python environment ==="
echo "Proceed? [y/N]"
read -r RESPONCE
if [ "${RESPONCE}" != "y" ]; then
echo "See https://lincc-ppt.readthedocs.io/ for details."
echo "Exiting."
exit 1
fi

fi

echo "Checking pip version"
MINIMUM_PIP_VERSION=22
pipversion=( $(python -m pip --version | awk '{print $2}' | sed 's/\./ /g') )
if let "${pipversion[0]}<${MINIMUM_PIP_VERSION}"; then
echo "Insufficient version of pip found. Requires at least version ${MINIMUM_PIP_VERSION}."
echo "See https://lincc-ppt.readthedocs.io/ for details."
exit 1
fi

echo "Installing package and runtime dependencies in local environment"
python -m pip install -e . > /dev/null

echo "Installing developer dependencies in local environment"
python -m pip install -e .'[dev]' > /dev/null

echo "Installing pre-commit"
pre-commit install > /dev/null

#######################################################
# Include any additional configurations below this line
#######################################################
2 changes: 1 addition & 1 deletion benchmarks/asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// variable.
"environment_type": "virtualenv",
// the base URL to show a commit for the project.
"show_commit_url": "https://github.com/lincc-frameworks/benchmarking-asv/commit",
"show_commit_url": "https://github.com/lincc-frameworks/benchmarking-asv/commit/",
// The Pythons you'd like to test against. If not provided, defaults
// to the current version of Python used to run `asv`.
"pythons": [
Expand Down
20 changes: 20 additions & 0 deletions docs/notebooks/intro_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
"source": [
"sierpinsky(4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3a7bb740",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -77,6 +85,18 @@
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 5e29e36

Please sign in to comment.