diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml index aff4154e..1aac897a 100644 --- a/.github/workflows/lint_and_test.yml +++ b/.github/workflows/lint_and_test.yml @@ -22,6 +22,6 @@ jobs: sudo apt update sudo apt install python3-icu - 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/README.md b/README.md index 9491cba6..5d66e001 100644 --- a/README.md +++ b/README.md @@ -40,11 +40,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 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 805f28c7..0fab4bfc 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: @@ -703,9 +703,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 @@ -860,9 +862,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 @@ -1086,9 +1086,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) @@ -1767,11 +1765,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 @@ -2245,24 +2247,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