From 26af6136c062607df76c647cf15a4234859c3c03 Mon Sep 17 00:00:00 2001 From: Peter Gorniak Date: Wed, 20 Mar 2024 16:05:42 -0700 Subject: [PATCH 1/2] Update buildsystem (#506) * Update buildsystem to use pyproject.toml and the "build" package --- .github/workflows/lint_and_test.yml | 2 +- .github/workflows/publish.yml | 4 +- .pre-commit-config.yaml | 8 +-- dodo.py | 9 ++-- pyproject.toml | 32 +++++++++++- setup.py | 32 ------------ src/domdiv/draw.py | 76 +++++++++++++++++------------ tox.ini | 1 + 8 files changed, 86 insertions(+), 78 deletions(-) delete mode 100644 setup.py diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml index 1772b872..c7ff897a 100644 --- a/.github/workflows/lint_and_test.yml +++ b/.github/workflows/lint_and_test.yml @@ -17,6 +17,6 @@ jobs: pip install -r requirements.txt pip install . - name: Lint - run: pre-commit run --all-files + run: pre-commit run --all-files --show-diff-on-failure -v - name: Test run: pytest diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 87b85830..248d34c0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -16,11 +16,11 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install -e .[dev] - name: Build and publish env: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - python setup.py sdist bdist_wheel + python -m build sdist bdist_wheel twine upload dist/* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3289c9b5..a20e3170 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,11 +5,11 @@ default_language_version: python: python3 repos: - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 24.3.0 hooks: - id: black - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -17,13 +17,13 @@ repos: - id: pretty-format-json args: [--autofix, --no-ensure-ascii, --indent=4] - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 + rev: 7.0.0 hooks: - id: flake8 args: [--max-line-length=120, "--ignore=E203,W503"] additional_dependencies: [flake8-bugbear] - repo: https://github.com/pycqa/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort name: isort (python) diff --git a/dodo.py b/dodo.py index eb5d7498..b37d3263 100644 --- a/dodo.py +++ b/dodo.py @@ -1,4 +1,3 @@ -import distutils.core import glob import os @@ -48,15 +47,13 @@ def task_build(): files = [ fname for fname in glob_no_dirs("src/domdiv/**/*") - + glob.glob("card_db_src/**/*.json" + "setup.py") + + glob.glob("card_db_src/**/*.json" + "pyproject.toml") if os.path.isfile(fname) ] return { "file_dep": files, "task_dep": ["update_languages"], - "actions": [ - lambda: True if distutils.core.run_setup("setup.py", "sdist") else False - ], + "actions": ["pip install -e .[dev]", "python -m build"], } @@ -66,4 +63,4 @@ def task_make_bgg_release(): def task_test(): files = glob_no_dirs("src/domdiv/**") - return {"file_dep": files, "actions": ["python setup.py test"]} + return {"file_dep": files, "actions": ["pip install -e .[dev]", "pytest"]} diff --git a/pyproject.toml b/pyproject.toml index d9122206..43aec4a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,4 +1,32 @@ + [build-system] -requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.3", "pytest-runner"] +requires = ["setuptools>=61", "setuptools_scm[toml]>=6"] +build-backend = "setuptools.build_meta" + +[project] +name = "domdiv" +dynamic = ["version"] +dependencies = ["reportlab", "Pillow", "configargparse"] +description = "Divider Generation for the Dominion Card Game" +keywords = ["boardgame", "cardgame", "dividers"] +authors = [{ name = "Peter Gorniak", email = "sumpfork@mailmight.net" }] +readme = "README.md" + +[project.urls] +"Say Thanks" = "https://boardgamegeek.com/thread/926575/web-page-generate-tabbed-dividers" +"Source" = "https://github.com/sumpfork/dominiontabs" +"Issue Tracker" = "https://github.com/sumpfork/dominiontabs/issues" +"Homepage" = "http://domtabs.sandflea.org" + +[project.optional-dependencies] +dev = ["build", "twine", "pre-commit", "doit", "pytest"] + +[project.scripts] +dominion_dividers = "domdiv.main:main" +domdiv_update_language = "domdiv.tools.update_language:run" +domdiv_bgg_release = "domdiv.tools.bgg_release:make_bgg_release" +domdiv_dedupe_cards = "domdiv.tools.cleanup_language_dupes:main" -[tools.setuptools_scm] +[tool.setuptools_scm] +# doing this break CI as the version file gets written when just `get_version` is called +# version_file = "src/domdiv/_version.py" diff --git a/setup.py b/setup.py deleted file mode 100644 index 135ca2b2..00000000 --- a/setup.py +++ /dev/null @@ -1,32 +0,0 @@ -from setuptools import setup - -setup( - name="domdiv", - entry_points={ - "console_scripts": [ - "dominion_dividers = domdiv.main:main", - "domdiv_update_language = domdiv.tools.update_language:run", - "domdiv_bgg_release = domdiv.tools.bgg_release:make_bgg_release", - "domdiv_dedupe_cards = domdiv.tools.cleanup_language_dupes:main", - ] - }, - package_dir={"": "src"}, - packages=["domdiv"], - use_scm_version=True, - setup_requires=["setuptools_scm", "pytest-runner"], - install_requires=["reportlab", "Pillow", "configargparse"], - tests_require=["pytest", "six", "pre-commit", "doit"], - url="http://domtabs.sandflea.org", - project_urls={ - "Say Thanks!": "https://boardgamegeek.com/thread/926575/web-page-generate-tabbed-dividers", - "Source": "https://github.com/sumpfork/dominiontabs", - "Tracker": "https://github.com/sumpfork/dominiontabs/issues", - }, - include_package_data=True, - author="Peter Gorniak", - author_email="sumpfork@mailmight.net", - description="Divider Generation for the Dominion Card Game", - keywords=["boardgame", "cardgame", "dividers"], - long_description="This script and library generate dividers for the Dominion Card Game by Rio Grande Games.\ - See it in action at http://domdiv.bgtools.net.", -) diff --git a/src/domdiv/draw.py b/src/domdiv/draw.py index 3022b6ff..1785004c 100644 --- a/src/domdiv/draw.py +++ b/src/domdiv/draw.py @@ -164,9 +164,9 @@ def __init__( 0 # Exact Centre special case, so swapping is still exact centre ) elif CardPlot.tabNumber == 1: - self.tabIndex = ( - self.tabIndexBack - ) = 1 # There is only one tab, so can only use 1 for both sides + self.tabIndex = self.tabIndexBack = ( + 1 # There is only one tab, so can only use 1 for both sides + ) elif 1 <= self.tabIndex <= CardPlot.tabNumber: self.tabIndexBack = CardPlot.tabNumber + 1 - self.tabIndex else: @@ -629,9 +629,11 @@ def registerFonts(self): pdfmetrics.registerFont( TTFont( font, - fontpath - if is_local - else pkg_resources.resource_filename("domdiv", fontpath), + ( + fontpath + if is_local + else pkg_resources.resource_filename("domdiv", fontpath) + ), ) ) registered[font] = fontpath @@ -786,9 +788,7 @@ def drawPanelOutline( line = ( plotter.LINE if lineType.lower() == "line" - else plotter.DOT - if lineType.lower() == "dot" - else NO_LINE + else plotter.DOT if lineType.lower() == "dot" else NO_LINE ) # lines ending at a midpoint (no dots) midline = NO_LINE if line == plotter.DOT else line @@ -1012,9 +1012,7 @@ def tabHeight(panelStyle, panelHeight): return ( panelHeight if panelStyle in ["tab", "strap"] - else item.tabHeight - if panelStyle == "folder" - else 0.0 + else item.tabHeight if panelStyle == "folder" else 0.0 ) headTabHeight = tabHeight(self.options.head, headHeight) @@ -1692,11 +1690,15 @@ def drawTab(self, item, panel=None, backside=False): side = ( CardPlot.CENTRE if self.options.tab_name_align == "centre" or self.wantCentreTab(card) - else CardPlot.LEFT - if self.options.tab_name_align == "left" - else CardPlot.RIGHT - if self.options.tab_name_align == "right" - else item.getClosestSide(backside=backside) + else ( + CardPlot.LEFT + if self.options.tab_name_align == "left" + else ( + CardPlot.RIGHT + if self.options.tab_name_align == "right" + else item.getClosestSide(backside=backside) + ) + ) ) # calculate x position and write text @@ -2170,24 +2172,36 @@ def calculatePages(self, cards): options.headHeight = ( 0.0 if options.head == "none" - else options.head_height * cm - if options.head_height - else options.dividerBaseHeight + options.labelHeight - if options.head == "folder" - else options.dividerBaseHeight - if options.head == "cover" - else options.labelHeight # tab or strap + else ( + options.head_height * cm + if options.head_height + else ( + options.dividerBaseHeight + options.labelHeight + if options.head == "folder" + else ( + options.dividerBaseHeight + if options.head == "cover" + else options.labelHeight + ) + ) + ) # tab or strap ) options.tailHeight = ( 0.0 if options.tail in ["none", "tab"] # not a real tab - else options.tail_height * cm - if options.tail_height - else options.dividerBaseHeight + options.labelHeight - if options.tail == "folder" - else options.dividerBaseHeight - if options.tail == "cover" - else options.labelHeight # strap + else ( + options.tail_height * cm + if options.tail_height + else ( + options.dividerBaseHeight + options.labelHeight + if options.tail == "folder" + else ( + options.dividerBaseHeight + if options.tail == "cover" + else options.labelHeight + ) + ) + ) # strap ) # Set Height diff --git a/tox.ini b/tox.ini index dd24d24a..5f277a5c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,6 @@ [tox] envlist = py39 +isolated_build = True [testenv] deps = pytest From 0a862204dac1e1073d052e7f4ac72b31bfecba9b Mon Sep 17 00:00:00 2001 From: Peter Gorniak Date: Wed, 20 Mar 2024 16:13:26 -0700 Subject: [PATCH 2/2] update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 96dcf65a..803c67a5 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,11 @@ The library will be installed as `domdiv` with the main entry point being `domdi ## Developing -Install requirements via `pip install -r requirements.txt`. Then, run `pre-commit install`. You can use `python setup.py develop` to install the `dominion_dividers` script so that it calls your checked out code, enabling you to run edited code without having to perform an install every time. +Install requirements via `pip install -r requirements.txt`. Then, run `pre-commit install`. You can use `pip install -e .[dev]` to install the `dominion_dividers` script so that it calls your checked out code, enabling you to run edited code without having to perform an install every time. This also installs needed dev dependencies. Feel free to comment on boardgamegeek at or file issues on github (). -Tests can be run (and their dependencies installed) via `python setup.py test`, which will also happen if/when you push a branch or make a PR. +Tests can be run (and their dependencies installed) via `pip install .[dev]` and then `doit test`. They will also run if/when you push a branch or make a PR. ## Image Sources