Skip to content

Commit

Permalink
Update buildsystem (#506)
Browse files Browse the repository at this point in the history
* Update buildsystem to use pyproject.toml and the "build" package
  • Loading branch information
sumpfork authored Mar 20, 2024
1 parent 98a7589 commit 26af613
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ 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
- id: check-json
- 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)
Expand Down
9 changes: 3 additions & 6 deletions dodo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import distutils.core
import glob
import os

Expand Down Expand Up @@ -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"],
}


Expand All @@ -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"]}
32 changes: 30 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]" }]
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"
32 changes: 0 additions & 32 deletions setup.py

This file was deleted.

76 changes: 45 additions & 31 deletions src/domdiv/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tox]
envlist = py39
isolated_build = True

[testenv]
deps = pytest
Expand Down

0 comments on commit 26af613

Please sign in to comment.