Skip to content

Commit

Permalink
Merge pull request #170 from facelessuser/chore/hatch
Browse files Browse the repository at this point in the history
Use hatchling backend
  • Loading branch information
facelessuser authored May 21, 2022
2 parents 4fb595f + 609d26c commit 85bbe61
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 222 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ jobs:
max-parallel: 4
matrix:
platform: [ubuntu-latest, windows-latest]
python-version: [3.6, 3.7, 3.8, 3.9, '3.10']
python-version: [3.7, 3.8, 3.9, '3.10', '3.11-dev']
include:
- python-version: 3.6
tox-env: py36
- python-version: 3.7
tox-env: py37
- python-version: 3.8
Expand All @@ -29,6 +27,11 @@ jobs:
tox-env: py39
- python-version: '3.10'
tox-env: py310
- python-version: '3.11-dev'
tox-env: py311
exclude:
- platform: windows-latest
python-version: '3.11-dev'

env:
TOXENV: ${{ matrix.tox-env }}
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ jobs:
- name: Package sdist
if: matrix.distribution == 'sdist'
run: |
pip install --upgrade setuptools wheel
python setup.py ${{ matrix.distribution }}
pip install --upgrade setuptools wheel build
python -m build -s
- name: Package bdist_wheel
if: matrix.distribution == 'bdist_wheel'
run: |
pip install --upgrade setuptools wheel
python setup.py ${{ matrix.distribution }} --python-tag py3${{ matrix.python-3-version}}
pip install --upgrade setuptools wheel build
python -m build -w
- name: Upload artifacts
uses: actions/upload-artifact@v2
Expand All @@ -81,7 +81,7 @@ jobs:
path: dist

- name: Publish
uses: pypa/gh-action-pypi-publish@v1.4.1
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_PWD }}
19 changes: 0 additions & 19 deletions MANIFEST.in

This file was deleted.

2 changes: 1 addition & 1 deletion backrefs/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,5 @@ def parse_version(ver: str) -> Version:
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(5, 2, 0, "final")
__version_info__ = Version(5, 3, 0, "final")
__version__ = __version_info__._get_canonical()
4 changes: 2 additions & 2 deletions backrefs/_bre_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def get_flags(self, i: _util.StringIter, scoped: bool = False) -> Optional[str]:
toggle = False
elif scoped and c == '-':
toggle = True
elif not _util.PY37 and scoped and c in _GLOBAL_FLAGS:
elif scoped and c in _GLOBAL_FLAGS:
raise ValueError("Bad flag")
elif c not in _GLOBAL_FLAGS and c not in _SCOPED_FLAGS:
raise ValueError("Bad flag")
Expand Down Expand Up @@ -593,7 +593,7 @@ def _parse(self, search: str) -> str:
self.verbose = bool(self.re_verbose)
self.unicode = bool(self.re_unicode)
self.global_flag_swap = {
"unicode": ((self.re_unicode is not None) if not _util.PY37 else False),
"unicode": False,
"verbose": False
}
self.temp_global_flag_swap = {
Expand Down
23 changes: 8 additions & 15 deletions backrefs/_bregex_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@
import regex # type: ignore[import]
import sys

if sys.version_info >= (3, 7):
from typing import _alias # type: ignore[attr-defined]

if sys.version_info >= (3, 9):
Pattern = _alias(type(regex.compile('')), 1)
Match = _alias(type(regex.compile('').match('')), 1)
else:
Pattern = _alias(type(regex.compile('')), AnyStr)
Match = _alias(type(regex.compile('').match('')), AnyStr)

elif sys.version_info:
from typing import _TypeAlias # type: ignore[attr-defined]

Pattern = _TypeAlias('Pattern', AnyStr, type(regex.compile('')), lambda p: p.pattern)
Match = _TypeAlias('Match', AnyStr, type(regex.compile('').match('')), lambda m: m.re.pattern)
from typing import _alias # type: ignore[attr-defined]

if sys.version_info >= (3, 9):
Pattern = _alias(type(regex.compile('')), 1)
Match = _alias(type(regex.compile('').match('')), 1)
else:
Pattern = _alias(type(regex.compile('')), AnyStr)
Match = _alias(type(regex.compile('').match('')), AnyStr)
5 changes: 1 addition & 4 deletions backrefs/uniprops/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
"""Unicode Properties."""
from . import unidata
import sys
from typing import Optional

UNICODE_RANGE = '\u0000-\U0010ffff'
ASCII_RANGE = '\x00-\xff'

PY37 = sys.version_info >= (3, 7)

MODE_NORMAL = 0
MODE_ASCII = 1
MODE_UNICODE = 2
Expand Down Expand Up @@ -555,7 +552,7 @@ def get_unicode_property(prop: str, value: Optional[str] = None, mode: int = MOD
return get_nfkc_quick_check_property(value, mode)
elif name == 'nfkdquickcheck':
return get_nfkd_quick_check_property(value, mode)
elif PY37 and name == 'verticalorientation':
elif name == 'verticalorientation':
return get_vertical_orientation_property(value, mode)
else:
raise ValueError("'{}={}' does not have a valid property name".format(prop, value))
Expand Down
3 changes: 0 additions & 3 deletions backrefs/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
Licensed under MIT
Copyright (c) 2015 - 2020 Isaac Muse <[email protected]>
"""
import sys
import warnings
from typing import Tuple, Any, List, Callable, AnyStr

PY37 = (3, 7) <= sys.version_info

FMT_FIELD = 0
FMT_INDEX = 1
FMT_ATTR = 2
Expand Down
1 change: 1 addition & 0 deletions docs/src/dictionary/en-custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Sep
Tox
Twemoji
accessor
backend
boolean
decrement
deprecations
Expand Down
7 changes: 6 additions & 1 deletion docs/src/markdown/about/changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Changelog

## 5.3

- **NEW**: Drop Python 3.6 support.
- **NEW**: Update build backend to use Hatch.

## 5.2

- **NEW**: Add static typing.
- **NEW**: Add type annotations.
- **FIX**: Re format replacement captures behave more like Regex in that you can technically index into the captures of
a given group in Re, but in Re there is only ever one or zero captures. Documentation was never really explicit on
what one should expect if indexing a group in Re occurred. The documentation seemed to vaguely insinuate that it would
Expand Down
96 changes: 96 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""Dynamically define some metadata."""
import os
import sys
import importlib.util
from hatchling.metadata.plugin.interface import MetadataHookInterface
from hatchling.builders.hooks.plugin.interface import BuildHookInterface


def get_version_dev_status(root):
"""Get version_info without importing the entire module."""

path = os.path.join(root, "backrefs", "__meta__.py")
spec = importlib.util.spec_from_file_location("__meta__", path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module.__version_info__._get_dev_status()


def get_requirements(root, requirements):
"""Load list of dependencies."""

install_requires = []
with open(os.path.join(root, requirements)) as f:
for line in f:
if not line.startswith("#"):
install_requires.append(line.strip())
return install_requires


def get_unicodedata():
"""Download the `unicodedata` version for the given Python version."""

import unicodedata

uver = unicodedata.unidata_version
path = os.path.join(os.path.dirname(__file__), 'tools', 'unidatadownload.py')
spec = importlib.util.spec_from_file_location("unidatadownload", path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
module.get_unicodedata(uver, no_zip=True)
return uver


def generate_unicode_table():
"""Generate the Unicode table for the given Python version."""

uver = get_unicodedata()
path = os.path.join(os.path.dirname(__file__), 'tools', 'unipropgen.py')
spec = importlib.util.spec_from_file_location("unipropgen", path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

module.build_tables(
os.path.join(
os.path.dirname(__file__),
'backrefs', 'uniprops', 'unidata'
),
uver
)


class CustomBuildHook(BuildHookInterface):
"""Build hook."""

def initialize(self, version, build_data):
"""Setup the build tag."""

if self.target_name != 'wheel':
return

build_data['tag'] = f'py{"".join([str(x) for x in sys.version_info[:2]])}-none-any'
generate_unicode_table()


class CustomMetadataHook(MetadataHookInterface):
"""Our metadata hook."""

def update(self, metadata):
"""See https://ofek.dev/hatch/latest/plugins/metadata-hook/ for more information."""

metadata["dependencies"] = get_requirements(self.root, 'requirements/project.txt')
metadata['optional-dependencies'] = {'extras': get_requirements(self.root, "requirements/extras.txt")}
metadata["classifiers"] = [
f"Development Status :: {get_version_dev_status(self.root)}",
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Topic :: Software Development :: Libraries :: Python Modules',
'Typing :: Typed'
]
68 changes: 64 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,74 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
"hatchling>=0.21.1",
]
build-backend = "hatchling.build"

build-backend = "setuptools.build_meta"
[project]
name = "backrefs"
description = "A wrapper around re and regex that adds additional back references.'"
readme = "README.md"
license = "MIT"
requires-python = ">=3.7"
authors = [
{ name = "Isaac Muse", email = "[email protected]" },
]
keywords = [
"regex",
"re"
]
dynamic = [
"classifiers",
"dependencies",
"version",
"optional-dependencies"
]

[project.urls]
Homepage = "https://github.com/facelessuser/backrefs"

[tool.hatch.version]
source = "code"
path = "backrefs/__meta__.py"

[tool.hatch.build.targets.sdist]
include = [
"/docs/src/markdown/**/*.md",
"/docs/src/markdown/**/*.gif",
"/docs/src/markdown/**/*.png",
"/docs/src/markdown/dictionary/*.txt",
"/docs/theme/**/*.css",
"/docs/theme/**/*.js",
"/docs/theme/**/*.html",
"/requirements/*.txt",
"/backrefs/**/*.py",
"/backrefs/py.typed",
"/tests/**/*.py",
"/tools/**/*.py",
"/tools/unicodedata/*.zip",
"/tools/unicodedata/LICENSE",
"/.pyspelling.yml",
"/.coveragerc",
"/mkdocs.yml",
"/tox.ini",
]

exclude = [
"backrefs/uniprops/unidata/*"
]

[tool.hatch.build.targets.wheel]
ignore-vcs = true
include = [
"/backrefs"
]

[tool.hatch.build.hooks.custom]
[tool.hatch.metadata.hooks.custom]

[tool.mypy]
files = [
"backrefs/*.py"
"backrefs"
]
strict = true
show_error_codes = true
Expand Down
2 changes: 1 addition & 1 deletion requirements/docs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mkdocs_pymdownx_material_extras==1.5.4
mkdocs_pymdownx_material_extras>=2.0
mkdocs-git-revision-date-localized-plugin
mkdocs-minify-plugin
pyspelling
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

Loading

0 comments on commit 85bbe61

Please sign in to comment.