From 37069925259ea06008461538c3ae95ee4e87682f Mon Sep 17 00:00:00 2001 From: Pamphile Roy Date: Tue, 1 Mar 2022 21:11:31 +0100 Subject: [PATCH 1/3] Add the packaging infrastructure --- .flake8 | 16 +++++++++++++++ .github/workflows/release.yml | 31 ++++++++++++++++++++++++++++ .github/workflows/test.yml | 38 +++++++++++++++++++++++++++++++++++ .gitignore | 27 +++++++++++++++++++++++++ .pre-commit-config.yaml | 23 +++++++++++++++++++++ README.md | 14 ++++++++++--- pyproject.toml | 28 ++++++++++++++++++++++++++ 7 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 .flake8 create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml 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..36ad00f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,38 @@ +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 flit + flit install + + - 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/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/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..cf5e5c0 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,28 @@ +[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] +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/*"] From f0d3c9d68549e8e3ee5a86ca7072e4d6801988f5 Mon Sep 17 00:00:00 2001 From: Pamphile Roy Date: Tue, 1 Mar 2022 21:59:04 +0100 Subject: [PATCH 2/3] Fix package name --- .github/workflows/test.yml | 3 +-- lazy_loader/__init__.py | 6 ++++++ pyproject.toml | 5 ++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 36ad00f..cc76b77 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,8 +27,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flit - flit install + pip install ".[test]" - name: Lint run: pre-commit run --all-files --show-diff-on-failure --color always 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 index cf5e5c0..0e7b144 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["flit_core >=3.3,<4"] build-backend = "flit_core.buildapi" [project] -name = "lazy-loader" +name = "lazy_loader" version = "0.1rc1" requires-python = ">=3.8" authors = [{name = "The Scientific Python Group"}] @@ -13,6 +13,9 @@ classifiers = ["License :: OSI Approved :: BSD License"] dynamic = ["description"] [project.optional-dependencies] +dev = [ + "flit" +] test = [ "pytest", "black", From bae737ed5cadf46b0cc33a74185e42d6a73fdbc7 Mon Sep 17 00:00:00 2001 From: Pamphile Roy Date: Tue, 1 Mar 2022 22:00:25 +0100 Subject: [PATCH 3/3] Remove makefile --- Makefile | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 1ab11de..0000000 --- a/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -test: - PYTHONPATH=. pytest