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

Start 1.3.4 branch #151

Merged
merged 26 commits into from
Oct 27, 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
59 changes: 36 additions & 23 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v3
- name: Set up Python 3.11 for linting
uses: actions/setup-python@v4.6.1
uses: actions/checkout@v4
- name: Set up Python 3.12 for linting
uses: actions/setup-python@v4.7.1
with:
python-version: '3.11'
python-version: '3.12'
- name: Install dependencies
run: |-
python -m pip install --upgrade pip
Expand All @@ -48,11 +48,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v4.6.1
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v4.7.1
with:
python-version: '3.11'
python-version: '3.12'
- name: Upgrade pip
run: |-
python -m pip install --upgrade pip
Expand Down Expand Up @@ -114,26 +114,27 @@ jobs:
os:
- ubuntu-latest
python-version:
- '3.11'
- '3.12'
arch:
- auto
steps:
- name: Checkout source
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
if: runner.os == 'Linux' && matrix.arch != 'auto'
with:
platforms: all
- name: Setup Python
uses: actions/setup-python@v4.6.1
uses: actions/setup-python@v4.7.1
with:
python-version: ${{ matrix.python-version }}
- name: Build pure wheel
shell: bash
run: |-
python -m pip install setuptools>=0.8 wheel build
python -m pip install setuptools>=0.8 wheel build twine
python -m build --wheel --outdir wheelhouse
python -m twine check ./wheelhouse/ubelt*.whl
- name: Show built files
shell: bash
run: ls -la wheelhouse
Expand Down Expand Up @@ -164,23 +165,23 @@ jobs:
install-extras: tests-strict,runtime-strict
os: windows-latest
arch: auto
- python-version: '3.11'
- python-version: '3.12'
install-extras: tests-strict,runtime-strict,optional-strict
os: ubuntu-latest
arch: auto
- python-version: '3.11'
- python-version: '3.12'
install-extras: tests-strict,runtime-strict,optional-strict
os: macOS-latest
arch: auto
- python-version: '3.11'
- python-version: '3.12'
install-extras: tests-strict,runtime-strict,optional-strict
os: windows-latest
arch: auto
- python-version: '3.11'
- python-version: '3.12'
install-extras: tests
os: windows-latest
arch: auto
- python-version: '3.11'
- python-version: '3.12'
install-extras: tests
os: windows-latest
arch: auto
Expand Down Expand Up @@ -208,6 +209,10 @@ jobs:
install-extras: tests,optional
os: windows-latest
arch: auto
- python-version: '3.12'
install-extras: tests,optional
os: windows-latest
arch: auto
- python-version: pypy-3.7
install-extras: tests,optional
os: windows-latest
Expand Down Expand Up @@ -236,6 +241,10 @@ jobs:
install-extras: tests,optional
os: windows-latest
arch: auto
- python-version: '3.12'
install-extras: tests,optional
os: windows-latest
arch: auto
- python-version: pypy-3.7
install-extras: tests,optional
os: windows-latest
Expand Down Expand Up @@ -264,6 +273,10 @@ jobs:
install-extras: tests,optional
os: windows-latest
arch: auto
- python-version: '3.12'
install-extras: tests,optional
os: windows-latest
arch: auto
- python-version: pypy-3.7
install-extras: tests,optional
os: windows-latest
Expand All @@ -282,17 +295,17 @@ jobs:
arch: auto
steps:
- name: Checkout source
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Enable MSVC 64bit
uses: ilammy/msvc-dev-cmd@v1
if: matrix.os == 'windows-latest'
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3
if: runner.os == 'Linux' && matrix.arch != 'auto'
with:
platforms: all
- name: Setup Python
uses: actions/setup-python@v4.6.1
uses: actions/setup-python@v4.7.1
with:
python-version: ${{ matrix.python-version }}
- uses: actions/download-artifact@v3
Expand Down Expand Up @@ -373,7 +386,7 @@ jobs:
- test_purepy_wheels
steps:
- name: Checkout source
uses: actions/checkout@v3
uses: actions/checkout@v4
- uses: actions/download-artifact@v3
name: Download wheels and sdist
with:
Expand Down Expand Up @@ -417,7 +430,7 @@ jobs:
- test_purepy_wheels
steps:
- name: Checkout source
uses: actions/checkout@v3
uses: actions/checkout@v4
- uses: actions/download-artifact@v3
name: Download wheels and sdist
with:
Expand Down
4 changes: 4 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Jon Crall <jon.crall@kitware.com> Jon Crall <erotemic@gmail.com>
Jon Crall <jon.crall@kitware.com> jon.crall <jon.crall@kitware.com>
Jon Crall <jon.crall@kitware.com> joncrall <erotemic@gmail.com>
Jon Crall <jon.crall@kitware.com> joncrall <jon.crall@kitware.com>
5 changes: 4 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@

# Required
version: 2
build:
os: "ubuntu-22.04"
tools:
python: "3.11"
sphinx:
configuration: docs/source/conf.py
formats: all
python:
version: 3.7
install:
- requirements: requirements/docs.txt
- method: pip
Expand Down
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,30 @@ We are currently working on porting this changelog to the specifications in
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
This project (loosely) adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Version 1.3.3 -
## Version 1.3.4 -

### Added
* Add backend option to `highlight_code` which can be "pygments" or "rich".
* Support for Python 3.12

### Changed
* Improve speed of inplace dictionary set operations.

### Fixed
* Align in the case of `nobraces=1` for `ubelt.urepr`.


## Version 1.3.3 - 2023-07-10

### Fixed

* Bug where the first call to `ub.hash_data` would error if it was given a
ndarray with object type.
* Actually exposed `ChDir`.

### Changed
* Docs and typing improvements

### Notes

* Skipped a release version due to a bad github tag.
Expand Down
19 changes: 19 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,25 @@ Libraries that contain one specific data structure or utility:
* timerit: snippet timing for benchmarks - https://github.com/Erotemic/timerit


Jaraco (i.e. Jason R. Coombs) has an extensive library of utilities:

* jaraco.classes - https://github.com/jaraco/jaraco.classes
* jaraco.collections - https://github.com/jaraco/jaraco.collections
* jaraco.context - https://github.com/jaraco/jaraco.context
* jaraco.crypto - https://github.com/jaraco/jaraco.crypto
* jaraco.functools - https://github.com/jaraco/jaraco.functools
* jaraco.geo - https://github.com/jaraco/jaraco.geo
* jaraco.imaging - https://github.com/jaraco/jaraco.imaging
* jaraco.itertools - https://github.com/jaraco/jaraco.itertools
* jaraco.logging - https://github.com/jaraco/jaraco.logging
* jaraco.media - https://github.com/jaraco/jaraco.media
* jaraco.path - https://github.com/jaraco/jaraco.path
* jaraco.text - https://github.com/jaraco/jaraco.text
* jaraco.util - https://github.com/jaraco/jaraco.util
* jaraco.windows - https://github.com/jaraco/jaraco.windows
* and many others not listed here. See: https://github.com/jaraco?tab=repositories&q=jaraco.


Ubelt is included in the the [bestof-python list](https://github.com/ml-tooling/best-of-python),
which contains many other tools that you should check out.

Expand Down
97 changes: 97 additions & 0 deletions dev/bench/bench_highlight.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""
Test if pygments or rich is faster when it comes to highlighting.

Results:
pygments is a lot faster
"""
import sys
import ubelt as ub
import warnings


def _pygments_highlight(text, lexer_name, **kwargs):
"""
Original pygments highlight logic
"""
if sys.platform.startswith('win32'): # nocover
# Hack on win32 to support colored output
try:
import colorama
if not colorama.initialise.atexit_done:
# Only init if it hasn't been done
colorama.init()
except ImportError:
warnings.warn(
'colorama is not installed, ansi colors may not work')

import pygments # type: ignore
import pygments.lexers # type: ignore
import pygments.formatters # type: ignore
import pygments.formatters.terminal # type: ignore

formatter = pygments.formatters.terminal.TerminalFormatter(bg='dark')
lexer = pygments.lexers.get_lexer_by_name(lexer_name, **kwargs)
new_text = pygments.highlight(text, lexer, formatter)
return new_text


def _rich_highlight(text, lexer_name):
"""
Alternative rich-based highlighter

References:
https://github.com/Textualize/rich/discussions/3076
"""
from rich.syntax import Syntax
from rich.console import Console
import io
syntax = Syntax(text, lexer_name, background_color='default')
stream = io.StringIO()
write_console = Console(file=stream, soft_wrap=True, color_system='standard')
write_console.print(syntax)
new_text = write_console.file.getvalue()
return new_text


def main():
# Benchmark which is faster
import timerit

lexer_name = 'python'
ti = timerit.Timerit(100, bestof=10, verbose=2)

text = 'import ubelt as ub; print(ub)'
for timer in ti.reset('small-pygments'):
pygments_text = _pygments_highlight(text, lexer_name)

for timer in ti.reset('small-rich'):
rich_text = _rich_highlight(text, lexer_name)

print(pygments_text)
print(rich_text)

# Use bigger text
try:
text = ub.Path(__file__).read_text()
except NameError:
text = ub.Path('~/code/ubelt/dev/bench/bench_highlight.py').expand().read_text()

for timer in ti.reset('big-pygments'):
pygments_text = _pygments_highlight(text, lexer_name)

for timer in ti.reset('big-rich'):
rich_text = _rich_highlight(text, lexer_name)

print(pygments_text)
print(rich_text)

print(ub.urepr(ti.measures['mean'], align=':', precision=8))
print(ub.urepr(ti.measures['min'], align=':', precision=8))


if __name__ == '__main__':
"""
CommandLine:
python ~/code/ubelt/dev/bench/bench_highlight.py
"""
main()
Loading