Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 3.12 and drop 3.7 #99

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
build:
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
Expand All @@ -38,14 +38,14 @@ jobs:
- name: Build dist and test with unittest
if: matrix.os != 'windows-latest'
run: |
python setup.py sdist bdist_wheel
python -m build
if [ -f requirements-test.txt ]; then pip install -r requirements-test.txt; fi
pip install dist/*.whl
python -m unittest
- name: Build dist and test with unittest on Windows
if: matrix.os == 'windows-latest'
run: |
python setup.py sdist bdist_wheel
python -m build
if (Test-Path -Path '.\requirements-test.txt' -PathType Leaf) {pip install -r requirements-test.txt}
pip install (Get-ChildItem dist/*.whl)
python -m unittest
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ on:
branches: [ master ]

jobs:
flake8-lint:
lint:
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: ${{ matrix.python-version }}
- name: Install flake8
run: pip install flake8
- name: Run flake8
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install twine setuptools wheel
pip install build twine setuptools wheel
- name: Build source tar
run: |
python setup.py sdist bdist_wheel
python -m build
- name: Publish wheels to PyPI
continue-on-error: true
env:
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
refresh: clean build install lint

build:
python setup.py build
python -m build

install:
python setup.py install
pip install .

build_dist:
make clean
python setup.py sdist bdist_wheel
python -m build
pip install dist/*.whl
make test

Expand Down
2 changes: 1 addition & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2020-2021 Tian Gao
Copyright 2020-2023 Tian Gao

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,6 @@ Please send bug reports and feature requests through [github issue tracker](http

## License

Copyright Tian Gao, 2020-2021.
Copyright 2020-2023 Tian Gao.

Distributed under the terms of the [Apache 2.0 license](https://github.com/gaogaotiantian/objprint/blob/master/LICENSE).
29 changes: 29 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "objprint"
authors = [{name = "Tian Gao", email = "[email protected]"}]
description = "A library that can print Python objects in human readable format"
readme = "README.md"
requires-python = ">=3.6"
license = {file = "LICENSE"}
dynamic = ["version"]
classifiers = [
"Development Status :: 4 - Beta",
"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",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent"
]

[project.urls]
Homepage = "https://github.com/gaogaotiantian/objprint"

[tool.setuptools.dynamic]
version = {attr = "objprint.__version__"}
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
flake8
setuptools
wheel
Expand Down
40 changes: 0 additions & 40 deletions setup.py

This file was deleted.

44 changes: 1 addition & 43 deletions src/objprint/frame_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import ast
import inspect
import io
import sys
import tokenize
from types import FrameType
from typing import List, Optional
Expand Down Expand Up @@ -60,48 +59,7 @@ def get_executing_function_call_str(self, frame: FrameType) -> Optional[str]:
except OSError:
return None

if sys.version_info < (3, 8):
return self.get_source_segment3637(source, node)
else:
return ast.get_source_segment(source, node)

def get_source_segment3637(self, source: str, node: ast.AST) -> str:
if node.lineno is None or node.col_offset is None: # pragma: no cover
return None
lineno = node.lineno - 1
lines = self._splitlines_no_ff(source)
first_line = lines[lineno].encode()[node.col_offset:].decode()
lines = lines[lineno + 1:]
lines.insert(0, first_line)
return "".join(lines)

def _splitlines_no_ff(self, source: str) -> List[str]: # pragma: no cover
"""Split a string into lines ignoring form feed and other chars.
This mimics how the Python parser splits source code.

:copyright: Copyright 2008 by Armin Ronacher.
:license: Python License.
from https://github.com/python/cpython/blob/main/Lib/ast.py
license: https://github.com/python/cpython/blob/main/LICENSE
"""
idx = 0
lines = []
next_line = ''
while idx < len(source):
c = source[idx]
next_line += c
idx += 1
# Keep \r\n together
if c == '\r' and idx < len(source) and source[idx] == '\n':
next_line += '\n'
idx += 1
if c in '\r\n':
lines.append(next_line)
next_line = ''

if next_line:
lines.append(next_line)
return lines
return ast.get_source_segment(source, node)

def return_object(self, frame: Optional[FrameType]) -> bool:
if frame is None:
Expand Down
2 changes: 1 addition & 1 deletion src/objprint/objprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def _get_line(key: str) -> str:
if cfg.label and any(re.fullmatch(pattern, key) is not None for pattern in cfg.label):
return set_color(f".{key} = {val}", COLOR.YELLOW)
elif cfg.color:
return f"{set_color('.'+key, COLOR.GREEN)} = {val}"
return f"{set_color('.' + key, COLOR.GREEN)} = {val}"
else:
return f".{key} = {val}"

Expand Down
2 changes: 1 addition & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_formatter(self):
op(a)
self.assertEqual(buf.getvalue(), "[0xa, 0xd, 0x10]\n")

op.register_formatter(float, lambda x: f"Float: {round(x,3)}")
op.register_formatter(float, lambda x: f"Float: {round(x, 3)}")
with io.StringIO() as buf, redirect_stdout(buf):
op(3.14159)
self.assertEqual(buf.getvalue(), "Float: 3.142\n")
Expand Down