From cdb1732ad2f5079dfaa6735808fdd28204bebe1c Mon Sep 17 00:00:00 2001 From: KOLANICH Date: Thu, 10 Nov 2022 13:54:29 +0300 Subject: [PATCH 1/7] Added `pyproject.toml` according to `PEP 517`. --- docs/usage.md | 4 ++-- pyproject.toml | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 pyproject.toml diff --git a/docs/usage.md b/docs/usage.md index 2a5b78c..f5305b3 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -22,8 +22,8 @@ Clone the repository from https://github.com/Alir3z4/html2text ``` $ git clone --depth 1 https://github.com/Alir3z4/html2text.git -$ python setup.py build -$ python setup.py install +$ python -m build -nwx +$ python -m pip install --upgrade ./dist/*.whl ``` diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b464d1d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=42.2"] +build-backend = "setuptools.build_meta" From d2019a6a4a6bb1e206a9a5b7707afb2b90ee6c95 Mon Sep 17 00:00:00 2001 From: KOLANICH Date: Thu, 10 Nov 2022 14:00:41 +0300 Subject: [PATCH 2/7] Removed `setup.py` - it is no longer needed. --- setup.py | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 setup.py diff --git a/setup.py b/setup.py deleted file mode 100644 index 6068493..0000000 --- a/setup.py +++ /dev/null @@ -1,3 +0,0 @@ -from setuptools import setup - -setup() From b33e73cfc2353f70c5a9738c0019dd6dfa55f9bb Mon Sep 17 00:00:00 2001 From: KOLANICH Date: Thu, 10 Nov 2022 13:57:23 +0300 Subject: [PATCH 3/7] Started using `setuptools_scm` for a better version number containing git commit hash. --- pyproject.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b464d1d..899e056 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,5 @@ [build-system] -requires = ["setuptools>=42.2"] +requires = ["setuptools>=42.2", "setuptools_scm[toml]>=3.4.3"] build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] From ebd94fae0581df47f6c643865ae25adf1433be35 Mon Sep 17 00:00:00 2001 From: KOLANICH Date: Thu, 10 Nov 2022 14:10:35 +0300 Subject: [PATCH 4/7] Started using `setuptools_scm` for fetching version automatically from git tags. --- .gitignore | 2 ++ docs/usage.md | 2 +- html2text/__init__.py | 4 +--- pyproject.toml | 1 + setup.cfg | 1 - 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 047a2c1..f5b7f4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +/html2text/_version.py + *.py[co] *.bak build diff --git a/docs/usage.md b/docs/usage.md index f5305b3..f22b56c 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -21,7 +21,7 @@ $ pip install html2text Clone the repository from https://github.com/Alir3z4/html2text ``` -$ git clone --depth 1 https://github.com/Alir3z4/html2text.git +$ git clone --depth 50 https://github.com/Alir3z4/html2text.git $ python -m build -nwx $ python -m pip install --upgrade ./dist/*.whl ``` diff --git a/html2text/__init__.py b/html2text/__init__.py index c59ae16..e9dc74f 100644 --- a/html2text/__init__.py +++ b/html2text/__init__.py @@ -9,6 +9,7 @@ from typing import Dict, List, Optional, Tuple, Union from . import config +from ._version import __version_tuple__ as __version__ from .elements import AnchorElement, ListElement from .typing import OutCallback from .utils import ( @@ -27,9 +28,6 @@ unifiable_n, ) -__version__ = (2020, 1, 16) - - # TODO: # Support decoded entities with UNIFIABLE. diff --git a/pyproject.toml b/pyproject.toml index 899e056..5c61825 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,3 +3,4 @@ requires = ["setuptools>=42.2", "setuptools_scm[toml]>=3.4.3"] build-backend = "setuptools.build_meta" [tool.setuptools_scm] +write_to = "html2text/_version.py" diff --git a/setup.cfg b/setup.cfg index 6ba62eb..fb10c46 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,5 @@ [metadata] name = html2text -version = attr: html2text.__version__ description = Turn HTML into equivalent Markdown-structured text. long_description = file: README.md long_description_content_type = text/markdown From 5dfa9a5aa9dc4801487e0356ae003cc8dd4a0c59 Mon Sep 17 00:00:00 2001 From: KOLANICH Date: Thu, 10 Nov 2022 14:17:08 +0300 Subject: [PATCH 5/7] Migrated the metadata into `PEP 621`-compliant `pyproject.toml`. --- pyproject.toml | 52 +++++++++++++++++++++++++++++++++++++++++++++++++- setup.cfg | 50 ------------------------------------------------ 2 files changed, 51 insertions(+), 51 deletions(-) delete mode 100644 setup.cfg diff --git a/pyproject.toml b/pyproject.toml index 5c61825..8a813b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,56 @@ [build-system] -requires = ["setuptools>=42.2", "setuptools_scm[toml]>=3.4.3"] +requires = ["setuptools>=61.2", "setuptools_scm[toml]>=3.4.3"] build-backend = "setuptools.build_meta" +[project] +name = "html2text" +description = "Turn HTML into equivalent Markdown-structured text." +readme = "README.md" +authors = [{name = "Aaron Swartz", email = "me@aaronsw.com"}] +maintainers = [{name = "Alireza Savand", email = "alireza.savand@gmail.com"}] +license = {text = "GNU GPL 3"} +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU General Public License (GPL)", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", +] +urls = {Homepage = "https://github.com/Alir3z4/html2text/"} +requires-python = ">=3.5" +dynamic = ["version"] + +[project.scripts] +html2text = "html2text.cli:main" + +[tool.setuptools] +zip-safe = false +packages = ["html2text"] +platforms = ["OS Independent"] +include-package-data = false + +[tool.setuptools.package-data] +html2text = ["py.typed"] + [tool.setuptools_scm] write_to = "html2text/_version.py" + +[tool.flake8] # you will need Flake8-pyproject +max_line_length = "88" +extend-ignore = "E203" + +[tool.isort] +profile = "black" +combine_as_imports = true + +[tool.mypy] +python_version = "3.5" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index fb10c46..0000000 --- a/setup.cfg +++ /dev/null @@ -1,50 +0,0 @@ -[metadata] -name = html2text -description = Turn HTML into equivalent Markdown-structured text. -long_description = file: README.md -long_description_content_type = text/markdown -url = https://github.com/Alir3z4/html2text/ -author = Aaron Swartz -author_email = me@aaronsw.com -maintainer = Alireza Savand -maintainer_email = alireza.savand@gmail.com -license = GNU GPL 3 -classifiers = - Development Status :: 5 - Production/Stable - Intended Audience :: Developers - License :: OSI Approved :: GNU General Public License (GPL) - Operating System :: OS Independent - Programming Language :: Python - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.5 - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3 :: Only - Programming Language :: Python :: Implementation :: CPython - Programming Language :: Python :: Implementation :: PyPy -platform = OS Independent - -[options] -zip_safe = False -packages = html2text -python_requires = >=3.5 - -[options.entry_points] -console_scripts = - html2text = html2text.cli:main - -[options.package_data] -html2text = py.typed - -[flake8] -max_line_length = 88 -extend-ignore = E203 - -[isort] -combine_as_imports = True -profile = black - -[mypy] -python_version = 3.5 From 4cd75f07abe6447f6ca7e6d3a96bf4f5146e9df9 Mon Sep 17 00:00:00 2001 From: Alireza Savand Date: Mon, 14 Apr 2025 14:32:10 +0400 Subject: [PATCH 6/7] Final cleanups on modernization of build process. --- README.md | 28 ++++++++++++++++++++++++---- html2text/__init__.py | 4 +++- html2text/cli.py | 3 ++- pyproject.toml | 25 +++++++++++++++++-------- tox.ini | 28 ++++++++++++++++++---------- 5 files changed, 64 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 9b7f607..15ff7a4 100644 --- a/README.md +++ b/README.md @@ -62,21 +62,41 @@ Hello, [world](https://www.google.com/earth/)! `html2text` is available on pypi https://pypi.org/project/html2text/ -``` +```shell $ pip install html2text ``` +## Development -## How to run unit tests +### How to run unit tests - tox +```shell +$ tox +``` To see the coverage results: - coverage html +```shell +$ coverage html +``` then open the `./htmlcov/index.html` file in your browser. + +### Code Quality & Pre Commit + +The CI runs several linting steps, including: + +- mypy +- Flake8 +- Black + +To make sure the code passes the CI linting steps, run: + +```shell +$ tox -e pre-commit +``` + ## Documentation Documentation lives [here](https://github.com/Alir3z4/html2text/blob/master/docs/usage.md) diff --git a/html2text/__init__.py b/html2text/__init__.py index 6d135ac..621fa74 100644 --- a/html2text/__init__.py +++ b/html2text/__init__.py @@ -9,8 +9,8 @@ from typing import Dict, List, Optional, Tuple, Union from . import config -from ._version import __version_tuple__ as __version__ from ._typing import OutCallback +from ._version import __version_tuple__ from .elements import AnchorElement, ListElement from .utils import ( control_character_replacements, @@ -29,6 +29,8 @@ unifiable_n, ) +__version__ = __version_tuple__ + # TODO: # Support decoded entities with UNIFIABLE. diff --git a/html2text/cli.py b/html2text/cli.py index 202a77f..e19a099 100644 --- a/html2text/cli.py +++ b/html2text/cli.py @@ -1,7 +1,8 @@ import argparse import sys -from . import HTML2Text, __version__, config +from . import HTML2Text, config +from ._version import __version_tuple__ as __version__ def main() -> None: diff --git a/pyproject.toml b/pyproject.toml index 8a813b9..6e6aa6c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,25 +8,24 @@ description = "Turn HTML into equivalent Markdown-structured text." readme = "README.md" authors = [{name = "Aaron Swartz", email = "me@aaronsw.com"}] maintainers = [{name = "Alireza Savand", email = "alireza.savand@gmail.com"}] -license = {text = "GNU GPL 3"} +license = "GPL-3.0-or-later" classifiers = [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", - "License :: OSI Approved :: GNU General Public License (GPL)", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "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", + "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ] urls = {Homepage = "https://github.com/Alir3z4/html2text/"} -requires-python = ">=3.5" +requires-python = ">=3.9" dynamic = ["version"] [project.scripts] @@ -44,6 +43,15 @@ html2text = ["py.typed"] [tool.setuptools_scm] write_to = "html2text/_version.py" +[tool.black] +line-length = 88 +target-version = ['py313'] +extend-exclude = ''' +/( + html2text/_version.py +) +''' + [tool.flake8] # you will need Flake8-pyproject max_line_length = "88" extend-ignore = "E203" @@ -51,6 +59,7 @@ extend-ignore = "E203" [tool.isort] profile = "black" combine_as_imports = true +extend_skip = ["html2text/_version.py"] [tool.mypy] -python_version = "3.5" +python_version = "3.9" diff --git a/tox.ini b/tox.ini index d2e10f6..ceadecc 100644 --- a/tox.ini +++ b/tox.ini @@ -18,29 +18,37 @@ setenv = [testenv:black] basepython = python3 -commands = - black --target-version py38 --line-length 88 --check --diff . -deps = - black +commands = black --check --diff . +deps = black skip_install = true [testenv:flake8] basepython = python3 -commands = - flake8 --max-line-length 88 +commands = flake8 deps = flake8 + Flake8-pyproject skip_install = true [testenv:isort] basepython = python3 -commands = - isort --check-only --diff . -deps = - isort +commands = isort --check-only --diff . +deps = isort skip_install = true [testenv:mypy] commands = mypy --strict html2text deps = mypy + +[testenv:pre-commit] +basepython = python3 +commands = + isort --atomic . + flake8 + black . +deps = + isort + flake8 + Flake8-pyproject + black skip_install = true From 4597cc5eacb85ac7cf5bef929a66a482314c316d Mon Sep 17 00:00:00 2001 From: Alireza Savand Date: Tue, 15 Apr 2025 07:47:32 +0400 Subject: [PATCH 7/7] Adding verbosity and printing the hash of the build on PyPI publishing. --- .github/workflows/pypi.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 99ead71..ecdfc07 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -28,3 +28,6 @@ jobs: - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + with: + verbose: true + print-hash: true