Skip to content

Commit

Permalink
Migrate to pyproject.toml; use ruff (#83)
Browse files Browse the repository at this point in the history
* Migrate to pyproject.toml; use ruff

* tox -e lint

* Update readme

* Prevent unnecessary builds

* Remove __version__

* Update publishing workflow

adapted from https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
  • Loading branch information
sloria authored Jan 18, 2024
1 parent 5f840ea commit dc966d3
Show file tree
Hide file tree
Showing 18 changed files with 148 additions and 150 deletions.
56 changes: 39 additions & 17 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: build
on:
push:
branches: ["main"]
tags: ["*"]
pull_request:

jobs:
tests:
name: ${{ matrix.name }}
Expand All @@ -13,39 +16,58 @@ jobs:
- { name: "3.8", python: "3.8", tox: py38 }
- { name: "3.12", python: "3.12", tox: py312 }
steps:
- uses: actions/checkout@v3.1.0
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
python-version: ${{ matrix.python }}
- run: python -m pip install --upgrade pip
- run: python -m pip install tox
- run: python -m tox -e${{ matrix.tox }}
build:
if: startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install pypa/build
run: python3 -m pip install build --user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/
# this duplicates pre-commit.ci, so only run it on tags
# it guarantees that linting is passing prior to a release
lint-pre-release:
name: lint
if: startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.1.0
- uses: actions/setup-python@v4.3.0
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- run: python -m pip install --upgrade pip
- run: python -m pip install tox
- run: python -m tox -elint
release:
needs: [tests, lint-pre-release]
publish-to-pypi:
name: PyPI release
if: startsWith(github.ref, 'refs/tags')
if: startsWith(github.ref, 'refs/tags/')
needs: [build, tests, lint-pre-release]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/ped
permissions:
id-token: write
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
- name: install requirements
run: python -m pip install build twine
- name: build dists
run: python -m build
- name: check package metadata
run: twine check dist/*
- name: publish
run: twine upload -u __token__ -p ${{ secrets.PYPI_API_TOKEN }} dist/*
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ target/
.konchrc
test-output
.mypy_cache

# ruff
.ruff_cache
28 changes: 12 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/psf/black
rev: 23.12.1
- id: ruff
- id: ruff-format
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.3
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear==23.12.2]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
- id: check-github-workflows
- id: check-readthedocs
- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.12.1]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
5 changes: 0 additions & 5 deletions MANIFEST.in

This file was deleted.

6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ This was inspired by `IPython's <https://ipython.org/>`_ ``%edit`` magic.
Changelog
*********

2.2.0 (unreleased)
3.0.0 (unreleased)
------------------

- Publish type information.
- Test against Python 3.8-3.12. Older versions of Python are no longer supported.

- *Backwards-incompatible*: Remove ``ped.__version__`` attribute.
Use ``importlib.metadata.version("ped")`` instead.

2.1.0 (2020-03-18)
------------------
Expand Down
66 changes: 63 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,63 @@
[tool.black]
line-length = 88
target-version = ['py38', 'py39', 'py310', 'py311', 'py312']
[project]
name = "ped"
version = "2.1.0"
description = "Quickly open Python modules in your text editor."
readme = "README.rst"
license = { file = "LICENSE" }
authors = [{ name = "Steven Loria", email = "[email protected]" }]
classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: System :: Shells",
]
keywords = ["commandline", "cli", "open", "editor", "editing"]
requires-python = ">=3.8"

[project.scripts]
ped = "ped:main"

[project.urls]
Issues = "https://github.com/sloria/ped/issues"
Source = "https://github.com/sloria/ped/"

[project.optional-dependencies]
dev = ["ped[tests]", "tox"]
tests = ["pytest", "pytest-mock", "scripttest==1.3"]

[build-system]
requires = ["flit_core<4"]
build-backend = "flit_core.buildapi"

[tool.flit.sdist]
include = ["tests/", "NOTICE", "tox.ini"]
exclude = ["tests/test-output"]

[tool.ruff]
src = ["src"]
fix = true
show-fixes = true
show-source = true

[tool.ruff.lint]
select = [
"B", # flake8-bugbear
"E", # pycodestyle error
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"W", # pycodestyle warning
]

[tool.mypy]
ignore_missing_imports = true
warn_unreachable = true
warn_unused_ignores = true
warn_redundant_casts = true
no_implicit_optional = true
18 changes: 0 additions & 18 deletions setup.cfg

This file was deleted.

69 changes: 0 additions & 69 deletions setup.py

This file was deleted.

29 changes: 17 additions & 12 deletions ped/__init__.py → src/ped/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
Example: ped django.core.urlresolvers
"""
from types import ModuleType
from typing import Optional, Tuple, Any
import argparse
import importlib
import importlib.metadata
import inspect
import os
import shlex
import subprocess
import sys

from .guess_module import guess_module, get_names_by_prefix
from .pypath import patch_sys_path
from .style import print_error, style, sprint, GREEN
from pathlib import Path
from types import ModuleType
from typing import Any, Optional, Tuple

__version__ = "2.1.0"
from .guess_module import get_names_by_prefix, guess_module
from .pypath import patch_sys_path
from .style import GREEN, print_error, sprint, style


def main() -> None:
Expand Down Expand Up @@ -47,7 +46,9 @@ def parse_args() -> argparse.Namespace:
parser.add_argument(
"-e", "--editor", type=str, dest="editor", help="editor program"
)
parser.add_argument("-v", "--version", action="version", version=__version__)
parser.add_argument(
"-v", "--version", action="version", version=importlib.metadata.version("ped")
)
parser.add_argument(
"-i",
"--info",
Expand Down Expand Up @@ -89,13 +90,15 @@ def get_info(ipath: str) -> Tuple[str, str, Optional[int]]:
module_name = ipath
try:
obj = import_object(module_name)
except ImportError:
except ImportError as error:
guessed = guess_module(ipath)
if guessed:
module_name = guessed[0]
obj = import_object(module_name)
else:
raise ImportError(f'Cannot find any module that matches "{ipath}"')
raise ImportError(
f'Cannot find any module that matches "{ipath}"'
) from error
fpath = find_file(obj)
if not fpath:
raise ImportError(f'Cannot find any module that matches "{ipath}"')
Expand All @@ -113,8 +116,10 @@ def import_object(ipath: str) -> ModuleType:
mod = importlib.import_module(module_name)
try:
return getattr(mod, symbol_name)
except AttributeError:
raise ImportError(f'Cannot import "{symbol_name}" from "{module_name}"')
except AttributeError as error:
raise ImportError(
f'Cannot import "{symbol_name}" from "{module_name}"'
) from error
raise err


Expand Down
2 changes: 1 addition & 1 deletion ped/guess_module.py → src/ped/guess_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Much of this code is adapted from IPython.core.completerlib
(see NOTICE for license information).
"""
from typing import List, Generator
import difflib
import inspect
import os
Expand All @@ -12,6 +11,7 @@
import time
import zipimport
from importlib.machinery import all_suffixes
from typing import Generator, List

_suffixes = all_suffixes()

Expand Down
Loading

0 comments on commit dc966d3

Please sign in to comment.