From f48729dc452ac8515becab7aed208a9eb1b4f8f3 Mon Sep 17 00:00:00 2001 From: Ege Akman Date: Fri, 22 Sep 2023 15:18:06 +0300 Subject: [PATCH 1/4] Update tests.yaml --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index ff4540e..e025e55 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -15,7 +15,7 @@ jobs: strategy: matrix: os: [macos-latest, windows-latest, ubuntu-latest] - python-version: ["3.10", "3.11", "3.12.0-beta.4"] + python-version: ["3.10", "3.11", "3.12-dev"] steps: - name: Checkout repo From 4f8193f7df255be1a7c9cafad833d8dc06e2030c Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 8 Nov 2023 22:24:41 +0200 Subject: [PATCH 2/4] Convert `setup.py` to `pyproject.toml` (#5) * Convert setup.py to pyproject.toml * Add pyproject-fmt and validate-pyproject to pre-commit * Update pyproject.toml Co-authored-by: Hugo van Kemenade --------- Co-authored-by: Ege Akman --- .pre-commit-config.yaml | 19 ++++++++++--- pyproject.toml | 60 +++++++++++++++++++++++++++++++++++++++++ setup.py | 55 ------------------------------------- 3 files changed, 76 insertions(+), 58 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f0f99b1..fd01aff 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,14 +5,27 @@ repos: - id: isort name: isort (python) - - repo: https://github.com/psf/black - rev: 23.7.0 + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 23.10.1 hooks: - id: black name: black (python) - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: + - id: check-toml + - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace + + - repo: https://github.com/tox-dev/pyproject-fmt + rev: 1.4.1 + hooks: + - id: pyproject-fmt + additional_dependencies: [tox] + + - repo: https://github.com/abravalheri/validate-pyproject + rev: v0.15 + hooks: + - id: validate-pyproject diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f2ed994 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,60 @@ +[build-system] +build-backend = "setuptools.build_meta" +requires = [ + "setuptools>=61.2", +] + +[project] +name = "python-docs-bootstrapper" +version = "0.1.1" +description = "Bootstrapper for Python documentation translations" +readme = "README.md" +keywords = [ + "automation", + "CLI", + "documentation", + "i18n", + "python-docs", + "sphinx", + "translation", + "utilities", +] +license = {text = "MIT"} +authors = [{name = "egeakman", email = "me@egeakman.dev"}] +requires-python = ">=3.10" +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "License :: OSI Approved :: MIT License", + "Operating System :: MacOS :: MacOS X", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Topic :: Utilities", +] +dependencies = [ + "sphinx==4.5", +] +[project.urls] +Releases = "https://github.com/egeakman/python-docs-bootstrapper/releases" +Homepage = "https://github.com/egeakman/python-docs-bootstrapper" +Issues = "https://github.com/egeakman/python-docs-bootstrapper/issues" +[project.scripts] +bootstrapper = "bootstrapper.bootstrapper:main" + +[tool.setuptools] +include-package-data = true + +[tool.setuptools.packages.find] +where = ["."] +namespaces = false + +[tool.setuptools.package-data] +bootstrapper = [ + "data/.gitignore", + "data/Makefile", + "data/README.md", +] diff --git a/setup.py b/setup.py deleted file mode 100644 index 75b3bea..0000000 --- a/setup.py +++ /dev/null @@ -1,55 +0,0 @@ -from setuptools import find_packages, setup - -version = "0.1.1" - -with open("README.md", "r", encoding="utf-8") as f: - long_description = f.read() - -setup( - name="python-docs-bootstrapper", - author="egeakman", - author_email="me@egeakman.dev", - url="https://github.com/egeakman/python-docs-bootstrapper", - description="Bootstrapper for Python documentation translations", - long_description=long_description, - long_description_content_type="text/markdown", - version=version, - license="MIT", - download_url=f"https://github.com/egeakman/python-docs-bootstrapper/archive/{version}.tar.gz", - packages=find_packages(where="."), - install_requires=["sphinx==4.5.0"], - include_package_data=True, - package_data={ - "bootstrapper": ["data/.gitignore", "data/Makefile", "data/README.md"] - }, - python_requires=">=3.10", - entry_points={ - "console_scripts": [ - "bootstrapper=bootstrapper.bootstrapper:main", - ] - }, - classifiers=[ - "Topic :: Utilities", - "Programming Language :: Python :: 3 :: Only", - "Development Status :: 5 - Production/Stable", - "Environment :: Console", - "License :: OSI Approved :: MIT License", - "Operating System :: Microsoft :: Windows", - "Operating System :: POSIX :: Linux", - "Operating System :: MacOS :: MacOS X", - ], - keywords=[ - "documentation", - "translation", - "sphinx", - "i18n", - "python-docs", - "CLI", - "automation", - "utilities", - ], - project_urls={ - "Homepage": "https://github.com/egeakman/python-docs-bootstrapper", - "Issues": "https://github.com/egeakman/python-docs-bootstrapper/issues", - }, -) From 633eb891116d23473aacb4ff4fd27d7f3305e3e3 Mon Sep 17 00:00:00 2001 From: Ege Akman Date: Thu, 9 Nov 2023 01:06:28 +0300 Subject: [PATCH 3/4] Optimize the bootstrapper and tests (#2) * Changes for the upcoming release * optimize cloning sequence * fix tests * add pre-commit checks * update pre-commit.yaml * Update .github/workflows/tests.yaml * Optimized folder discovery and creation * Make the logger customizable --- .github/workflows/pre-commit.yaml | 17 ++++++ .github/workflows/tests.yaml | 19 +++---- .pre-commit-config.yaml | 3 +- bootstrapper/bootstrapper.py | 90 +++++++++++++++---------------- bootstrapper/data/Makefile | 4 +- bootstrapper/data/README.md | 4 +- pyproject.toml | 2 +- 7 files changed, 72 insertions(+), 67 deletions(-) create mode 100644 .github/workflows/pre-commit.yaml diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 0000000..3bcf53d --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,17 @@ +name: pre-commit checks + +on: [push, pull_request, workflow_dispatch] + +permissions: + contents: read + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: "3.x" + - uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index e025e55..d73657f 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,12 +1,6 @@ name: Tests -on: - workflow_dispatch: - push: - branches: - - "**" - pull_request: - branches: - - "**" + +on: [push, pull_request, workflow_dispatch] jobs: test: @@ -15,11 +9,12 @@ jobs: strategy: matrix: os: [macos-latest, windows-latest, ubuntu-latest] - python-version: ["3.10", "3.11", "3.12-dev"] + python-version: ["3.11", "3.12"] + build-version: ["3.11", "3.12"] steps: - name: Checkout repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v4 @@ -41,8 +36,8 @@ jobs: - name: Install the package run: pip install . - - name: Run the package - run: bootstrapper tr -b 3.12 + - name: Run the bootstrapper + run: bootstrapper tr -b ${{ matrix.build-version }} - name: See results (non-Windows) if: matrix.os != 'windows-latest' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fd01aff..97d4ab3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,11 +9,12 @@ repos: rev: 23.10.1 hooks: - id: black - name: black (python) - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 hooks: + - id: check-case-conflict + - id: check-merge-conflict - id: check-toml - id: check-yaml - id: end-of-file-fixer diff --git a/bootstrapper/bootstrapper.py b/bootstrapper/bootstrapper.py index d39124b..8708a4e 100644 --- a/bootstrapper/bootstrapper.py +++ b/bootstrapper/bootstrapper.py @@ -21,17 +21,16 @@ def emit(self, record): self.flush() -logger = logging.getLogger() -logger.setLevel(logging.INFO) -handler = _NoNewLine() -handler.setFormatter(logging.Formatter("%(message)s")) -logger.addHandler(handler) - - class Bootstrapper: - def __init__(self, language: str, branch: str = "3.12") -> None: + def __init__( + self, + language: str, + branch: str = "3.12", + logger: logging.Logger = logging.getLogger(), + ) -> None: self.language = language self.branch = branch + self.logger = logger self.translation_repo = f"python-docs-{self.language}" self.cpython_repo = f"{self.translation_repo}/venv/cpython" self.readme_url = "https://raw.githubusercontent.com/egeakman/python-docs-bootstrapper/master/bootstrapper/data/README.md" @@ -43,36 +42,36 @@ def _request(self, url: str) -> str: return response.read().decode() def create_dirs(self) -> None: - logger.info("Creating directories...") + self.logger.info("Creating directories...") os.makedirs(self.translation_repo, exist_ok=True) os.makedirs(self.cpython_repo, exist_ok=True) - print("✅") + self.logger.info("✅\n") def setup_cpython_repo(self) -> None: if not os.path.exists(f"{self.cpython_repo}/.git") and not os.path.isdir( f"{self.cpython_repo}/.git" ): - logger.info("Cloning CPython repo...") + self.logger.info("Cloning CPython repo...") subprocess.run( [ "git", "clone", "https://github.com/python/cpython.git", self.cpython_repo, + f"--branch={self.branch}", "-q", ], check=True, ) - print("✅") + self.logger.info("✅\n") - subprocess.run( - ["git", "-C", self.cpython_repo, "checkout", self.branch, "-q"], check=True - ) + self.logger.info("Updating CPython repo...") subprocess.run( ["git", "-C", self.cpython_repo, "pull", "--ff-only", "-q"], check=True ) + self.logger.info("✅\n") - logger.info("Building gettext files...") + self.logger.info("Building gettext files...") subprocess.run( [ "sphinx-build", @@ -85,21 +84,18 @@ def setup_cpython_repo(self) -> None: cwd=self.cpython_repo, check=True, ) - print("✅") + self.logger.info("✅\n") def setup_translation_repo(self) -> None: - logger.info("Initializing translation repo...") + self.logger.info("Initializing translation repo...") subprocess.run(["git", "init", "-q"], cwd=self.translation_repo, check=True) subprocess.run( ["git", "branch", "-m", self.branch], cwd=self.translation_repo, check=True ) - print("✅") - - logger.info("Copying gettext files...") - files = glob.glob(f"{self.cpython_repo}/pot/**/*.pot") + glob.glob( - f"{self.cpython_repo}/pot/*.pot" - ) + self.logger.info("✅\n") + self.logger.info("Copying gettext files...") + files = glob.glob(f"{self.cpython_repo}/pot/**/*.pot", recursive=True) files = [path.replace("\\", "/") for path in files] for file in files: @@ -108,69 +104,62 @@ def setup_translation_repo(self) -> None: ".pot", ".po" ) ) - - if len(file.split("/")) > 5: - os.makedirs("/".join(dest_path.split("/")[:2]), exist_ok=True) - + os.makedirs(os.path.dirname(dest_path), exist_ok=True) shutil.copyfile(file, dest_path) files[files.index(file)] = dest_path - print("✅") + self.logger.info("✅\n") - logger.info("Cleaning up gettext files...") + self.logger.info("Cleaning up gettext files...") for file in files: with open(file, "r", encoding="utf-8") as f: contents = f.read() contents = re.sub("^#: .*Doc/", "#: ", contents, flags=re.M) with open(file, "w", encoding="utf-8") as f: f.write(contents) - print("✅") + self.logger.info("✅\n") def create_readme(self) -> None: - logger.info("Creating README.md...") + self.logger.info("Creating README.md...") try: readme = self._request(self.readme_url) except (urllib.error.HTTPError, urllib.error.URLError): - logger.warning( + self.logger.warning( "\n ⚠️ Failed to fetch README.md from GitHub, using local copy..." ) readme = Path(f"{os.path.dirname(__file__)}/data/README.md").read_text( encoding="utf-8" ) - readme = readme.replace("{{translation.language}}", self.language) - with open(f"{self.translation_repo}/README.md", "w", encoding="utf-8") as f: f.write(readme) - print("✅") + self.logger.info("✅\n") def create_gitignore(self) -> None: - logger.info("Creating .gitignore...") + self.logger.info("Creating .gitignore...") try: gitignore = self._request(self.gitignore_url) except (urllib.error.HTTPError, urllib.error.URLError): - logger.warning( + self.logger.warning( "\n ⚠️ Failed to fetch .gitignore from GitHub, using local copy..." ) gitignore = Path(f"{os.path.dirname(__file__)}/data/.gitignore").read_text( encoding="utf-8" ) - with open(f"{self.translation_repo}/.gitignore", "w", encoding="utf-8") as f: f.write(gitignore) - print("✅") + self.logger.info("✅\n") def create_makefile(self) -> None: - logging.info("Creating .makefile...") + logging.info("Creating Makefile...") try: makefile = self._request(self.makefile_url) except (urllib.error.HTTPError, urllib.error.URLError): - logger.warning( + self.logger.warning( "\n ⚠️ Failed to fetch Makefile from GitHub, using local copy..." ) makefile = Path(f"{os.path.dirname(__file__)}/data/Makefile").read_text( encoding="utf-8" ) - head = ( subprocess.run( ["git", "-C", self.cpython_repo, "rev-parse", "HEAD"], @@ -180,14 +169,12 @@ def create_makefile(self) -> None: .stdout.strip() .decode() ) - makefile = makefile.replace("{{translation.language}}", self.language) makefile = makefile.replace("{{translation.branch}}", self.branch) makefile = makefile.replace("{{translation.head}}", head) - with open(f"{self.translation_repo}/Makefile", "w", encoding="utf-8") as f: f.write(makefile) - print("✅") + self.logger.info("✅\n") def run(self) -> None: try: @@ -197,9 +184,11 @@ def run(self) -> None: self.create_readme() self.create_gitignore() self.create_makefile() - logger.info(f"🎉 Done bootstrapping the {self.language} translation ✅\n") + self.logger.info( + f"🎉 Done bootstrapping the {self.language} translation ✅\n" + ) except Exception as e: - logger.critical( + self.logger.critical( f"❌ Bootstrapping of the {self.language} translation failed: {e}\n" ) sys.exit(1) @@ -218,6 +207,11 @@ def main() -> None: "-b", "--branch", type=str, default="3.12", help="CPython branch (e.g. 3.12)" ) args = parser.parse_args() + logger = logging.getLogger() + logger.setLevel(logging.INFO) + handler = _NoNewLine() + handler.setFormatter(logging.Formatter("%(message)s")) + logger.addHandler(handler) Bootstrapper(args.language.lower().replace("_", "-"), args.branch).run() diff --git a/bootstrapper/data/Makefile b/bootstrapper/data/Makefile index 3cd30f1..cdc2c23 100644 --- a/bootstrapper/data/Makefile +++ b/bootstrapper/data/Makefile @@ -10,9 +10,7 @@ # - make clean # To remove build artifacts # - make fuzzy # To find fuzzy strings # -# Modes are: autobuild-stable, autobuild-dev, and autobuild-html, -# documented in gen/src/3.6/Doc/Makefile as we're only delegating the -# real work to the Python Doc Makefile. +# Modes are: autobuild-stable, autobuild-dev, and autobuild-html # Configuration diff --git a/bootstrapper/data/README.md b/bootstrapper/data/README.md index 4181a41..7328c5d 100644 --- a/bootstrapper/data/README.md +++ b/bootstrapper/data/README.md @@ -2,7 +2,7 @@ Hello! This is the repository of the {{translation.language}} translation of the Python documentation. -You can refer to the following resources throughout this journey: +**You can refer to the following resources throughout this journey:** - [DevGuide Translating Section](https://devguide.python.org/documentation/translating/) (add your translation to the list!) - [PEP 545](https://www.python.org/dev/peps/pep-0545/) (the PEP that describes the translation process) @@ -14,4 +14,4 @@ Python's documentation is maintained using a global network of volunteers. By po You signify acceptance of this agreement by submitting your work to the PSF for inclusion in the documentation. -**Do not forget to replace this file with your own README that describes your translation and community!** +***Do not forget to replace this file with your own README that describes your translation and community, while keeping the above agreement!*** diff --git a/pyproject.toml b/pyproject.toml index f2ed994..70ead93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,9 +39,9 @@ dependencies = [ "sphinx==4.5", ] [project.urls] -Releases = "https://github.com/egeakman/python-docs-bootstrapper/releases" Homepage = "https://github.com/egeakman/python-docs-bootstrapper" Issues = "https://github.com/egeakman/python-docs-bootstrapper/issues" +Releases = "https://github.com/egeakman/python-docs-bootstrapper/releases" [project.scripts] bootstrapper = "bootstrapper.bootstrapper:main" From 33276fab94f9cd653446650482998211b0d072f0 Mon Sep 17 00:00:00 2001 From: egeakman Date: Sun, 12 Nov 2023 21:25:06 +0300 Subject: [PATCH 4/4] bump version for new release --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 70ead93..0cd5b43 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ requires = [ [project] name = "python-docs-bootstrapper" -version = "0.1.1" +version = "0.1.2" description = "Bootstrapper for Python documentation translations" readme = "README.md" keywords = [ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy