From fc04c12475cb50e917703da0e486b5011917c636 Mon Sep 17 00:00:00 2001 From: "K.B.Dharun Krishna" Date: Thu, 27 Mar 2025 22:37:18 +0530 Subject: [PATCH 1/8] feat: migrate setup.py to pyproject (with hatch backend), misc Signed-off-by: K.B.Dharun Krishna --- .github/workflows/publish.yml | 13 +++--- README.md | 3 +- pyproject.toml | 85 +++++++++++++++++++++++++++++++++-- setup.py | 60 ------------------------- tldr.py | 4 +- 5 files changed, 93 insertions(+), 72 deletions(-) delete mode 100644 setup.py diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7863dfd..18808a1 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -36,16 +36,16 @@ jobs: working-directory: docs run: make man - - name: Install pep517 + - name: Install build run: - python -m pip install pep517 --user + python -m pip install build --user - name: Build a binary wheel and a source tarball run: >- - python -m pep517.build - --source - --binary - --out-dir dist/ + python -m build + --sdist + --wheel + --outdir dist/ . - name: Attest generated files @@ -61,6 +61,7 @@ jobs: pypi-publish: runs-on: ubuntu-latest + if: github.repository == 'tldr-pages/tldr-python-client' needs: ['release-build'] environment: diff --git a/README.md b/README.md index b06705a..66c1818 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # tldr-python-client [![PyPI Release](https://img.shields.io/pypi/v/tldr.svg)](https://pypi.python.org/pypi/tldr) -[![Build](https://github.com/tldr-pages/tldr-python-client/workflows/Test/badge.svg?branch=main)](https://github.com/tldr-pages/tldr-python-client/actions?query=branch%3Amain) +[![Test](https://github.com/tldr-pages/tldr-python-client/actions/workflows/test.yml/badge.svg)](https://github.com/tldr-pages/tldr-python-client/actions/workflows/test.yml) +[![CodeQL](https://github.com/tldr-pages/tldr-python-client/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/tldr-pages/tldr-python-client/actions/workflows/github-code-scanning/codeql) [![Snap Release](https://snapcraft.io/tldr/badge.svg)](https://snapcraft.io/tldr) Python command-line client for [tldr pages](https://github.com/tldr-pages/tldr). diff --git a/pyproject.toml b/pyproject.toml index 2ca7184..9728e0c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,4 +1,83 @@ [build-system] -# Minimum requirements for the build system to execute. -requires = ["setuptools", "wheel"] # PEP 508 specifications. -build-backend = "setuptools.build_meta" +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "tldr" +dynamic = ["version"] +description = "Python command line client for tldr." +readme = "README.md" +license = "MIT" +requires-python = "~=3.9" +authors = [ + { name = "Felix Yan and tldr-pages contributors" }, +] +keywords = [ + "tldr", + "tldr-pages", + "cheatsheets", + "man", + "manpages", + "documentation" +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Intended Audience :: End Users/Desktop", + "Intended Audience :: Developers", + "Intended Audience :: Education" + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Operating System :: Android", + "Operating System :: MacOS :: MacOS X", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX", + "Operating System :: POSIX :: BSD :: FreeBSD", + "Operating System :: POSIX :: BSD :: NetBSD", + "Operating System :: POSIX :: BSD :: OpenBSD", + "Operating System :: POSIX :: Linux", + "Operating System :: POSIX :: SunOS/Solaris", + "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", + "Topic :: Documentation", + "Topic :: Software Development :: Documentation", + "Topic :: System", + "Topic :: Utilities", +] +dependencies = [ + "colorama; sys_platform=='win32'", + "shtab>=1.3.10", + "termcolor", +] +[project.optional-dependencies] +cli = [ + "pytest", + "pytest-runner", + "flake8", + "sphinx", + "sphinx-argparse" +] + +[project.scripts] +tldr = "tldr:cli" + +[project.urls] +Homepage = "https://tldr.sh" +Source = "https://github.com/tldr-pages/tldr-python-client" +Issues = "https://github.com/tldr-pages/tldr-python-client/issues" +Changelog = "https://github.com/tldr-pages/tldr-python-client/blob/main/CHANGELOG.md" +Funding = "https://liberapay.com/tldr-pages" + +[tool.hatch.version] +path = "tldr/__init__.py" + +[tool.hatch.build.targets.wheel.shared-data] +"docs/man" = "share/man/man1" + +[tool.hatch.build.targets.sdist] +include = [ + "/tldr", +] diff --git a/setup.py b/setup.py deleted file mode 100644 index 489f62d..0000000 --- a/setup.py +++ /dev/null @@ -1,60 +0,0 @@ -from pathlib import Path -import re -from setuptools import setup - -setup_dir = Path(__file__).resolve().parent -version = re.search( - r'__version__ = "(.*)"', - Path(setup_dir, 'tldr.py').open().read() -) -if version is None: - raise SystemExit("Could not determine version to use") -version = version.group(1) - -with open('requirements.txt') as f: - required = f.read().splitlines() - -setup( - name='tldr', - author='Felix Yan and tldr-pages contributors', - url='https://github.com/tldr-pages/tldr-python-client', - description='command line client for tldr', - long_description=Path(setup_dir, 'README.md').open().read(), - long_description_content_type='text/markdown', - license='MIT', - py_modules=['tldr'], - entry_points={ - "console_scripts": [ - "tldr = tldr:cli" - ] - }, - data_files=[('share/man/man1', ['docs/man/tldr.1'])], - install_requires=required, - tests_require=[ - 'pytest', - 'pytest-runner', - ], - version=version, - python_requires='~=3.9', - classifiers=[ - "Development Status :: 5 - Production/Stable", - "License :: OSI Approved :: MIT License", - "Environment :: Console", - "Intended Audience :: End Users/Desktop", - "Natural Language :: English", - "Operating System :: POSIX :: Linux", - "Operating System :: POSIX :: SunOS/Solaris", - "Operating System :: POSIX :: BSD :: FreeBSD", - "Operating System :: POSIX :: BSD :: NetBSD", - "Operating System :: POSIX :: BSD :: OpenBSD", - "Operating System :: MacOS :: MacOS X", - "Operating System :: Microsoft :: Windows", - "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", - "Topic :: Utilities", - "Topic :: System" - ] -) diff --git a/tldr.py b/tldr.py index 4b596a6..ee6f8f7 100755 --- a/tldr.py +++ b/tldr.py @@ -9,17 +9,17 @@ from zipfile import ZipFile from datetime import datetime from io import BytesIO -import ssl from typing import List, Optional, Tuple, Union from urllib.parse import quote from urllib.request import urlopen, Request from urllib.error import HTTPError, URLError from termcolor import colored +import ssl import shtab import shutil __version__ = "3.3.0" -__client_specification__ = "2.2" +__client_specification__ = "2.3" REQUEST_HEADERS = {'User-Agent': 'tldr-python-client'} PAGES_SOURCE_LOCATION = os.environ.get( From 70cfc713f2ab79d27ce8001fccd69b3fcdd5805b Mon Sep 17 00:00:00 2001 From: "K.B.Dharun Krishna" Date: Thu, 27 Mar 2025 22:38:02 +0530 Subject: [PATCH 2/8] fix: typo Signed-off-by: K.B.Dharun Krishna --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9728e0c..7f5f15c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ classifiers = [ "Environment :: Console", "Intended Audience :: End Users/Desktop", "Intended Audience :: Developers", - "Intended Audience :: Education" + "Intended Audience :: Education", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: Android", From c2334dc6af8d29f220b043ee87def92e4da17b04 Mon Sep 17 00:00:00 2001 From: "K.B.Dharun Krishna" Date: Thu, 27 Mar 2025 22:41:01 +0530 Subject: [PATCH 3/8] fix: dynamic versioning for hatch Signed-off-by: K.B.Dharun Krishna --- pyproject.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 7f5f15c..19c6b24 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,7 +72,8 @@ Changelog = "https://github.com/tldr-pages/tldr-python-client/blob/main/CHANGELO Funding = "https://liberapay.com/tldr-pages" [tool.hatch.version] -path = "tldr/__init__.py" +path = "tldr.py" +pattern = '__version__ = ["\'](.*?)[\'\"]' [tool.hatch.build.targets.wheel.shared-data] "docs/man" = "share/man/man1" From 7ff0f5211bdefd77e1e0d866bd5b16e5c6fa7bfb Mon Sep 17 00:00:00 2001 From: "K.B.Dharun Krishna" Date: Thu, 27 Mar 2025 22:45:43 +0530 Subject: [PATCH 4/8] test: updated file Signed-off-by: K.B.Dharun Krishna --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 19c6b24..2ee0cdb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,5 +80,5 @@ pattern = '__version__ = ["\'](.*?)[\'\"]' [tool.hatch.build.targets.sdist] include = [ - "/tldr", + "tldr.py" ] From 5df19e4a4ae522d9ecbe2c5a55fb162e95eb4fb4 Mon Sep 17 00:00:00 2001 From: "K.B.Dharun Krishna" Date: Thu, 27 Mar 2025 22:47:43 +0530 Subject: [PATCH 5/8] test: update dynamic version regex Signed-off-by: K.B.Dharun Krishna --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2ee0cdb..a275095 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,7 +73,7 @@ Funding = "https://liberapay.com/tldr-pages" [tool.hatch.version] path = "tldr.py" -pattern = '__version__ = ["\'](.*?)[\'\"]' +pattern = '''__version__ = ["'](.*?)["']''' [tool.hatch.build.targets.wheel.shared-data] "docs/man" = "share/man/man1" From d293d6e09f584a599b814055d5810bfe9cc4470c Mon Sep 17 00:00:00 2001 From: "K.B.Dharun Krishna" Date: Thu, 27 Mar 2025 22:49:57 +0530 Subject: [PATCH 6/8] test: use attr for version instead of regex Signed-off-by: K.B.Dharun Krishna --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a275095..b66fa1a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,7 +73,7 @@ Funding = "https://liberapay.com/tldr-pages" [tool.hatch.version] path = "tldr.py" -pattern = '''__version__ = ["'](.*?)["']''' +attr = "__version__" [tool.hatch.build.targets.wheel.shared-data] "docs/man" = "share/man/man1" From d7d5b0091869310cc9911b0d995d4477c52de74f Mon Sep 17 00:00:00 2001 From: "K.B.Dharun Krishna" Date: Thu, 27 Mar 2025 23:49:50 +0530 Subject: [PATCH 7/8] fix: add missing sdists Signed-off-by: K.B.Dharun Krishna --- pyproject.toml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b66fa1a..1a71ee3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,5 +80,11 @@ attr = "__version__" [tool.hatch.build.targets.sdist] include = [ - "tldr.py" + "tldr.py", + "README.md", + "LICENSE.md", + "CHANGELOG.md", + "tests/test_tldr.py", + "tests/data/**", + "docs/**", ] From 4bad4aba3cbb70cf2178733d0f29053c7d9c0d71 Mon Sep 17 00:00:00 2001 From: "K.B.Dharun Krishna" Date: Thu, 27 Mar 2025 23:58:04 +0530 Subject: [PATCH 8/8] cleanup: only include required files in sdist Signed-off-by: K.B.Dharun Krishna --- pyproject.toml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1a71ee3..aeaacd8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,7 +84,5 @@ include = [ "README.md", "LICENSE.md", "CHANGELOG.md", - "tests/test_tldr.py", - "tests/data/**", - "docs/**", + "docs/man/tldr.1", ]