From f25619e11147208b1a21264fbdfc2cd86cd06bc1 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Thu, 30 Mar 2023 14:06:12 +0100 Subject: [PATCH 01/33] Move to hatch for dev --- pyproject.toml | 68 ++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 74 -------------------------------------------------- 2 files changed, 68 insertions(+), 74 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f905ec1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,68 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "accessible-pygments" +version = "0.0.4" +description = "A collection of accessible pygments styles" +readme = "README.md" +license = "BSD-3-Clause" +requires-python = ">=3.9" +authors = [ + { name = "Stephannie Jimenez Gacha", email = "steff456@hotmail.com" }, +] +keywords = ["a11", "accessibility", "pygments", "WCAG", "Sphinx"] +classifiers = [ + "Intended Audience :: Developers", + "Intended Audience :: Education", + "Intended Audience :: Information Technology", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Topic :: Software Development :: Libraries :: Python Modules", +] +dependencies = ["pygments >= 1.5"] + +[project.entry-points."pygments.styles"] +a11y-dark = "a11y_pygments.a11y_dark.style:Theme" +a11y-high-contrast-dark = "a11y_pygments.a11y_high_contrast_dark.style:Theme" +a11y-high-contrast-light = "a11y_pygments.a11y_high_contrast_light.style:Theme" +a11y-light = "a11y_pygments.a11y_light.style:Theme" +blinds-dark = "a11y_pygments.blinds_dark.style:Theme" +blinds-light = "a11y_pygments.blinds_light.style:Theme" +github-dark = "a11y_pygments.github_dark.style:Theme" +github-dark-colorblind = "a11y_pygments.github_dark_colorblind.style:Theme" +github-dark-high-contrast = "a11y_pygments.github_dark_high_contrast.style:Theme" +github-light = "a11y_pygments.github_light.style:Theme" +github-light-colorblind = "a11y_pygments.github_light_colorblind.style:Theme" +github-light-high-contrast = "a11y_pygments.github_light_high_contrast.style:Theme" +gotthard-dark = "a11y_pygments.gotthard_dark.style:Theme" +gotthard-light = "a11y_pygments.gotthard_light.style:Theme" +greative = "a11y_pygments.greative.style:Theme" +pitaya-smoothie = "a11y_pygments.pitaya_smoothie.style:Theme" + +[project.urls] +Homepage = "https://github.com/Quansight-Labs/accessible-pygments" + +[tool.hatch.version] +path = "a11y_pygments/__init__.py" + +[tool.hatch.build.targets.sdist] +include = ["/a11y_pygments"] + +[tool.hatch.envs.dev.scripts] +render_html = "python test/run_tests.py" +css = "python test/run_css.py" + +# testing environment and tasks +[tool.hatch.envs.test] +dependencies = ["hypothesis", "pytest"] + +[tool.hatch.envs.test.scripts] +tests = "python -m pytest test/test_*.py" diff --git a/setup.py b/setup.py deleted file mode 100644 index 36db5d7..0000000 --- a/setup.py +++ /dev/null @@ -1,74 +0,0 @@ -import ast -import os -from setuptools import setup, find_packages - -from a11y_pygments.utils.utils import find_all_themes_packages - - -def find_entrypoints(): - themes = find_all_themes_packages() - entrypoints = [] - base_package = 'a11y_pygments' - for theme in themes: - name = theme.replace('_', '-') - package = '{}.{}.style:Theme'.format(base_package, theme) - entrypoints.append('{} = {}'.format(name, package)) - print(entrypoints) - return entrypoints - - -def get_long_description(): - with open(os.path.join( - os.path.dirname(os.path.abspath(__file__)), 'README.md' - ), encoding='utf8') as fp: - return fp.read() - - -def get_version(module='a11y_pygments'): - """Get version.""" - dir = os.path.dirname(os.path.abspath(__file__)) - path = os.path.join(dir, module, '__init__.py') - with open(path, 'r') as f: - data = f.read() - lines = data.split('\n') - for line in lines: - if line.startswith('VERSION_INFO'): - version_tuple = ast.literal_eval(line.split('=')[-1].strip()) - version = '.'.join(map(str, version_tuple)) - break - return version - - -setup ( - name='accessible-pygments', - version=get_version(), - description='A collection of accessible pygments styles', - long_description=get_long_description(), - long_description_content_type='text/markdown', - license='BSD', - keywords='pygments style accessible a11', - - author='Stephannie Jimenez Gacha', - author_email='steff456@hotmail.com', - - url='https://github.com/Quansight-Labs/accessible-pygments', - - packages=find_packages(exclude=['test']), - install_requires=[ - 'pygments >= 1.5' - ], - - entry_points ={ - "pygments.styles": find_entrypoints() - }, - - classifiers=[ - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 3', - 'Topic :: Software Development :: Libraries :: Python Modules', - ] -) From 6ff7733a4d11f3d7d74cb1aa001b11e166c8b1ce Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Thu, 30 Mar 2023 16:06:01 +0100 Subject: [PATCH 02/33] :white_check_mark: Add contrast utils and test --- a11y_pygments/utils/wcag_contrast.py | 106 +++++++++++++++++++++++++++ test/test_contrast.py | 49 +++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 a11y_pygments/utils/wcag_contrast.py create mode 100644 test/test_contrast.py diff --git a/a11y_pygments/utils/wcag_contrast.py b/a11y_pygments/utils/wcag_contrast.py new file mode 100644 index 0000000..a355e3e --- /dev/null +++ b/a11y_pygments/utils/wcag_contrast.py @@ -0,0 +1,106 @@ +# Methods to calculate WCAG contrast ratio and check if it passes AA or AAA +# https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html + +from typing import Tuple, Union +import re + + +def hex_to_rgb(hex: int) -> Tuple[int, int, int]: + """Convert a hex defined colour to RGB. + + Args: + hex (string): color in hex format (#rrggbb/#rgb) + + Returns: + rgb: tuple of rgb values ``(r, g, b, a)``, where each channel (red, green, blue, + alpha) can assume values between 0 and 1. + """ + # hex color in #rrggbb format + match = re.match(r"\A#[a-fA-F0-9]{6}\Z", hex) + if match: + return tuple(int(n, 16) / 255 for n in [hex[1:3], hex[3:5], hex[5:7]]) + # hex color in #rgb format, shorthand for #rrggbb. + match = re.match(r"\A#[a-fA-F0-9]{3}\Z", hex) + if match: + return tuple(int(n, 16) / 255 for n in [hex[1] * 2, hex[2] * 2, hex[3] * 2]) + + +def sRGB_channel(v: float) -> float: + """Colors need to be normalised (from a sRGB space) before computing the relative + luminance. + + Args: + v (float): r,g,b channels values between 0 and 1 + + Returns: + float: sRGB channel value for a given rgb color channel + """ + if v <= 0.04045: + return v / 12.92 + else: + return ((v + 0.055) / 1.055) ** 2.4 + + +def relative_luminance(color: Tuple[int, int, int]) -> float: + """Compute the relative luminance of a color. + + Args: + color (tuple): rgb color tuple ``(r, g, b)`` + + Returns: + float: relative luminance of a color + """ + r, g, b = color + r = sRGB_channel(r) + g = sRGB_channel(g) + b = sRGB_channel(b) + + return 0.2126 * r + 0.7152 * g + 0.0722 * b + + +def contrast_ratio(color1: Tuple[int, int, int], color2: Tuple[int, int, int]) -> float: + """Compute the contrast ratio between two colors. + + Args: + color1 (tuple): rgb color tuple ``(r, g, b)`` + color2 (tuple): rgb color tuple ``(r, g, b)`` + + Returns: + float: contrast ratio between two colors + """ + + l1 = relative_luminance(color1) + l2 = relative_luminance(color2) + + if l1 > l2: + return (l1 + 0.05) / (l2 + 0.05) + else: + return (l2 + 0.05) / (l1 + 0.05) + + +def passes_contrast( + color1: Tuple[int, int, int], color2: Tuple[int, int, int], level="AA" +) -> Union[bool, float]: + """Method to verify the contrast ratio between two colours. + + Args: + color1 (tuple): rgb color tuple ``(r, g, b)`` + color2 (tuple): rgb color tuple ``(r, g, b)`` + level (str, optional): WCAG contrast level. Defaults to "AA". + """ + + if level not in ["AA", "AAA"]: + raise ValueError("level must be either 'AA' or 'AAA'") + + ratio = contrast_ratio(color1, color2) + + if level == "AA": + if ratio >= 4.5: + return round(ratio, 2) + else: + return False + elif level == "AAA": + if ratio >= 7.0: + return round(ratio, 2) + else: + return False diff --git a/test/test_contrast.py b/test/test_contrast.py new file mode 100644 index 0000000..86df41d --- /dev/null +++ b/test/test_contrast.py @@ -0,0 +1,49 @@ +from hypothesis import given +from hypothesis.strategies import floats, tuples +import pytest + +from a11y_pygments.utils import wcag_contrast as wcag + +color_channel = floats(0.0, 1.0) +color = tuples(color_channel, color_channel, color_channel) + + +@pytest.mark.parametrize( + "rgb1,rgb2,expected", + [ + [(0.0, 0.0, 0.0), (1.0, 1.0, 1.0), 21.0], + [(0.0, 0.0, 0.0), (0.0, 0.0, 0.0), 1.0], + [(0.0, 198 / 255.0, 0.0), (0.0, 0.0, 198 / 255.0), 5.000229313902297], + ], +) +def test_luminance(rgb1, rgb2, expected): + c1 = wcag.contrast_ratio(rgb1, rgb2) + c2 = wcag.contrast_ratio(rgb2, rgb1) + assert c1 == expected + assert c2 == expected + + +@pytest.mark.parametrize( + "c1,c2, expected", + [ + ("#0a1103", "#0a1103", False), + ("#F1AAC4", "#FEF8FA", False), + ("#610C2B", "#FEF8FA", 12.55), + ("#1B78CA", "#FEF8FA", False), + ("#1B78CA", "#FEF8FA", False), + ("#2E3A89", "#FEF8FA", 9.61), + ("#0B3254", "#0B3254", False), + ("#FBE9F0", "#0B3254", 11.27), + ], +) +def test_passes_contrast(c1, c2, expected): + got = wcag.passes_contrast(wcag.hex_to_rgb(c1), wcag.hex_to_rgb(c2), "AA") + assert got == expected + + +@given(color, color) +def test_contrast(rgb1, rgb2): + c1 = wcag.contrast_ratio(rgb1, rgb2) + c2 = wcag.contrast_ratio(rgb2, rgb1) + assert 1.0 <= c1 <= 21.0 + assert c1 == c2 From 0b7112a513444b5ed9fbb290bea4926138d516e5 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Fri, 31 Mar 2023 16:18:26 +0100 Subject: [PATCH 03/33] :art: Use pathlib --- a11y_pygments/utils/utils.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/a11y_pygments/utils/utils.py b/a11y_pygments/utils/utils.py index 9d3836b..3d46059 100644 --- a/a11y_pygments/utils/utils.py +++ b/a11y_pygments/utils/utils.py @@ -1,5 +1,5 @@ import os -import os.path as osp +from pathlib import Path from typing import List from pygments.formatters import HtmlFormatter @@ -35,18 +35,17 @@ def generate_css(themes: List[str], save_dir=""): formatter = HtmlFormatter(style=style, full=True, hl_lines=[2, 3, 4]) css = formatter.get_style_defs() color = style.style_for_token(Text)["color"] - css += "\n .highlight { background: %s; color: #%s; }" % ( - style.background_color, - color, + css += ( + f"\n.highlight {{ background: {style.background_color}; color: #{color}; }}" ) package = theme.replace("-", "_") - out = osp.join(basedir, package, "style.css") + out = Path(basedir) / package / "style.css" with open(out, "w") as f: f.write(css) if save_dir: - if not osp.exists(osp.join(save_dir, "css")): - os.mkdir(osp.join(save_dir, "css")) - out = osp.join(save_dir, "css", package + "-style.css") + if not Path(save_dir).joinpath("css").exists(): + os.mkdir(Path(save_dir).joinpath("css")) + out = Path(save_dir).joinpath("css", f"{package}-style.css") with open(out, "w") as f: f.write(css) From f42cf310c5b3baf2f348b58193e8b863ac59ffbf Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Fri, 31 Mar 2023 16:19:56 +0100 Subject: [PATCH 04/33] Update docs --- CONTRIBUTING.md | 19 +++++++++++++------ RELEASE.md | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 044dbff..9e306dc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,24 +21,31 @@ Welcome! And thanks for taking your time to contribute to this project ๐Ÿคฉ Please share your thoughts for fixes and features in the issue tracker. When doing so, please a clear description and provide useful environment information. +Please share your thoughts for fixes and features in the issue tracker. Add a clear description, and please provide useful environment information. -## Creating your development environment ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป ๐Ÿ‘จ๐Ÿผโ€๐Ÿ’ป +## Contributing to this package For creating your development environment locally you will need to have the following tools installed: +### Prerequisites ๐Ÿ“ฆ + - ๐Ÿ An environment manager like `conda` or `pyenv` - ๐Ÿ“ `git` - Python >= 3.9 + You will need to have the following installed locally: -### Fork this repository โฌ +- `git` +- Python >= 3.9 +- [hatch](https://hatch.pypa.io/) -Fork this repository to your profile and clone it to your local machine: +### Creating your development environment ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป ๐Ÿ‘จ๐Ÿผโ€๐Ÿ’ป -```bash -git clone -``` +1. Fork this repository to your GitHub account, and clone it to your local machine: Remember that this fork is a copy of the repository and any change done in it doesn't affect the original one. +`bash git clone ` + +Remember that this fork is a copy of the repository and any change done in it doesn't damage the original one. ### Install dependencies ๐Ÿ’ฝ diff --git a/RELEASE.md b/RELEASE.md index b02e64d..761bfc0 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,6 +1,6 @@ # Release -Please follow the instructions to make a new release of the accessibility pygments package. +Please follow the instructions to make a new release of the `accessible pygments` package. - `git fetch && git pull` - `git clean -xdfi` From b6ef88a7f57bdc8f98d9e10c0eec12446513a063 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Fri, 31 Mar 2023 16:26:21 +0100 Subject: [PATCH 05/33] :memo: Update documentation --- CONTRIBUTING.md | 51 +++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9e306dc..6cfede0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,9 +4,9 @@ Welcome! And thanks for taking your time to contribute to this project ๐Ÿคฉ - [Contributing to accessible pygments themes](#contributing-to-accessible-pygments-themes) - [Submit an issue ๐Ÿ“ฌ](#submit-an-issue-) - - [Creating your development environment ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป ๐Ÿ‘จ๐Ÿผโ€๐Ÿ’ป](#creating-your-development-environment--) - - [Fork this repository โฌ](#fork-this-repository-) - - [Install dependencies ๐Ÿ’ฝ](#install-dependencies-) + - [Contributing to this package](#contributing-to-this-package) + - [Prerequisites ๐Ÿ“ฆ](#prerequisites-) + - [Creating your development environment ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป ๐Ÿ‘จ๐Ÿผโ€๐Ÿ’ป](#creating-your-development-environment--) - [Run the tests ๐Ÿƒ๐Ÿปโ€โ™€๏ธ ๐Ÿƒโ€โ™‚๏ธ](#run-the-tests-๏ธ-๏ธ) - [Adding a new theme ๐ŸŽจ](#adding-a-new-theme-) - [Where to add a new theme ๐Ÿ‘ฉ๐Ÿผโ€๐ŸŽจ](#where-to-add-a-new-theme-) @@ -29,10 +29,7 @@ For creating your development environment locally you will need to have the foll ### Prerequisites ๐Ÿ“ฆ -- ๐Ÿ An environment manager like `conda` or `pyenv` -- ๐Ÿ“ `git` -- Python >= 3.9 - You will need to have the following installed locally: +You will need to have the following installed locally: - `git` - Python >= 3.9 @@ -40,25 +37,36 @@ For creating your development environment locally you will need to have the foll ### Creating your development environment ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป ๐Ÿ‘จ๐Ÿผโ€๐Ÿ’ป -1. Fork this repository to your GitHub account, and clone it to your local machine: +1. Fork this repository to your GitHub account, then clone it to your local machine: -Remember that this fork is a copy of the repository and any change done in it doesn't affect the original one. -`bash git clone ` + ```bash + git clone + ``` -Remember that this fork is a copy of the repository and any change done in it doesn't damage the original one. + Remember that this fork is a copy of the repository and any change done in it doesn't affect the original one. -### Install dependencies ๐Ÿ’ฝ +2. From here you can create your local environments with hatch: -Once you have the local clone in your machine, you need to install the dependencies. -You can create a new environment for this project and install the dependencies there: + ```bash + hatch env create + ``` -```bash -conda create -n a11y-pygments-dev python=3.9 -conda activate a11y-pygments-dev -pip install -e . -``` +3. You can verify that the environment was created successfully by running: -After running these instructions you will have an environment named `a11y-pygments-dev`, with the requirements installed and this package installed in development version. + ```console + $ hatch env show + โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“ + โ”ƒ Name โ”ƒ Type โ”ƒ Dependencies โ”ƒ Scripts โ”ƒ + โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ + โ”‚ default โ”‚ virtual โ”‚ โ”‚ โ”‚ + โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค + โ”‚ dev โ”‚ virtual โ”‚ โ”‚ css โ”‚ + โ”‚ โ”‚ โ”‚ โ”‚ render_html โ”‚ + โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค + โ”‚ test โ”‚ virtual โ”‚ hypothesis โ”‚ tests โ”‚ + โ”‚ โ”‚ โ”‚ pytest โ”‚ โ”‚ + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ + ``` ### Run the tests ๐Ÿƒ๐Ÿปโ€โ™€๏ธ ๐Ÿƒโ€โ™‚๏ธ @@ -96,7 +104,8 @@ To add a new theme, please create a folder with your new theme name, like `white You can use as a base one of our existing themes, this file needs to define a new class named `Theme` with the new colors and rules you want. > **NOTE** ๐Ÿ“ -> Please try to encapsulate all the raw colors in the `Colors` `enum` and call them in the rules section. This will help us with maintenance ๐Ÿ™. +> Please try to encapsulate all the raw colors in the `Colors` `enum` and call them in the rules section. +> This will help us with maintenance ๐Ÿ™. ### Visualize and debug your theme From 03531edf60759bd3b0c8f40001824ba2ff89b063 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 3 Apr 2023 16:46:13 +0100 Subject: [PATCH 06/33] :wrench: Update pyproject --- .pre-commit-config.yaml | 3 ++- pyproject.toml | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 004fff9..b15c7de 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,6 +21,8 @@ repos: hooks: - id: end-of-file-fixer - id: trailing-whitespace + - id: check-toml + - id: check-yaml # python - repo: https://github.com/psf/black @@ -42,7 +44,6 @@ repos: name: isort additional_dependencies: [toml] files: \.py$ - args: ["--profile", "black"] - repo: https://github.com/pre-commit/mirrors-prettier rev: v2.7.1 diff --git a/pyproject.toml b/pyproject.toml index f905ec1..de78d91 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,12 +1,11 @@ [build-system] -requires = ["hatchling"] +requires = ["hatchling", "hatch-fancy-pypi-readme"] build-backend = "hatchling.build" [project] name = "accessible-pygments" version = "0.0.4" description = "A collection of accessible pygments styles" -readme = "README.md" license = "BSD-3-Clause" requires-python = ">=3.9" authors = [ @@ -25,9 +24,11 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Development Status :: 3 - Alpha", "Topic :: Software Development :: Libraries :: Python Modules", ] dependencies = ["pygments >= 1.5"] +dynamic = ["readme"] [project.entry-points."pygments.styles"] a11y-dark = "a11y_pygments.a11y_dark.style:Theme" @@ -49,6 +50,17 @@ pitaya-smoothie = "a11y_pygments.pitaya_smoothie.style:Theme" [project.urls] Homepage = "https://github.com/Quansight-Labs/accessible-pygments" +"Bug Reports" = "https://github.com/Quansight-Labs/accessible-pygments/issues" + +[tool.hatch.build.targets.wheel] +packages = ["a11y_pygments"] +exclude = ["/.github", "/test", "/docs"] + +[tool.hatch.metadata.hooks.fancy-pypi-readme] +content-type = "text/markdown" + +[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]] +path = "README.md" [tool.hatch.version] path = "a11y_pygments/__init__.py" @@ -66,3 +78,6 @@ dependencies = ["hypothesis", "pytest"] [tool.hatch.envs.test.scripts] tests = "python -m pytest test/test_*.py" + +[tool.isort] +profile = "black" From e913e9b296a383c947eabc5e9a2ad8eb21682f29 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 3 Apr 2023 16:55:35 +0100 Subject: [PATCH 07/33] :heavy_plus_sign: Add fancy readme hook --- CONTRIBUTING.md | 6 ++++++ README.md | 12 ++++++------ pyproject.toml | 5 +++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6cfede0..f704dcf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -161,6 +161,12 @@ You will have to manually add a new link to your new theme: With this change you will be able to open `test/index.html` in your favorite browser and find your new theme in our demo! +To check the Readme output: + +```bash +pipx run hatch-fancy-pypi-readme | pipx run rich-cli --markdown --hyperlinks - +``` + ### Create a Pull Request Once you have the folder with the described files, please open a Pull Request ๐Ÿ‘๐Ÿป diff --git a/README.md b/README.md index 92c8e87..024fa89 100644 --- a/README.md +++ b/README.md @@ -111,18 +111,18 @@ HtmlFormatter(style='a11y-light').style ## Development and contribution -You can find our contribution guides on [CONTRIBUTING.md](./CONTRIBUTING.md). +You can find our contribution guides on [CONTRIBUTING.md](CONTRIBUTING.md). ## Acknowledgments ๐Ÿค We want to thank the following sources for being the source of inspiration for one or more themes that are available in this repository, - [a11y dark and light syntax highlighting](https://github.com/ericwbailey/a11y-syntax-highlighting). -- [pitaya smoothie vscode theme](https://github.com/trallard/pitaya_smoothie). -- [github vscode themes](https://github.com/primer/github-vscode-theme). -- [gotthard vscode themes](https://github.com/janbiasi/vscode-gotthard-theme/). -- [blinds vscode themes](https://github.com/orbulant/blinds-theme). -- [greative vscode theme](https://github.com/SumanKhdka/Greative-VSCode-Theme). +- [pitaya smoothie VSCode theme](https://github.com/trallard/pitaya_smoothie). +- [github VSCode themes](https://github.com/primer/github-vscode-theme). +- [gotthard VSCode themes](https://github.com/janbiasi/vscode-gotthard-theme/). +- [blinds VSCode themes](https://github.com/orbulant/blinds-theme). +- [greative VSCode theme](https://github.com/SumanKhdka/Greative-vscode-Theme). ## License ๐Ÿ“‘ diff --git a/pyproject.toml b/pyproject.toml index de78d91..a0f3c3d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,6 +62,11 @@ content-type = "text/markdown" [[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]] path = "README.md" +[[tool.hatch.metadata.hooks.fancy-pypi-readme.substitutions]] +# Literal TOML strings (single quotes) need no escaping of backslashes. +pattern = '\[(.+?)\]\(((?!https?://)\S+?)\)' +replacement = '[\1](https://github.com/Quansight-Labs/accessible-pygments/tree/main/\g<2>)' + [tool.hatch.version] path = "a11y_pygments/__init__.py" From 9169e9fdb23971314ff8d0308c4e7e16cd999924 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 3 Apr 2023 19:22:41 +0100 Subject: [PATCH 08/33] :see_no_evil: Update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0263a52..2396a56 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,7 @@ coverage.xml *.py,cover .hypothesis/ .pytest_cache/ +.ruff_cache # Translations *.mo From f53a13ed7b33159615c6e50b0ae452dd111be1c0 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 3 Apr 2023 19:24:05 +0100 Subject: [PATCH 09/33] :building_construction: Update build targets --- pyproject.toml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a0f3c3d..b192d56 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" name = "accessible-pygments" version = "0.0.4" description = "A collection of accessible pygments styles" -license = "BSD-3-Clause" +license = { text = "BSD-3-Clause" } requires-python = ">=3.9" authors = [ { name = "Stephannie Jimenez Gacha", email = "steff456@hotmail.com" }, @@ -52,10 +52,6 @@ pitaya-smoothie = "a11y_pygments.pitaya_smoothie.style:Theme" Homepage = "https://github.com/Quansight-Labs/accessible-pygments" "Bug Reports" = "https://github.com/Quansight-Labs/accessible-pygments/issues" -[tool.hatch.build.targets.wheel] -packages = ["a11y_pygments"] -exclude = ["/.github", "/test", "/docs"] - [tool.hatch.metadata.hooks.fancy-pypi-readme] content-type = "text/markdown" @@ -73,6 +69,10 @@ path = "a11y_pygments/__init__.py" [tool.hatch.build.targets.sdist] include = ["/a11y_pygments"] +[tool.hatch.build.targets.wheel] +only-include = ["a11y_pygments"] +sources = ["a11y_pygments"] + [tool.hatch.envs.dev.scripts] render_html = "python test/run_tests.py" css = "python test/run_css.py" @@ -86,3 +86,4 @@ tests = "python -m pytest test/test_*.py" [tool.isort] profile = "black" +skip_gitignore = true From 8b0f6ba0d7c31e2ea3f92527372ec8c800d16e20 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 3 Apr 2023 19:25:52 +0100 Subject: [PATCH 10/33] :construction_worker: Add build workflow --- .github/workflows/pypi-package.yml | 71 ++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 .github/workflows/pypi-package.yml diff --git a/.github/workflows/pypi-package.yml b/.github/workflows/pypi-package.yml new file mode 100644 index 0000000..ef878ce --- /dev/null +++ b/.github/workflows/pypi-package.yml @@ -0,0 +1,71 @@ +name: Build and maybe upload PyPI package + +on: + push: + branches: + - main + tags: + - "*" + pull_request: + branches: + - main + release: + types: + - published + +permissions: + contents: read + +jobs: + # Always build and lint + build-package: + name: Build package ๐Ÿ“ฆ + runs-on: ubuntu-latest + + steps: + - name: Checkout repository ๐Ÿ›Ž + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: hynek/build-and-inspect-python-package@v1 + + # Upload to Test PyPI on every commit on main. + release-test-pypi: + name: Publish in-dev package to test.pypi.org + environment: release-test-pypi + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + needs: build-package + + steps: + - name: Download package built in previous job ๐Ÿ“ฅ + uses: actions/download-artifact@v3 + with: + name: Packages + path: dist + - name: Upload package to Test PyPI ๐Ÿš€ + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.TEST_PYPI_API_TOKEN }} + repository-url: https://test.pypi.org/legacy/ + + # Upload to real PyPI on GitHub Releases. + release-pypi: + name: Publish released package to pypi.org ๐Ÿš€ + environment: release-pypi + if: github.event.action == 'published' + runs-on: ubuntu-latest + needs: build-package + + steps: + - name: Download packages built by build-and-inspect-python-package ๐Ÿ“ฅ + uses: actions/download-artifact@v3 + with: + name: Packages + path: dist + + - name: Upload package to PyPI ๐Ÿš€ + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} From 076246a2e0a9acd87354d160d607cfd173628776 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 3 Apr 2023 19:47:02 +0100 Subject: [PATCH 11/33] Delegate version to hatch --- .github/workflows/pypi-package.yml | 3 +++ a11y_pygments/__init__.py | 2 -- pyproject.toml | 13 ++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pypi-package.yml b/.github/workflows/pypi-package.yml index ef878ce..6b2cb5a 100644 --- a/.github/workflows/pypi-package.yml +++ b/.github/workflows/pypi-package.yml @@ -13,6 +13,9 @@ on: types: - published +env: + FORCE_COLOR: "1" # Make tools pretty. + permissions: contents: read diff --git a/a11y_pygments/__init__.py b/a11y_pygments/__init__.py index a439a51..e69de29 100644 --- a/a11y_pygments/__init__.py +++ b/a11y_pygments/__init__.py @@ -1,2 +0,0 @@ -VERSION_INFO = (0, 0, 5, "dev") -__version__ = ".".join(map(str, VERSION_INFO)) diff --git a/pyproject.toml b/pyproject.toml index b192d56..09f7fae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,9 @@ [build-system] -requires = ["hatchling", "hatch-fancy-pypi-readme"] +requires = ["hatchling", "hatch-fancy-pypi-readme", "hatch-vcs"] build-backend = "hatchling.build" [project] name = "accessible-pygments" -version = "0.0.4" description = "A collection of accessible pygments styles" license = { text = "BSD-3-Clause" } requires-python = ">=3.9" @@ -28,7 +27,7 @@ classifiers = [ "Topic :: Software Development :: Libraries :: Python Modules", ] dependencies = ["pygments >= 1.5"] -dynamic = ["readme"] +dynamic = ["version", "readme"] [project.entry-points."pygments.styles"] a11y-dark = "a11y_pygments.a11y_dark.style:Theme" @@ -64,7 +63,7 @@ pattern = '\[(.+?)\]\(((?!https?://)\S+?)\)' replacement = '[\1](https://github.com/Quansight-Labs/accessible-pygments/tree/main/\g<2>)' [tool.hatch.version] -path = "a11y_pygments/__init__.py" +source = "vcs" [tool.hatch.build.targets.sdist] include = ["/a11y_pygments"] @@ -77,9 +76,9 @@ sources = ["a11y_pygments"] render_html = "python test/run_tests.py" css = "python test/run_css.py" -# testing environment and tasks -[tool.hatch.envs.test] -dependencies = ["hypothesis", "pytest"] +[project.optional-dependencies] +tests = ["hypothesis", "pytest"] +dev = ["pre-commit"] [tool.hatch.envs.test.scripts] tests = "python -m pytest test/test_*.py" From 09cba954222d14a2d31f84754421dc48f09ab356 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 3 Apr 2023 20:00:02 +0100 Subject: [PATCH 12/33] :memo: Update release docs --- RELEASE.md | 74 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 761bfc0..3e20a9e 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,19 +1,61 @@ -# Release +# Making a release Please follow the instructions to make a new release of the `accessible pygments` package. -- `git fetch && git pull` -- `git clean -xdfi` -- Update `CHANGELOG.md` with `gitchangelog` -- `git add && git commit -m "Update changelog"` -- Update `VERSION_INFO` in the `__init__.py` removing `dev` -- `git add && git commit -m "Release vX.X.X"` -- `python setup.py bdist_wheel --universal` -- `python setup.py sdist` -- `twine check dist/*` -- `twine upload dist/*` -- `git tag -a vX.X.X -m 'Release x.x.x'` -- Update `VERSION_INFO` in the `__init__.py` add `dev` and increment version -- `git add && git commit` -- `git push` -- `git push --tags` +1. Create a new branch for the release + + ```bash + git checkout -b release-vX.X.X + ``` + +2. Document the changes since the last release + + - Update `CHANGELOG.md` with `gitchangelog` + - Commit the changes `git add && git commit -m "Update changelog"` + +3. Check package locally + + ```bash + # since we use vcs to dynamically set the tag you can check with hatch + $ hatch version + + 0.0.5.dev18+g8b0f6ba.d20230403 + + # build locally and check the artifacts + $ hatch build + + [sdist] + dist/accessible_pygments-0.0.5.dev19+g076246a.d20230403.tar.gz + + [wheel] + dist/accessible_pygments-0.0.5.dev19+g076246a.d20230403-py3-none-any.whl + + # clean the build artifacts + hatch clean + ``` + +4. Submit the PR, and merge the release branch into main once approved. +5. After merge: check the build artifacts from the GitHub actions workflow +6. Prepare the release commit - checkout the branch for the release and make sure it is to date and the repo is clean: + + ```bash + git checkout main + git fetch && git pull + git clean -xdfi + ``` + +7. Tag the release with the version number and push the tag to GitHub + + ```bash + git tag -a vX.X.X -m 'Release x.x.x' + git push --tags + ``` + + If you need to course-correct and delete the tag: + + ```bash + git tag -d vX.X.X + git push --delete origin vX.X.X + ``` + +8. Check that the release was published correctly From 03e897eb752cdc440549599c3bf1e148bbfaf0bf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Apr 2023 19:08:38 +0000 Subject: [PATCH 13/33] [pre-commit.ci] Apply automatic pre-commit fixes --- a11y_pygments/utils/wcag_contrast.py | 2 +- test/test_contrast.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/a11y_pygments/utils/wcag_contrast.py b/a11y_pygments/utils/wcag_contrast.py index a355e3e..a3d0df1 100644 --- a/a11y_pygments/utils/wcag_contrast.py +++ b/a11y_pygments/utils/wcag_contrast.py @@ -1,8 +1,8 @@ # Methods to calculate WCAG contrast ratio and check if it passes AA or AAA # https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html -from typing import Tuple, Union import re +from typing import Tuple, Union def hex_to_rgb(hex: int) -> Tuple[int, int, int]: diff --git a/test/test_contrast.py b/test/test_contrast.py index 86df41d..c93e8e9 100644 --- a/test/test_contrast.py +++ b/test/test_contrast.py @@ -1,6 +1,6 @@ +import pytest from hypothesis import given from hypothesis.strategies import floats, tuples -import pytest from a11y_pygments.utils import wcag_contrast as wcag From 29d9847ba80393c963186bb740ddb556001f5cd4 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 3 Apr 2023 20:29:30 +0100 Subject: [PATCH 14/33] :wrench: Update config --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 09f7fae..2300373 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,11 +66,11 @@ replacement = '[\1](https://github.com/Quansight-Labs/accessible-pygments/tree/m source = "vcs" [tool.hatch.build.targets.sdist] -include = ["/a11y_pygments"] +include = ["a11y_pygments"] [tool.hatch.build.targets.wheel] -only-include = ["a11y_pygments"] -sources = ["a11y_pygments"] +packages = ["a11y_pygments"] +exclude = ["/.github", "/test", "/docs"] [tool.hatch.envs.dev.scripts] render_html = "python test/run_tests.py" From 10dfc5fca059b0c15d3a261d19ff35ac347c9ae0 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 3 Apr 2023 20:37:42 +0100 Subject: [PATCH 15/33] :construction_worker: update package path --- .github/workflows/pypi-package.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pypi-package.yml b/.github/workflows/pypi-package.yml index 6b2cb5a..ba7c76e 100644 --- a/.github/workflows/pypi-package.yml +++ b/.github/workflows/pypi-package.yml @@ -12,6 +12,7 @@ on: release: types: - published + workflow_dispatch: env: FORCE_COLOR: "1" # Make tools pretty. @@ -32,6 +33,8 @@ jobs: fetch-depth: 0 - uses: hynek/build-and-inspect-python-package@v1 + with: + path: a11y_pygments # Upload to Test PyPI on every commit on main. release-test-pypi: From b61574be84e98199fffac28399f8069bec9aa202 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 3 Apr 2023 20:39:32 +0100 Subject: [PATCH 16/33] :bug: Revert path --- .github/workflows/pypi-package.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/pypi-package.yml b/.github/workflows/pypi-package.yml index ba7c76e..2312e52 100644 --- a/.github/workflows/pypi-package.yml +++ b/.github/workflows/pypi-package.yml @@ -33,8 +33,6 @@ jobs: fetch-depth: 0 - uses: hynek/build-and-inspect-python-package@v1 - with: - path: a11y_pygments # Upload to Test PyPI on every commit on main. release-test-pypi: From 8edb7c122d5f3b653eb9bcfe272471608a4d8bfb Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Mon, 3 Apr 2023 20:52:38 +0100 Subject: [PATCH 17/33] :bug: Should exclude in dist --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2300373..0403910 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,11 +66,10 @@ replacement = '[\1](https://github.com/Quansight-Labs/accessible-pygments/tree/m source = "vcs" [tool.hatch.build.targets.sdist] -include = ["a11y_pygments"] +exclude = ["/.github", "/docs", "/test"] [tool.hatch.build.targets.wheel] packages = ["a11y_pygments"] -exclude = ["/.github", "/test", "/docs"] [tool.hatch.envs.dev.scripts] render_html = "python test/run_tests.py" From aed2698b7e01d6be45ba688879470da6a77bccbd Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 4 Apr 2023 17:35:22 +0100 Subject: [PATCH 18/33] :rotating_light: Move linters config to pyproject --- .pre-commit-config.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b15c7de..67b6d92 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -35,7 +35,6 @@ repos: rev: v0.0.254 hooks: - id: ruff - args: ["--fix", "--exclude", "test/scripts/*.py"] - repo: https://github.com/pycqa/isort rev: 5.12.0 From 983a6d40e228453ddacfcbd11e4d8274439fadbf Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 4 Apr 2023 17:36:41 +0100 Subject: [PATCH 19/33] Rename to render_html - for accuracy --- a11y_pygments/__init__.py | 8 ++++ a11y_pygments/utils/utils.py | 41 +++++++++++++------- docs/generate_css.py | 4 +- pyproject.toml | 24 +++++++----- test/render_html.py | 75 ++++++++++++++++++++++++++++++++++++ test/run_css.py | 14 +++++-- test/run_tests.py | 49 ----------------------- 7 files changed, 139 insertions(+), 76 deletions(-) create mode 100644 test/render_html.py delete mode 100644 test/run_tests.py diff --git a/a11y_pygments/__init__.py b/a11y_pygments/__init__.py index e69de29..c614774 100644 --- a/a11y_pygments/__init__.py +++ b/a11y_pygments/__init__.py @@ -0,0 +1,8 @@ +import logging + +logger = logging.getLogger() + +logging.basicConfig( + format="# %(asctime)s %(levelname)s %(name)s %(filename)s:%(lineno)s -- %(message)s\n", + level=logging.INFO, +) diff --git a/a11y_pygments/utils/utils.py b/a11y_pygments/utils/utils.py index 3d46059..2cb4bbe 100644 --- a/a11y_pygments/utils/utils.py +++ b/a11y_pygments/utils/utils.py @@ -1,3 +1,4 @@ +import logging import os from pathlib import Path from typing import List @@ -9,26 +10,36 @@ def find_all_themes_packages() -> List[str]: - """Finds the current supported themes in the a11y pygments package.""" + """Finds the currently supported themes in the a11y_pygments package. + + Returns: + themes: list of themes under the a11y_pygments package + """ exclude = {"test", "a11y_pygments", "a11y_pygments.utils"} packages = set(find_packages()) themes = list(packages - exclude) + # drop the a11y_pygments part of the pkg name themes = [x.split(".")[1] for x in themes] return themes -def find_all_themes() -> List[str]: - """Finds the current supported themes names in the a11y pygments package.""" - exclude = {"test", "a11y_pygments", "a11y_pygments.utils"} - packages = set(find_packages()) - themes = list(packages - exclude) - themes = [x.split(".")[1] for x in themes] +def get_themes_names() -> List[str]: + """Get themes names from the a11y_pygments package. + + Returns: + themes: list of themes names + """ + themes = find_all_themes_packages() themes = [x.replace("_", "-") for x in themes] + logging.info(f"Found pygment themes: {themes}") return themes def generate_css(themes: List[str], save_dir=""): - """Generate css for the given themes.""" + """Generate css for the available themes. + Args: + themes (list): list of themes names + """ basedir = "a11y_pygments" for theme in themes: style = get_style_by_name(theme) @@ -40,12 +51,16 @@ def generate_css(themes: List[str], save_dir=""): ) package = theme.replace("-", "_") out = Path(basedir) / package / "style.css" - with open(out, "w") as f: - f.write(css) + # with open(out, "w") as f: + # f.write(css) if save_dir: if not Path(save_dir).joinpath("css").exists(): os.mkdir(Path(save_dir).joinpath("css")) - out = Path(save_dir).joinpath("css", f"{package}-style.css") - with open(out, "w") as f: - f.write(css) + out = Path(save_dir) / package / "style.css" + else: + out = Path(basedir) / package / "style.css" + + logging.info(f"Saving css to {out}") + with open(out, "w") as f: + f.write(css) diff --git a/docs/generate_css.py b/docs/generate_css.py index 35c3383..f0310ac 100644 --- a/docs/generate_css.py +++ b/docs/generate_css.py @@ -1,7 +1,7 @@ import os -from a11y_pygments.utils.utils import find_all_themes, generate_css +from a11y_pygments.utils.utils import generate_css, get_themes_names act_folder = os.path.dirname(__file__) -themes = find_all_themes() +themes = get_themes_names() generate_css(themes, save_dir=act_folder) diff --git a/pyproject.toml b/pyproject.toml index 0403910..6d52a7e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,23 +65,29 @@ replacement = '[\1](https://github.com/Quansight-Labs/accessible-pygments/tree/m [tool.hatch.version] source = "vcs" -[tool.hatch.build.targets.sdist] -exclude = ["/.github", "/docs", "/test"] +[project.optional-dependencies] +tests = ["hypothesis", "pytest"] +dev = ["pre-commit"] -[tool.hatch.build.targets.wheel] -packages = ["a11y_pygments"] +[tool.hatch.build.targets] +sdist = { exclude = ["/.github", "/docs", "/test"] } +wheel = { packages = ["a11y_pygments"] } [tool.hatch.envs.dev.scripts] -render_html = "python test/run_tests.py" +render_html = "python test/render_html.py" css = "python test/run_css.py" -[project.optional-dependencies] -tests = ["hypothesis", "pytest"] -dev = ["pre-commit"] - [tool.hatch.envs.test.scripts] tests = "python -m pytest test/test_*.py" [tool.isort] profile = "black" skip_gitignore = true + +[tool.ruff] +fix = true +exclude = ["test/scripts/*.py"] +ignore = [ + "E501" + # line too long | Black takes care of this +] diff --git a/test/render_html.py b/test/render_html.py new file mode 100644 index 0000000..23e49d9 --- /dev/null +++ b/test/render_html.py @@ -0,0 +1,75 @@ +""" +Script to create the HTML samples for all the themes in accessible-pygments. + +Usage:: + + python test/render_html.py +""" + +import os +from pathlib import Path + +from pygments import highlight as pygments_highlight +from pygments.formatters import HtmlFormatter +from pygments.lexers import get_lexer_by_name +from pygments.styles import get_style_by_name + +from a11y_pygments.utils.utils import get_themes_names + +# List of available language examples +languages = { + "python": "py", + "javascript": "js", + "bash": "bash", + "html": "html", + "css": "css", + "markdown": "md", +} + +# Setting directories +HERE = Path(__file__).parent +outdir = HERE / "results" + + +def render_html(themes: list, languages=languages, outdir=outdir): + """Generate rendered HTML sample of the themes for the specified languages. + + Args: + themes (list): list of registred themes. + languages (dict, optional): Dict containing the languages samples to render. + Defaults to languages. + outdir (pathlib.Path, optional): Directory to save the rendered HTML files to. + Defaults to outdir. + """ + + if not outdir.exists(): + os.mkdir(outdir) + + for language in languages: + ext = languages[language] + name = HERE / "scripts" / f"test.{ext}" + + with open(name, "r") as f: + lines = f.read() + + lexer = get_lexer_by_name(language, stripall=True) + + for theme in themes: + style = get_style_by_name(theme) + formatter = HtmlFormatter(style=style, full=True, hl_lines=[2, 3, 4]) + result = pygments_highlight(lines, lexer, formatter) + + theme_outdir = outdir / theme + + if not theme_outdir.exists(): + os.mkdir(theme_outdir) + + out = theme_outdir / f"{ext}.html" + with open(out, "w") as f: + f.write(result) + + +if __name__ == "__main__": + # get names of all themes + themes = get_themes_names() + render_html(themes) diff --git a/test/run_css.py b/test/run_css.py index d462c8c..2f00828 100644 --- a/test/run_css.py +++ b/test/run_css.py @@ -1,4 +1,12 @@ -from a11y_pygments.utils.utils import find_all_themes, generate_css +""" +Script to generate the css files for the themes in accessible-pygments. -themes = find_all_themes() -generate_css(themes) +Usage:: + + python test/run_css.py +""" +from a11y_pygments.utils.utils import generate_css, get_themes_names + +if __name__ == "__main__": + themes = get_themes_names() + generate_css(themes) diff --git a/test/run_tests.py b/test/run_tests.py deleted file mode 100644 index b5e4bbb..0000000 --- a/test/run_tests.py +++ /dev/null @@ -1,49 +0,0 @@ -import os -import os.path as osp - -from pygments import highlight as pygments_highlight -from pygments.formatters import HtmlFormatter -from pygments.lexers import get_lexer_by_name -from pygments.styles import get_style_by_name - -from a11y_pygments.utils.utils import find_all_themes - -languages = { - "python": "py", - "javascript": "js", - "bash": "bash", - "html": "html", - "css": "css", - "markdown": "md", -} - -themes = find_all_themes() - -actdir = osp.dirname(__file__) -outdir = osp.join(actdir, "results") - -if not osp.exists(outdir): - os.mkdir(outdir) - -for language in languages: - ext = languages[language] - name = osp.join(actdir, "scripts", "test." + ext) - - with open(name, "r") as f: - lines = f.read() - - lexer = get_lexer_by_name(language, stripall=True) - - for theme in themes: - style = get_style_by_name(theme) - formatter = HtmlFormatter(style=style, full=True, hl_lines=[2, 3, 4]) - result = pygments_highlight(lines, lexer, formatter) - - theme_outdir = osp.join(outdir, theme) - - if not osp.exists(theme_outdir): - os.mkdir(theme_outdir) - - out = osp.join(theme_outdir, ext + ".html") - with open(out, "w") as f: - f.write(result) From a743196e0e441aa9852539c77ef0e1640517d1eb Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 4 Apr 2023 17:37:25 +0100 Subject: [PATCH 20/33] :memo: Update docs --- CONTRIBUTING.md | 24 +++++++++++++----------- README.md | 13 ++++++++----- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f704dcf..12c4d13 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,9 +5,10 @@ Welcome! And thanks for taking your time to contribute to this project ๐Ÿคฉ - [Contributing to accessible pygments themes](#contributing-to-accessible-pygments-themes) - [Submit an issue ๐Ÿ“ฌ](#submit-an-issue-) - [Contributing to this package](#contributing-to-this-package) - - [Prerequisites ๐Ÿ“ฆ](#prerequisites-) + - [Pre-requisites ๐Ÿ“ฆ](#pre-requisites-) - [Creating your development environment ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป ๐Ÿ‘จ๐Ÿผโ€๐Ÿ’ป](#creating-your-development-environment--) - - [Run the tests ๐Ÿƒ๐Ÿปโ€โ™€๏ธ ๐Ÿƒโ€โ™‚๏ธ](#run-the-tests-๏ธ-๏ธ) + - [Running the tests](#running-the-tests) + - [Rendering the HTML examples](#rendering-the-html-examples) - [Adding a new theme ๐ŸŽจ](#adding-a-new-theme-) - [Where to add a new theme ๐Ÿ‘ฉ๐Ÿผโ€๐ŸŽจ](#where-to-add-a-new-theme-) - [Customize your `style.py` file](#customize-your-stylepy-file) @@ -21,13 +22,12 @@ Welcome! And thanks for taking your time to contribute to this project ๐Ÿคฉ Please share your thoughts for fixes and features in the issue tracker. When doing so, please a clear description and provide useful environment information. -Please share your thoughts for fixes and features in the issue tracker. Add a clear description, and please provide useful environment information. +Please share your thoughts for fixes and features [in the issue tracker](https://github.com/Quansight-Labs/accessible-pygments/issues). +When doing so, add a clear description, and please provide as much information as possible about your environment. ## Contributing to this package -For creating your development environment locally you will need to have the following tools installed: - -### Prerequisites ๐Ÿ“ฆ +### Pre-requisites ๐Ÿ“ฆ You will need to have the following installed locally: @@ -40,7 +40,7 @@ You will need to have the following installed locally: 1. Fork this repository to your GitHub account, then clone it to your local machine: ```bash - git clone + git clone https://github.com//accessible-pygments.git ``` Remember that this fork is a copy of the repository and any change done in it doesn't affect the original one. @@ -48,7 +48,7 @@ You will need to have the following installed locally: 2. From here you can create your local environments with hatch: ```bash - hatch env create + hatch env create ``` 3. You can verify that the environment was created successfully by running: @@ -68,14 +68,16 @@ You will need to have the following installed locally: โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` -### Run the tests ๐Ÿƒ๐Ÿปโ€โ™€๏ธ ๐Ÿƒโ€โ™‚๏ธ +### Running the tests -Once the development environment is ready run the following command: +You can run the tests directly with hatch: ```bash -python test/run_tests.py +hatch run test:tests ``` +### Rendering the HTML examples + You will see the results under `test/results` in HTML format for each supported theme. We recommend using your favorite browser to see the rich HTML output. diff --git a/README.md b/README.md index 024fa89..8ad1a18 100644 --- a/README.md +++ b/README.md @@ -13,23 +13,23 @@ - [Documentation ๐Ÿ“–](#documentation-) - [Installation ๐Ÿ’ป](#installation-) - [Using the themes directly in your code or app](#using-the-themes-directly-in-your-code-or-app) - - [Using the themes with Sphinx documentation](#using-the-themes-with-sphinx-documentation) + - [Using the themes in your Sphinx documentation](#using-the-themes-in-your-sphinx-documentation) - [Development and contribution](#development-and-contribution) - [Acknowledgments ๐Ÿค](#acknowledgments-) - [License ๐Ÿ“‘](#license-) This package includes a collection of accessible themes for pygments based on multiple open-source syntax highlighting themes. The images below show all the themes side by side. -![Screenshot of all light themes side by side](./docs/light_themes.png) +![Display of all the light themes side by side](./docs/light_themes.png) -![Screenshot of all dark themes side by side](./docs/dark_themes.png) +![Display of all dark themes side by side](./docs/dark_themes.png) :sparkles: For a demo of all our themes please [visit our online demo](https://quansight-labs.github.io/accessible-pygments/) :sparkles: ## Accessibility details โ™ฟ๏ธ > **Note** -> What we mean by accessible? In this context we are specially referring to themes which meet the [WCAG 2.1 criteria for color contrast](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html). +> What do we mean by accessible? In this context we are specially referring to themes which meet the [WCAG 2.1 criteria for color contrast](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html). > Some themes included are also color-blind friendly. ### WCAG 2.1 - AAA compliant @@ -66,6 +66,9 @@ The following themes are AA compliant with [WCAG 2.1 criteria for color contrast ```bash conda install -c conda-forge accessible-pygments + +# if you prefer using mambga +mamba install -c conda-forge accessible-pygments ``` ```bash @@ -92,7 +95,7 @@ HtmlFormatter(style='a11y-light').style ``` -### Using the themes with Sphinx documentation +### Using the themes in your Sphinx documentation 1. You will need to add `accessible-pygments` as a dependency to your documentation: From 8eb3f82304a5e250d51c956ebe7aebce80beec18 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 4 Apr 2023 17:52:55 +0100 Subject: [PATCH 21/33] Reuse css path --- a11y_pygments/utils/utils.py | 2 -- pyproject.toml | 3 ++- test/run_css.py | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/a11y_pygments/utils/utils.py b/a11y_pygments/utils/utils.py index 2cb4bbe..0e5a505 100644 --- a/a11y_pygments/utils/utils.py +++ b/a11y_pygments/utils/utils.py @@ -51,8 +51,6 @@ def generate_css(themes: List[str], save_dir=""): ) package = theme.replace("-", "_") out = Path(basedir) / package / "style.css" - # with open(out, "w") as f: - # f.write(css) if save_dir: if not Path(save_dir).joinpath("css").exists(): diff --git a/pyproject.toml b/pyproject.toml index 6d52a7e..65937b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,7 +75,8 @@ wheel = { packages = ["a11y_pygments"] } [tool.hatch.envs.dev.scripts] render_html = "python test/render_html.py" -css = "python test/run_css.py" +create_css = "python test/run_css.py" +create_docs = "python test/run_css.py --save-dir docs/css" [tool.hatch.envs.test.scripts] tests = "python -m pytest test/test_*.py" diff --git a/test/run_css.py b/test/run_css.py index 2f00828..2fd71d7 100644 --- a/test/run_css.py +++ b/test/run_css.py @@ -5,8 +5,22 @@ python test/run_css.py """ +import argparse +import logging +from pathlib import Path + from a11y_pygments.utils.utils import generate_css, get_themes_names if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "--save_dir", type=str, default="", help="Directory to save the css files" + ) + args = parser.parse_args() + + if args.save_dir: + save_dir = Path(args.save_dir).resolve() + logging.info(f"Saving css files to {save_dir}") + themes = get_themes_names() - generate_css(themes) + generate_css(themes, args.save_dir) From 40524485033351674fe50707d88ab3ea6029e7ac Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 4 Apr 2023 20:56:10 +0100 Subject: [PATCH 22/33] Unify scripts --- a11y_pygments/utils/utils.py | 6 ++++-- docs/generate_css.py | 7 ------- pyproject.toml | 3 ++- test/render_html.py | 2 +- test/run_css.py | 2 +- 5 files changed, 8 insertions(+), 12 deletions(-) delete mode 100644 docs/generate_css.py diff --git a/a11y_pygments/utils/utils.py b/a11y_pygments/utils/utils.py index 0e5a505..67d3621 100644 --- a/a11y_pygments/utils/utils.py +++ b/a11y_pygments/utils/utils.py @@ -50,12 +50,14 @@ def generate_css(themes: List[str], save_dir=""): f"\n.highlight {{ background: {style.background_color}; color: #{color}; }}" ) package = theme.replace("-", "_") - out = Path(basedir) / package / "style.css" if save_dir: if not Path(save_dir).joinpath("css").exists(): os.mkdir(Path(save_dir).joinpath("css")) - out = Path(save_dir) / package / "style.css" + if "docs" in save_dir: + out = Path(save_dir).joinpath("css", f"{package}-style.css") + else: + out = Path(save_dir) / package / "style.css" else: out = Path(basedir) / package / "style.css" diff --git a/docs/generate_css.py b/docs/generate_css.py deleted file mode 100644 index f0310ac..0000000 --- a/docs/generate_css.py +++ /dev/null @@ -1,7 +0,0 @@ -import os - -from a11y_pygments.utils.utils import generate_css, get_themes_names - -act_folder = os.path.dirname(__file__) -themes = get_themes_names() -generate_css(themes, save_dir=act_folder) diff --git a/pyproject.toml b/pyproject.toml index 65937b4..f751e36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,7 @@ license = { text = "BSD-3-Clause" } requires-python = ">=3.9" authors = [ { name = "Stephannie Jimenez Gacha", email = "steff456@hotmail.com" }, + { name = "Tania Allard", email = "trallard@bitsandchips.me" }, ] keywords = ["a11", "accessibility", "pygments", "WCAG", "Sphinx"] classifiers = [ @@ -76,7 +77,7 @@ wheel = { packages = ["a11y_pygments"] } [tool.hatch.envs.dev.scripts] render_html = "python test/render_html.py" create_css = "python test/run_css.py" -create_docs = "python test/run_css.py --save-dir docs/css" +create_docs = "python test/run_css.py --save-dir docs" [tool.hatch.envs.test.scripts] tests = "python -m pytest test/test_*.py" diff --git a/test/render_html.py b/test/render_html.py index 23e49d9..c16d451 100644 --- a/test/render_html.py +++ b/test/render_html.py @@ -1,5 +1,5 @@ """ -Script to create the HTML samples for all the themes in accessible-pygments. +Script to create individual HTML samples for each of the themes in accessible-pygments. Usage:: diff --git a/test/run_css.py b/test/run_css.py index 2fd71d7..5880ffc 100644 --- a/test/run_css.py +++ b/test/run_css.py @@ -14,7 +14,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( - "--save_dir", type=str, default="", help="Directory to save the css files" + "--save-dir", type=str, default="", help="Directory to save the css files" ) args = parser.parse_args() From a495b4eaf053d6a5582f41158f56da33f291a250 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 4 Apr 2023 21:23:32 +0100 Subject: [PATCH 23/33] :memo: Update docs --- CONTRIBUTING.md | 41 ++++++++++++++++++----------------------- README.md | 4 +++- pyproject.toml | 3 +-- test/render_html.py | 1 - 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 12c4d13..c72cbce 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,7 +43,7 @@ You will need to have the following installed locally: git clone https://github.com//accessible-pygments.git ``` - Remember that this fork is a copy of the repository and any change done in it doesn't affect the original one. + Remember that this fork is a copy of the repository and any changes in it doesn't affect the original one. 2. From here you can create your local environments with hatch: @@ -78,7 +78,13 @@ hatch run test:tests ### Rendering the HTML examples -You will see the results under `test/results` in HTML format for each supported theme. +You can generate individual HTML files for each of the themes included in `accessible_pygments` by running: + +```bash +hatch run dev:render_html +``` + +This will add the HTML files under `test/results` for each supported theme. We recommend using your favorite browser to see the rich HTML output. ## Adding a new theme ๐ŸŽจ @@ -111,19 +117,13 @@ You can use as a base one of our existing themes, this file needs to define a ne ### Visualize and debug your theme -To see and debug your theme re-install the package via: - -```bash -pip install -e . -``` - -Then generate the HTML results: +While working on your theme, it might be helpful to generate the individual HTML files with the following command: ```bash -python test/run_tests.py +hatch dev:render_html ``` -If successful, you should be able to see the results of your new theme under `test/results/` in HTML format. +If successful, you should be able to see the results of your new theme under `test/results/`. ### Update the `README.md` file @@ -140,17 +140,18 @@ Also, don't forget to add the name of your theme to our list of supported themes You can generate the CSS file automatically through: ```bash -python a11y_pygments/test/run_css.py +hatch dev:create_css ``` -The file should appear in the folder of your new theme. +This will add the CSS file under `a11y_pygments//style.css` and in the `docs` directory. #### Add your theme to our static page We have a demo page where you will be able to change the style of different languages at the same time. -To add your new theme please go to the file `test/index.html`. Under themes, we have a link to all the generated CSS files. +To add your new theme: -You will have to manually add a new link to your new theme: +1. Open the `[docs/index.html](docs/index.html)` file. +2. Add a new link to your new theme in the `themes` section: ```HTML ... @@ -161,14 +162,8 @@ You will have to manually add a new link to your new theme: ``` -With this change you will be able to open `test/index.html` in your favorite browser and find your new theme in our demo! - -To check the Readme output: - -```bash -pipx run hatch-fancy-pypi-readme | pipx run rich-cli --markdown --hyperlinks - -``` +With this change you will be able to open `docs/index.html` in your favorite browser and find your new theme in our demo! ### Create a Pull Request -Once you have the folder with the described files, please open a Pull Request ๐Ÿ‘๐Ÿป +Once you have added and verified your theme you should be ready to open a Pull Request ๐Ÿ‘๐Ÿป diff --git a/README.md b/README.md index 8ad1a18..14d0415 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,9 @@ The following themes are AA compliant with [WCAG 2.1 criteria for color contrast ### Installation ๐Ÿ’ป -`accessible-pygments` is available through pip and Conda. You can install it using: +`accessible-pygments` is available through pip and conda. + +You can install it through the following commands: ```bash conda install -c conda-forge accessible-pygments diff --git a/pyproject.toml b/pyproject.toml index f751e36..4f013c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -76,8 +76,7 @@ wheel = { packages = ["a11y_pygments"] } [tool.hatch.envs.dev.scripts] render_html = "python test/render_html.py" -create_css = "python test/run_css.py" -create_docs = "python test/run_css.py --save-dir docs" +create_css = "python test/run_css.py && python test/run_css.py --save-dir docs" [tool.hatch.envs.test.scripts] tests = "python -m pytest test/test_*.py" diff --git a/test/render_html.py b/test/render_html.py index c16d451..17effd9 100644 --- a/test/render_html.py +++ b/test/render_html.py @@ -5,7 +5,6 @@ python test/render_html.py """ - import os from pathlib import Path From d0021a13d5a6ab0f2054cd75564ee462d77d192a Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 4 Apr 2023 21:26:50 +0100 Subject: [PATCH 24/33] :memo: Add conda instructions --- CONTRIBUTING.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c72cbce..86f196a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -68,6 +68,16 @@ You will need to have the following installed locally: โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ ``` +Alternatively you can use conda to create your environment: + +```bash +conda create -n a11y-pygments-dev python=3.9 +conda activate a11y-pygments-dev +pip install -e . +``` + +After running these instructions you will have an environment named `a11y-pygments-dev`, with a development version of the package installed. + ### Running the tests You can run the tests directly with hatch: From d73c32c17b53643d897ebf7b90e919fd24cdd420 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 4 Apr 2023 21:39:51 +0100 Subject: [PATCH 25/33] :construction_worker: Add preview action --- .github/workflows/preview-pr.yml | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/preview-pr.yml diff --git a/.github/workflows/preview-pr.yml b/.github/workflows/preview-pr.yml new file mode 100644 index 0000000..af74e67 --- /dev/null +++ b/.github/workflows/preview-pr.yml @@ -0,0 +1,36 @@ +name: Deploy PR previews on GH pages + +on: + push: + branches: + - main + pull_request: + branches: + - main + +concurrency: preview-${{ github.ref }} + +jobs: + deploy-preview: + runs-on: ubuntu-latest + steps: + - name: Checkout repository ๐Ÿ›Ž + uses: actions/checkout@v3 + + - name: Set up Python ๐Ÿ + uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - name: Install dependencies ๐Ÿ“ฆ + run: | + pip install hatch + + - name: Build the demo pages ๐Ÿ“š + run: | + hatch run dev:create_css + + - name: Deploy PR Preview + uses: rossjrw/pr-preview-action@v1.2.0 + with: + source-dir: ./docs From b91780038fba4e02691d862f96bf30825a566797 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 4 Apr 2023 21:47:33 +0100 Subject: [PATCH 26/33] :bug: Try and install hatch on its own --- .github/workflows/preview-pr.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/preview-pr.yml b/.github/workflows/preview-pr.yml index af74e67..2562a63 100644 --- a/.github/workflows/preview-pr.yml +++ b/.github/workflows/preview-pr.yml @@ -17,14 +17,9 @@ jobs: - name: Checkout repository ๐Ÿ›Ž uses: actions/checkout@v3 - - name: Set up Python ๐Ÿ - uses: actions/setup-python@v4 - with: - python-version: 3.9 - - name: Install dependencies ๐Ÿ“ฆ run: | - pip install hatch + pipx install hatch - name: Build the demo pages ๐Ÿ“š run: | From 4bed0ad43240c97825ba0a5d96d2bd3c48102fb4 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 4 Apr 2023 22:17:05 +0100 Subject: [PATCH 27/33] :construction_worker: Debug action --- .github/workflows/preview-pr.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview-pr.yml b/.github/workflows/preview-pr.yml index 2562a63..a4fd42c 100644 --- a/.github/workflows/preview-pr.yml +++ b/.github/workflows/preview-pr.yml @@ -9,6 +9,8 @@ on: - main concurrency: preview-${{ github.ref }} +env: + FORCE_COLOR: "1" jobs: deploy-preview: @@ -17,12 +19,18 @@ jobs: - name: Checkout repository ๐Ÿ›Ž uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + - name: Install dependencies ๐Ÿ“ฆ run: | - pipx install hatch + pip install hatch - name: Build the demo pages ๐Ÿ“š run: | + hatch version hatch run dev:create_css - name: Deploy PR Preview From d7886eb30365317d75228641d806af6cca3642d8 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 4 Apr 2023 22:50:52 +0100 Subject: [PATCH 28/33] Replace w pip installs --- .github/workflows/preview-pr.yml | 8 +++++--- pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/preview-pr.yml b/.github/workflows/preview-pr.yml index a4fd42c..68af53c 100644 --- a/.github/workflows/preview-pr.yml +++ b/.github/workflows/preview-pr.yml @@ -11,6 +11,8 @@ on: concurrency: preview-${{ github.ref }} env: FORCE_COLOR: "1" + PYTHONIOENCODING: utf-8 + SETUPTOOLS_SCM_PRETEND_VERSION: "1.0" # avoid warnings about shallow checkout jobs: deploy-preview: @@ -26,12 +28,12 @@ jobs: - name: Install dependencies ๐Ÿ“ฆ run: | - pip install hatch + pip install pygments>=1.5 + pip install -e .[dev] - name: Build the demo pages ๐Ÿ“š run: | - hatch version - hatch run dev:create_css + python test/run_css.py --save-dir docs - name: Deploy PR Preview uses: rossjrw/pr-preview-action@v1.2.0 diff --git a/pyproject.toml b/pyproject.toml index 4f013c9..cd6ba73 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ authors = [ { name = "Stephannie Jimenez Gacha", email = "steff456@hotmail.com" }, { name = "Tania Allard", email = "trallard@bitsandchips.me" }, ] -keywords = ["a11", "accessibility", "pygments", "WCAG", "Sphinx"] +keywords = ["a11y", "accessibility", "pygments", "WCAG", "Sphinx"] classifiers = [ "Intended Audience :: Developers", "Intended Audience :: Education", From e5218e913096d278ae12492215123a7ad417e39e Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Tue, 4 Apr 2023 22:58:50 +0100 Subject: [PATCH 29/33] :green_heart: Fix preview branch --- .github/workflows/preview-pr.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview-pr.yml b/.github/workflows/preview-pr.yml index 68af53c..6b8f6b2 100644 --- a/.github/workflows/preview-pr.yml +++ b/.github/workflows/preview-pr.yml @@ -38,4 +38,5 @@ jobs: - name: Deploy PR Preview uses: rossjrw/pr-preview-action@v1.2.0 with: - source-dir: ./docs + source-dir: docs + preview-branch: main From e070c3936fb6c2026814b9082c3fa601fa306ed4 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Wed, 5 Apr 2023 10:30:11 +0100 Subject: [PATCH 30/33] :wrench: Use token id trusted service --- .github/workflows/preview-pr.yml | 2 +- .github/workflows/pypi-package.yml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview-pr.yml b/.github/workflows/preview-pr.yml index 6b8f6b2..2de4dab 100644 --- a/.github/workflows/preview-pr.yml +++ b/.github/workflows/preview-pr.yml @@ -39,4 +39,4 @@ jobs: uses: rossjrw/pr-preview-action@v1.2.0 with: source-dir: docs - preview-branch: main + preview-branch: gh-pages diff --git a/.github/workflows/pypi-package.yml b/.github/workflows/pypi-package.yml index 2312e52..7c10b18 100644 --- a/.github/workflows/pypi-package.yml +++ b/.github/workflows/pypi-package.yml @@ -19,6 +19,7 @@ env: permissions: contents: read + id-token: write jobs: # Always build and lint @@ -73,3 +74,4 @@ jobs: uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.PYPI_API_TOKEN }} + print-hash: true From 0c57f0e31050a9d1383f7470053ee690d8e93897 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Wed, 5 Apr 2023 10:35:36 +0100 Subject: [PATCH 31/33] :wrench: Add nojekyll file --- docs/.nojekyll | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 docs/.nojekyll diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 0000000..e69de29 From f8fe269e54ec53e150e699f3858a36a53ff12543 Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Wed, 5 Apr 2023 10:47:46 +0100 Subject: [PATCH 32/33] :construction_worker: Add deploy action --- .github/workflows/preview-pr.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/preview-pr.yml b/.github/workflows/preview-pr.yml index 2de4dab..0fe3d8c 100644 --- a/.github/workflows/preview-pr.yml +++ b/.github/workflows/preview-pr.yml @@ -40,3 +40,33 @@ jobs: with: source-dir: docs preview-branch: gh-pages + + publish-pages: + runs-on: ubuntu-latest + needs: deploy-preview + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + permissions: + contents: write + steps: + - name: Checkout repository ๐Ÿ›Ž + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - name: Install dependencies ๐Ÿ“ฆ + run: | + pip install pygments>=1.5 + pip install -e .[dev] + + - name: Build the demo pages ๐Ÿ“š + run: | + python test/run_css.py --save-dir docs + + - name: Deploy to GitHub Pages ๐Ÿš€ + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages + folder: docs From 70cc29955bca7a7bea78f7cc541bc53e572343ed Mon Sep 17 00:00:00 2001 From: Tania Allard Date: Wed, 5 Apr 2023 10:56:25 +0100 Subject: [PATCH 33/33] :zap: Replace with GH action --- .github/workflows/preview-pr.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/preview-pr.yml b/.github/workflows/preview-pr.yml index 0fe3d8c..5447ede 100644 --- a/.github/workflows/preview-pr.yml +++ b/.github/workflows/preview-pr.yml @@ -47,6 +47,17 @@ jobs: if: github.event_name == 'push' && github.ref == 'refs/heads/main' permissions: contents: write + pages: write + id-token: write + + concurrency: + group: "pages" + cancel-in-progress: false + + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: - name: Checkout repository ๐Ÿ›Ž uses: actions/checkout@v3 @@ -65,8 +76,13 @@ jobs: run: | python test/run_css.py --save-dir docs - - name: Deploy to GitHub Pages ๐Ÿš€ - uses: JamesIves/github-pages-deploy-action@v4 + - name: Setup Pages ๐Ÿ›  + uses: actions/configure-pages@v3 + + - name: Upload artifact ๐Ÿ“ฅ + uses: actions/upload-pages-artifact@v1 with: - branch: gh-pages - folder: docs + path: "docs" + - name: Deploy to GitHub Pages ๐Ÿš€ + id: deployment + uses: actions/deploy-pages@v2