Skip to content

Commit

Permalink
Merge pull request #9 from oreum-industries/update-to-python311
Browse files Browse the repository at this point in the history
Update to python 3.11 and MacOS accelerate BLAS
  • Loading branch information
jonsedar authored Dec 17, 2023
2 parents 84048fb + 39e5a0a commit 97c7df4
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 164 deletions.
23 changes: 14 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
name: ci
on: [pull_request]
on: pull_request
jobs:
qc_coding_standards:
runs-on: ubuntu-latest
code_qc:
runs-on: ${{ matrix.platform }}
strategy:
matrix:
platform: ["ubuntu-latest"]
python-version: ["3.11"]
steps:
- uses: actions/checkout@v3
- name: Set Up Basic Python Env
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Run Linter & Static Security Checks
run: make lint
python-version: ${{ matrix.python-version }}
- name: Run Linting and Code Security Checks
run: |
make lint
28 changes: 18 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# .pre-commit-config.yaml
default_language_version:
python: python3.10
python: python3.11
default_stages: [commit, push]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks # general checks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
args: ['--maxkb=1024']
Expand All @@ -31,12 +31,12 @@ repos:
- id: no-print-statements
files: ^src/
- repo: https://github.com/psf/black # black formatter
rev: 23.7.0
rev: 23.11.0
hooks:
- id: black
files: ^src/
- repo: https://github.com/PyCQA/isort # isort sort imports
rev: 5.12.0
rev: 5.13.0
hooks:
- id: isort
files: ^src/
Expand All @@ -45,14 +45,22 @@ repos:
hooks:
- id: flake8
files: ^src/
- repo: https://github.com/nbQA-dev/nbQA # generalised notebook QA
rev: 1.7.0
- repo: https://github.com/pycqa/bandit # basic security checks for python code
rev: 1.7.6
hooks:
# - id: nbqa-black # not yet
- id: nbqa-isort
additional_dependencies: [isort==5.10.1]
- id: bandit
files: ^src/
args: ["--config", "pyproject.toml"]
additional_dependencies: ["bandit[toml]"]
- repo: https://github.com/econchick/interrogate # check for docstrings
rev: 1.5.0
hooks:
- id: interrogate
files: ^src/
args: [--config, pyproject.toml]
pass_filenames: false # see https://github.com/econchick/interrogate/issues/60#issuecomment-1180262851
- repo: https://gitlab.com/iam-cms/pre-commit-hooks # apply Apache2 header
rev: v0.2.0
rev: v0.4.0
hooks:
- id: apache-license
files: ^src/
Expand Down
165 changes: 85 additions & 80 deletions LICENSES_THIRD_PARTY.md

Large diffs are not rendered by default.

97 changes: 62 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,61 +1,88 @@
# Makefile
# Simplifies dev install on MacOS x64 (Intel)
.PHONY: create-env dev help lint mamba uninstall
.SILENT: create-env dev help lint mamba uninstall
SHELL := /bin/bash
MAMBADL = https://github.com/conda-forge/miniforge/releases/latest/download/
MAMBAV = Mambaforge-MacOSX-x86_64.sh
MAMBARC = $(HOME)/.mambarc
MAMBARCMSG = Please create file $(MAMBARC), particularly to set platform: osx-64
MAMBADIR = $(HOME)/.mamba
# NOTE:
# + Intended for install on MacOS Apple Silicon arm64 using Accelerate
# (NOT Intel x86 using MKL via Rosetta 2)
# + Uses sh by default: to confirm shell create a recipe with $(info $(SHELL))
.PHONY: dev help install-env install-mamba lint uninstall-env uninstall-mamba
.SILENT: dev help install-env install-mamba lint uninstall-env uninstall-mamba
MAMBADL := https://github.com/conda-forge/miniforge/releases/download/23.3.1-1
MAMBAV := Miniforge3-MacOSX-arm64.sh
MAMBARCMSG := Please create file $(MAMBARC), importantly set `platform: osx-arm64`
MAMBARC := $(HOME)/.mambarc
MAMBADIR := $(HOME)/miniforge
PYTHON_DEFAULT = $(or $(shell which python3), $(shell which python))
PYTHON_ENV = $(MAMBADIR)/envs/squirrel_radar/bin/python
ifneq ("$(wildcard $(PYTHON_ENV))","")
PYTHON = $(PYTHON_ENV)
else
PYTHON = $(PYTHON_DEFAULT)
endif
VERSION := $(shell echo $(VVERSION) | sed 's/v//')

create-env: ## create mamba (conda) environment CONDA_SUBDIR=osx-64
export PATH=$(MAMBADIR)/bin:$$PATH; \
if which mamba; then echo "mamba ready"; else make mamba; fi
mamba env create --file condaenv_squirrel_radar.yml;

dev: # create env for local dev on any machine MacOS x64 (Intel)
make create-env
dev: ## create env for local dev
make install-env
export PATH=$(MAMBADIR)/envs/squirrel_radar/bin:$$PATH; \
export CONDA_ENV_PATH=$(MAMBADIR)/envs/squirrel_radar/bin; \
export CONDA_DEFAULT_ENV=squirrel_radar; \
export CONDA_SUBDIR=osx-64; \
$(PYTHON_ENV) -m pip index versions oreum_core; \
$(PYTHON_ENV) -m pip install -e .[dev]; \
export CONDA_SUBDIR=osx-arm64; \
$(PYTHON_ENV) -m pip install -e ".[dev]"; \
$(PYTHON_ENV) -c "import numpy as np; np.__config__.show()" > dev/install_log/blas_info.txt; \
pipdeptree -a > dev/install_log/pipdeptree.txt; \
pipdeptree -a -r > dev/install_log/pipdeptree_rev.txt; \
pip-licenses -saud -f markdown --output-file LICENSES_THIRD_PARTY.md; \
pre-commit install; \
pre-commit autoupdate;

help:
@echo "Use \`make <target>' where <target> is:"
@echo " dev create local dev env"
@echo " lint run code lint & security checks"
@echo " uninstall remove local dev env (use from parent dir as `make -C squirrel_radar uninstall`)"
install-env: ## create mamba (conda) environment
export PATH=$(MAMBADIR)/bin:$$PATH; \
if which mamba; then echo "mamba ready"; else make install-mamba; fi
export PATH=$(MAMBADIR)/bin:$$PATH; \
export CONDA_SUBDIR=osx-arm64; \
mamba update -n base mamba; \
mamba env create --file condaenv_squirrel_radar.yml -y;

lint: ## run code linters and static security (checks only)
$(PYTHON) -m pip install black flake8 isort
install-mamba: ## get mamba via miniforge, explicitly use bash
test -f $(MAMBARC) || { echo $(MAMBARCMSG); exit 1; }
wget $(MAMBADL)/$(MAMBAV) -O $(HOME)/miniforge.sh
chmod 755 $(HOME)/miniforge.sh
bash $(HOME)/miniforge.sh -b -p $(MAMBADIR)
export PATH=$(MAMBADIR)/bin:$$PATH; \
conda init zsh;
rm $(HOME)/miniforge.sh

lint: ## run code lint & security checks
$(PYTHON) -m pip install black flake8 interrogate isort bandit
black --check --diff --config pyproject.toml src/
isort --check-only src/
flake8 src/
interrogate src/
bandit --config pyproject.toml -r src/

mamba: ## get mamba via mambaforge for MacOS x86_64 (Intel via Rosetta2)
test -f $(MAMBARC) || { echo $(MAMBARCMSG); exit 1; }
wget $(MAMBADL)$(MAMBAV) -O $$HOME/mambaforge.sh
bash $$HOME/mambaforge.sh -b -p $$HOME/.mamba
export PATH=$$HOME/.mamba/bin:$$PATH; \
conda init zsh;
rm $$HOME/mambaforge.sh
help:
@echo "Use \make <target> where <target> is:"
@echo " dev create local dev env"
@echo " lint run code lint & security checks"
@echo " uninstall-env remove env (use from parent dir \make -C squirrel_radar ...)"


test-dev-env: ## test the dev machine install of critial numeric packages
export PATH=$(MAMBADIR)/bin:$$PATH; \
export PATH=$(MAMBADIR)/envs/squirrel_radar/bin:$$PATH; \
export CONDA_ENV_PATH=$(MAMBADIR)/envs/squirrel_radar/bin; \
export CONDA_DEFAULT_ENV=squirrel_radar; \
$(PYTHON_ENV) -c "import numpy as np; np.test()" > dev/install_log/tests_numpy.txt; \


uninstall-env: ## remove mamba env
export PATH=$(MAMBADIR)/bin:$$PATH; \
export CONDA_SUBDIR=osx-arm64; \
mamba env remove --name squirrel_radar -y; \
conda clean --all -afy;
# mamba clean -afy # 2023-12-10 see: https://github.com/mamba-org/mamba/issues/3044

uninstall: ## remove mamba env (use from parent dir as `make -C squirrel_radar/ uninstall`)
mamba env remove --name squirrel_radar -y
mamba clean -ay
uninstall-mamba: ## last ditch per https://github.com/conda-forge/miniforge#uninstallation
conda init zsh --reverse
rm -rf $(MAMBADIR)
rm -rf $(HOME)/.conda
rm -f $(HOME)/.condarc
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
Quick Implementation of the
[Squirrel Radar](https://douglassquirrel.com/radar)


[![Python](https://img.shields.io/badge/python-3.11-blue)](https://www.python.org)
[![License](https://img.shields.io/badge/license-Apache2.0-blue.svg)](https://choosealicense.com/licenses/apache-2.0/)
[![GitHub Release](https://img.shields.io/github/v/release/oreum-industries/squirrel_radar?display_name=tag&sort=semver)](https://github.com/oreum-industries/squirrel_radar/releases)
[![CI](https://github.com/oreum-industries/squirrel_radar/workflows/ci/badge.svg)](https://github.com/oreum-industries/squirrel_radar/actions/workflows/ci.yml)

[![code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![code style: flake8](https://img.shields.io/badge/code%20style-flake8-331188.svg)](https://flake8.pycqa.org/en/latest/)
[![code style: isort](https://img.shields.io/badge/code%20style-isort-%231674b1?style=flat)](https://pycqa.github.io/isort/)
[![GitHub Release](https://img.shields.io/github/v/release/oreum-industries/squirrel_radar?display_name=tag&sort=semver)](https://github.com/oreum-industries/squirrel_radar/releases)



### Contents
Expand Down Expand Up @@ -103,8 +106,14 @@ upon directory open
Notes:

+ We use `conda` virtual envs controlled by `mamba` (quicker than `conda`)
+ We install packages using `mambaforge` (sourced from the `conda-forge` repo) wherever possible and use `pip` for packages that are handled better by `pip` and/or more up-to-date on [pypi](https://pypi.org)
+ We install packages using `miniforge` (sourced from the `conda-forge` repo)
wherever possible and only use `pip` for packages that are handled better by
`pip` and/or more up-to-date on [pypi](https://pypi.org)
+ Packages might not be the very latest because we want stability for `pymc`
which is usually in a state of development flux
+ See [cheat sheet of conda commands](https://conda.io/docs/_downloads/conda-cheatsheet.pdf)
+ The `Makefile` creates a dev env and will also download and preinstall
`miniforge` if not yet installed on your system


#### 2.2.1 Create the dev environment
Expand All @@ -117,15 +126,17 @@ $> make -C squirrel_radar dev

This will also create some files to help confirm / diagnose successful installation:

+ `dev/install_log/blas_info.txt` for the `BLAS MKL` installation for `numpy`
+ `dev/install_log/pipdeptree[_rev].txt` lists installed package deps (and reversed)
+ `LICENSES_THIRD_PARTY.md` details the license for each package used


#### 2.2.2 To remove the dev environment (Useful during env install experimentation):

From the dir above `squirrel_radar/` project dir:

```zsh
$> make -C squirrel_radar uninstall
$> make -C squirrel_radar uninstall-env
```


Expand Down Expand Up @@ -216,6 +227,3 @@ See LICENSE.md.

Oreum OÜ t/a Oreum Industries, Sepapaja 6, Tallinn, 15551, Estonia,
reg.16122291, [oreum.io](https://oreum.io)

---
Oreum OÜ &copy; 2023
38 changes: 19 additions & 19 deletions condaenv_squirrel_radar.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# Manually created as-at 2022-02-15
# Last updated as-at 2023-07-31
# NOTE:
# + Creates a virtual env for project usage
# + Require running on Intel x86 AMD64 CPU (or Rosetta2 on MacOS)
# + Install with mamba via Makefile, must force MKL via libblas (note not "blas")
# + Install numpy alongside from defaults channel (the only one compiled against MKL)
# see https://github.com/conda-forge/numpy-feedstock/issues/84#issuecomment-385186685
# + This is a minimal set of packages dependent upon forcing MKL and conda-forge
# + There's also a fuller set of deps to be installed by pip in the pyproject.toml
# Manually created as-at 2023-0601
# Last updated as-at 2023-12-10
# NOTES:
# + Creates a virtual env for project development
# + Require running on Apple Silicon ARM64 (NOT Intel x86 AMD64 CPU via Rosetta2)
# + Install with mamba via Makefile, there's also a fuller set of deps to be
# installed by pip in the pyproject.toml
# + numpy not strictly needed here but because we're explcit about BLAS/LAPACK
# from acccelerate, then also get specific numpy
# also see https://numpy.org/install/ and https://github.com/numpy/numpy/pull/24053
# + libblas, libcblas, liblapack, not strictly needed here but we want to be
# explcit about forcing BLAS to use Accelerate
name: squirrel_radar
channels:
- defaults
# - conda-forge # commented out - we declare specifics per package and want numpy from defaults
- conda-forge
# - defaults
dependencies:
- numpy>=1.24.3 # NOTE: the MKL version is only available in defaults
- conda-forge::ipykernel>=6.23.1
- conda-forge::libblas=*[build=*mkl] # force MKL
- conda-forge::libcblas=*[build=*mkl] # force MKL
- conda-forge::liblapack=*[build=*mkl] # force MKL
- conda-forge::mkl==2021.4.* # NOTE 2022 version(s) dont work on MacOS https://stackoverflow.com/a/71640311/1165112
- conda-forge::mkl-service==2.4.*
- conda-forge::python==3.10.*
- conda-forge::numpy>=1.25.2 #>=1.26.2 # see NOTES
- conda-forge::libblas=*[build=*accelerate] # see NOTES
- conda-forge::libcblas=*[build=*accelerate] # see NOTES
- conda-forge::liblapack=*[build=*accelerate] # see NOTES
- conda-forge::python==3.11.*
19 changes: 15 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[project]
name = "squirrel_radar"
version = "1.0.1"
version = "1.1.0"
description = "Squirrel Radar Implemention by Oreum Industries"
readme = "README.md"
license = {file = "LICENSE.md"}
authors = [{ name = "Jonathan Sedar", email = "jonathan.sedar@oreum.io" },]
requires-python = "==3.10.*"
requires-python = "==3.11.*"
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Information Analysis",
Expand Down Expand Up @@ -42,9 +42,19 @@ dev = [
[project.urls]
homepage = "https://github.com/oreum-industries/squirrel_radar"


[tool.bandit]
skips = [
"B101", # skip asserts
"B404",
"B603",
"B607",
]


[tool.black]
line-length = 88
target-version = ["py39"]
target-version = ["py311"]
skip-string-normalization = true
skip-magic-trailing-comma = true
include = '\.py$'
Expand All @@ -58,3 +68,4 @@ verbose = true
profile = 'black'
multi_line_output = 3
skip_gitignore = true
py_version = 311

0 comments on commit 97c7df4

Please sign in to comment.