Skip to content

Commit

Permalink
Ruff's the codebase (#237)
Browse files Browse the repository at this point in the history
* Switches to pyproject

* Deploy on master

* Ruffs the codebase

* Removal of format

* Removes % format

* Canonicalizes docstrings

* Removes versioneer

* Updates to fully using hatch, removes old setup files

* hatch version stubs

* Updates for hatch vcs

* Updates test

* Additional ruff options

* Onem ore ruff flag

* Moves workflows to main branch

* Adds mypy overrides

* MyPy fixes

* Removes old ordered dict
  • Loading branch information
dgasmith committed Jul 14, 2024
1 parent 94c62a0 commit 1992f4a
Show file tree
Hide file tree
Showing 39 changed files with 342 additions and 2,878 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/Docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Docs
on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- main

jobs:
deploy:
Expand All @@ -25,7 +25,7 @@ jobs:
- name: Build Docs
run: mkdocs build

# Only deploy if master, otherwise just build for testing
# Only deploy if main, otherwise just build for testing
- name: Deploy
if: endsWith(github.ref, '/master')
if: endsWith(github.ref, '/main')
run: mkdocs gh-deploy --force
37 changes: 24 additions & 13 deletions .github/workflows/Linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Linting

on:
push:
branches: master
branches: main
pull_request:
branches: master
branches: main

jobs:
mypy:
Expand Down Expand Up @@ -46,26 +46,37 @@ jobs:
run: |
mypy opt_einsum
black:
name: Black
ruff:
name: Ruff
strategy:
fail-fast: false
matrix:
python-version: [3.12]
environment: ["min-deps"]

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Python Setup
uses: actions/[email protected]
- uses: conda-incubator/setup-miniconda@v3
with:
python-version: 3.8
python-version: ${{ matrix.python-version }}
mamba-version: "*"
channel-priority: true
activate-environment: test
environment-file: devtools/conda-envs/${{ matrix.environment }}-environment.yaml

- name: Create Environment
shell: bash
- name: Environment Information
shell: bash -l {0}
run: |
python -m pip install --upgrade pip
python -m pip install black
conda info
conda list
conda config --show-sources
conda config --show
- name: Lint
shell: bash
shell: bash -l {0}
run: |
set -e
black opt_einsum --check
make format-check
6 changes: 3 additions & 3 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Tests

on:
push:
branches: master
branches: main
pull_request:
branches: master
branches: main

jobs:
miniconda-setup:
Expand All @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
include:
- python-version: 3.9
- python-version: 3.8
environment: "min-deps"
- python-version: 3.12
environment: "min-deps"
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Hatch replaces this file
opt_einsum/_version.py

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
9 changes: 0 additions & 9 deletions MANIFEST.in

This file was deleted.

21 changes: 5 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
.DEFAULT_GOAL := all
isort = isort opt_einsum scripts/
black = black opt_einsum scripts/
autoflake = autoflake -ir --remove-all-unused-imports --ignore-init-module-imports --remove-unused-variables opt_einsum scripts/
mypy = mypy --ignore-missing-imports opt_einsum scripts/

.PHONY: install
install:
pip install -e .

.PHONY: format
format:
$(autoflake)
$(isort)
$(black)
ruff check opt_einsum --fix
ruff format opt_einsum

.PHONY: format-check
format-check:
$(isort) --check-only
$(black) --check

.PHONY: check-dist
check-dist:
python setup.py check -ms
python setup.py sdist
twine check dist/*
ruff check opt_einsum
ruff format --check opt_einsum

.PHONY: mypy
mypy:
$(mypy)
mypy opt_einsum

.PHONY: test
test:
Expand Down
6 changes: 2 additions & 4 deletions devtools/conda-envs/full-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- conda-forge
dependencies:
# Base depends
- python >=3.9
- python >=3.8
- numpy >=1.23
- nomkl

Expand All @@ -15,10 +15,8 @@ dependencies:
- jax

# Testing
- autoflake
- black
- codecov
- isort
- mypy
- pytest
- pytest-cov
- ruff ==0.5.*
6 changes: 2 additions & 4 deletions devtools/conda-envs/min-deps-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ channels:
- conda-forge
dependencies:
# Base depends
- python >=3.9
- python >=3.8

# Testing
- autoflake
- black
- codecov
- isort
- mypy
- pytest
- pytest-cov
- ruff ==0.5.*
6 changes: 2 additions & 4 deletions devtools/conda-envs/min-ver-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- conda-forge
dependencies:
# Base depends
- python >=3.9
- python >=3.8
- numpy >=1.23
- nomkl

Expand All @@ -12,10 +12,8 @@ dependencies:
- dask ==2021.*

# Testing
- autoflake
- black
- codecov
- isort
- mypy
- pytest
- pytest-cov
- ruff ==0.5.*
6 changes: 2 additions & 4 deletions devtools/conda-envs/torch-only-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ channels:
- conda-forge
dependencies:
# Base depends
- python >=3.9
- python >=3.8
- pytorch::pytorch >=2.0,<3.0.0a
- pytorch::cpuonly
- mkl

# Testing
- autoflake
- black
- codecov
- isort
- mypy
- pytest
- pytest-cov
- ruff ==0.5.*
13 changes: 3 additions & 10 deletions opt_einsum/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""
Main init function for opt_einsum.
"""
"""Main init function for opt_einsum."""

from opt_einsum import blas, helpers, path_random, paths
from opt_einsum._version import __version__
from opt_einsum.contract import contract, contract_expression, contract_path
from opt_einsum.parser import get_symbol
from opt_einsum.path_random import RandomGreedy
from opt_einsum.paths import BranchBound, DynamicProgramming
from opt_einsum.sharing import shared_intermediates

__all__ = [
"__version__",
"blas",
"helpers",
"path_random",
Expand All @@ -24,13 +24,6 @@
"shared_intermediates",
]

# Handle versioneer
from opt_einsum._version import get_versions # isort:skip

versions = get_versions()
__version__ = versions["version"]
__git_revision__ = versions["full-revisionid"]
del get_versions, versions

paths.register_path_fn("random-greedy", path_random.random_greedy)
paths.register_path_fn("random-greedy-128", path_random.random_greedy_128)
Loading

0 comments on commit 1992f4a

Please sign in to comment.