diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e85abd4..a15c894 100755 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.7', '3.8', '3.9', '3.10'] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] os: [ubuntu-latest , macos-latest, windows-latest] steps: - name: Checkout diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0952f55..c339f2e 100755 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -8,7 +8,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.7', '3.8', '3.9', '3.10'] + python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] os: [ubuntu-latest, macos-latest, windows-latest] steps: - name: Checkout diff --git a/Cargo.toml b/Cargo.toml index 314dbeb..d130f5c 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pywordfreq" -version = "0.3.1" +version = "0.4.0" authors = ["Gal Ben David "] edition = "2021" description = "Word frequency checker based on Wikipedia corpus written in Rust" @@ -27,6 +27,7 @@ classifier = [ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Programming Language :: Rust", ] diff --git a/README.md b/README.md index 6ca2ddc..ad3cb09 100755 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ![license](https://img.shields.io/badge/MIT-License-blue) -![Python](https://img.shields.io/badge/Python-3.7%20%7C%203.8%20%7C%203.9-blue) +![Python](https://img.shields.io/badge/Python-3.7%20%7C%203.8%20%7C%203.9%20%7C%203.10%20%7C%203.11-blue) ![OS](https://img.shields.io/badge/OS-Mac%20%7C%20Linux%20%7C%20Windows-blue) ![Build](https://github.com/intsights/pywordfreq/workflows/Build/badge.svg) [![PyPi](https://img.shields.io/pypi/v/pywordfreq.svg)](https://pypi.org/project/pywordfreq/) diff --git a/pyproject.toml b/pyproject.toml index 88fa504..6e7f691 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ sdist-include = [ [tool.poetry] name = "pywordfreq" -version = "0.3.1" +version = "0.4.0" authors = ["Gal Ben David "] description = "Word frequency checker based on Wikipedia corpus written in Rust" readme = "README.md" @@ -35,6 +35,7 @@ classifiers = [ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Programming Language :: Rust", ] diff --git a/pywordfreq/__init__.py b/pywordfreq/__init__.py index 6e0668f..424fce7 100755 --- a/pywordfreq/__init__.py +++ b/pywordfreq/__init__.py @@ -1,16 +1,32 @@ import importlib.resources +import sys from . import pywordfreq +PY_VERSION_MAJOR = sys.version_info.major +PY_VERSION_MINOR = sys.version_info.minor + def lazy_full_frequency( word, ): - pywordfreq.load_dictionary( - importlib.resources.read_binary( + if PY_VERSION_MAJOR >= 3 and PY_VERSION_MINOR >= 11: + with importlib.resources.files( + __package__, + ).joinpath( + 'word_frequencies.gz', + ).open( + 'rb', + ) as _word_frequencies_binary: + word_frequencies_binary = _word_frequencies_binary.read() + else: + word_frequencies_binary = importlib.resources.read_binary( package=__package__, resource='word_frequencies.gz', ) + + pywordfreq.load_dictionary( + word_frequencies_binary ) global full_frequency @@ -19,17 +35,31 @@ def lazy_full_frequency( full_frequency = pywordfreq.full_frequency partial_frequency = pywordfreq.partial_frequency - return pywordfreq.full_frequency(word) + return pywordfreq.full_frequency( + word + ) def lazy_partial_frequency( pattern, ): - pywordfreq.load_dictionary( - importlib.resources.read_binary( + if PY_VERSION_MAJOR >= 3 and PY_VERSION_MINOR >= 11: + with importlib.resources.files( + __package__, + ).joinpath( + 'word_frequencies.gz', + ).open( + 'rb', + ) as _word_frequencies_binary: + word_frequencies_binary = _word_frequencies_binary.read() + else: + word_frequencies_binary = importlib.resources.read_binary( package=__package__, resource='word_frequencies.gz', ) + + pywordfreq.load_dictionary( + word_frequencies_binary ) global full_frequency @@ -38,7 +68,9 @@ def lazy_partial_frequency( full_frequency = pywordfreq.full_frequency partial_frequency = pywordfreq.partial_frequency - return pywordfreq.partial_frequency(pattern) + return pywordfreq.partial_frequency( + pattern + ) full_frequency = lazy_full_frequency