diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..217a665 --- /dev/null +++ b/.flake8 @@ -0,0 +1,16 @@ +# See: +# +# https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes (E, W) +# https://flake8.pycqa.org/en/latest/user/error-codes.html (F) +# https://github.com/PyCQA/flake8-bugbear +# +# for error codes. And +# +# https://flake8.pycqa.org/en/latest/user/violations.html#selecting-violations-with-flake8 +# +# for error classes selected below. + +[flake8] +max-line-length = 80 +select = C,E,F,W,B,B950 +ignore = E501, W503 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..49fbeaa --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,31 @@ +name: Release + +on: + push: + tags: + - '*.*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Setup Python 3.10 + uses: actions/setup-python@v2 + with: + python-version: '3.10' + architecture: 'x64' + + - name: Install flit + run: pip install flit + + - name: Build + run: flit build + + - name: Publish to PyPI + env: + FLIT_USERNAME: __token__ + FLIT_PASSWORD: ${{ secrets.PYPI_TOKEN }} + run: | + flit publish diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..cc76b77 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,37 @@ +name: test + +on: [push, pull_request] + +jobs: + default: + runs-on: ${{ matrix.os }}-latest + strategy: + matrix: + os: [ubuntu] + python-version: ["3.10"] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ".[test]" + + - name: Lint + run: pre-commit run --all-files --show-diff-on-failure --color always + + - name: Test + run: | + pytest diff --git a/.gitignore b/.gitignore index 96c3ff7..b6d2083 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,29 @@ *~ +# Byte-compiled / optimized / DLL files **/__pycache__ +*.py[cod] + +# Distribution / packaging +dist/ + +# Unit test / coverage reports +.pytest_cache/ + +# General +.DS_Store + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# IntelliJ project files +.idea + +# Spyder project settings +.spyderproject +.spyproject diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..fbca482 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,23 @@ +# Install pre-commit hooks via +# pre-commit install + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.1.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/psf/black + rev: 22.1.0 + hooks: + - id: black + - repo: https://gitlab.com/pycqa/flake8 + rev: 3.8.4 + hooks: + - id: flake8 + pass_filenames: true + - repo: https://github.com/pycqa/isort + rev: 5.10.1 + hooks: + - id: isort diff --git a/Makefile b/Makefile deleted file mode 100644 index 1ab11de..0000000 --- a/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -test: - PYTHONPATH=. pytest diff --git a/README.md b/README.md index 5660700..0a04b44 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -`lazy_loader` makes it easy to load subpackages and functions on demand. +![PyPI](https://img.shields.io/pypi/v/lazy-loader?style=for-the-badge) + +`lazy-loader` makes it easy to load subpackages and functions on demand. ## Motivation @@ -7,6 +9,12 @@ For a more detailed discussion, see [the SPEC](https://scientific-python.org/specs/spec-0001/). +## Installation + +``` +pip install -U lazy-loader +``` + ## Usage ### Lazily load subpackages @@ -15,12 +23,12 @@ Consider the `__init__.py` from [scikit-image](https://scikit-image.org): ```python subpackages = [ - ... + ..., 'filters', ... ] -from lazy_loader import lazy +import lazy_loader as lazy __getattr__, __dir__, _ = lazy.attach(__name__, subpackages) ``` diff --git a/lazy_loader/__init__.py b/lazy_loader/__init__.py index f22e6f9..743fd91 100644 --- a/lazy_loader/__init__.py +++ b/lazy_loader/__init__.py @@ -1,3 +1,9 @@ +""" +lazy_loader +=========== + +Makes it easy to load subpackages and functions on demand. +""" import importlib import importlib.util import types diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..0e7b144 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,31 @@ +[build-system] +requires = ["flit_core >=3.3,<4"] +build-backend = "flit_core.buildapi" + +[project] +name = "lazy_loader" +version = "0.1rc1" +requires-python = ">=3.8" +authors = [{name = "The Scientific Python Group"}] +readme = "README.md" +license = {file = "LICENSE.md"} +classifiers = ["License :: OSI Approved :: BSD License"] +dynamic = ["description"] + +[project.optional-dependencies] +dev = [ + "flit" +] +test = [ + "pytest", + "black", + "pre-commit", + "flake8" +] + +[project.urls] +Home = "https://scientific-python.org/specs/spec-0001/" +Source = "https://github.com/scientific-python/lazy-loader" + +[tool.flit.sdist] +exclude = ["tests/*"]