Skip to content

Commit ffd21bb

Browse files
committed
Convert examples and testing to be more namespace friendly.
1 parent 3514445 commit ffd21bb

File tree

18 files changed

+57
-36
lines changed

18 files changed

+57
-36
lines changed

.github/workflows/python-package.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ jobs:
191191
pip install tcod-*.tar.gz
192192
- name: Confirm package import
193193
run: |
194-
python -c "import tcod"
194+
python -c "import tcod.context"
195195
196196
linux-wheels:
197197
needs: [black, isort, mypy]
@@ -232,7 +232,7 @@ jobs:
232232
yum-config-manager --enable epel &&
233233
yum install -y SDL2-devel
234234
CIBW_BEFORE_TEST: pip install numpy
235-
CIBW_TEST_COMMAND: python -c "import tcod"
235+
CIBW_TEST_COMMAND: python -c "import tcod.context"
236236
# Skip test on emulated architectures
237237
CIBW_TEST_SKIP: "*_aarch64"
238238
- name: Archive wheel
@@ -267,7 +267,7 @@ jobs:
267267
CIBW_ARCHS_MACOS: x86_64 arm64 universal2
268268
CIBW_BEFORE_BUILD_MACOS: pip install --upgrade delocate
269269
CIBW_BEFORE_TEST: pip install numpy
270-
CIBW_TEST_COMMAND: python -c "import tcod"
270+
CIBW_TEST_COMMAND: python -c "import tcod.context"
271271
CIBW_TEST_SKIP: "pp* *-macosx_arm64 *-macosx_universal2:arm64"
272272
- name: Archive wheel
273273
uses: actions/upload-artifact@v3

docs/installation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ You can then verify that ``tcod`` is importable from the Python interpreter::
5050

5151
>python
5252

53-
>>> import tcod
53+
>>> import tcod.context
5454

55-
If ``import tcod`` doesn't throw an ``ImportError`` then ``tcod`` has been installed correctly to your system libraries.
55+
If ``import tcod.context`` doesn't throw an ``ImportError`` then ``tcod`` has been installed correctly to your system libraries.
5656

5757
Some IDE's such as PyCharm will create a virtual environment which will ignore your system libraries and require tcod to be installed again in that new environment.
5858

docs/tcod/getting-started.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ Example::
2323

2424
#!/usr/bin/env python3
2525
# Make sure 'dejavu10x10_gs_tc.png' is in the same directory as this script.
26-
import tcod
26+
import tcod.console
27+
import tcod.context
28+
import tcod.event
29+
import tcod.tileset
2730

2831
WIDTH, HEIGHT = 80, 60 # Console width and height in tiles.
2932

@@ -35,7 +38,7 @@ Example::
3538
"dejavu10x10_gs_tc.png", 32, 8, tcod.tileset.CHARMAP_TCOD,
3639
)
3740
# Create the main console.
38-
console = tcod.Console(WIDTH, HEIGHT, order="F")
41+
console = tcod.console.Console(WIDTH, HEIGHT, order="F")
3942
# Create a window based on this console and tileset.
4043
with tcod.context.new( # New window for a console of size columns×rows.
4144
columns=console.width, rows=console.height, tileset=tileset,
@@ -87,7 +90,8 @@ clearing the console every frame and replacing it only on resizing the window.
8790
Example::
8891

8992
#!/usr/bin/env python3
90-
import tcod
93+
import tcod.context
94+
import tcod.event
9195

9296
WIDTH, HEIGHT = 720, 480 # Window pixel resolution (when not maximized.)
9397
FLAGS = tcod.context.SDL_WINDOW_RESIZABLE | tcod.context.SDL_WINDOW_MAXIMIZED

examples/distribution/PyInstaller/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import sys
88
from pathlib import Path
99

10-
import tcod
10+
import tcod.console
11+
import tcod.context
12+
import tcod.event
13+
import tcod.tileset
1114

1215
WIDTH, HEIGHT = 80, 60
1316

examples/distribution/cx_Freeze/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env python3
22
"""cx_Freeze main script example."""
3-
import tcod
3+
import tcod.console
4+
import tcod.context
5+
import tcod.event
6+
import tcod.tileset
47

58
WIDTH, HEIGHT = 80, 60
69
console = None

examples/eventget.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"""An demonstration of event handling using the tcod.event module."""
77
from typing import List, Set
88

9-
import tcod
9+
import tcod.context
10+
import tcod.event
1011
import tcod.sdl.joystick
1112
import tcod.sdl.sys
1213

examples/sdl-hello-world.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import numpy as np
55
from PIL import Image, ImageDraw, ImageFont # type: ignore # pip install Pillow
66

7-
import tcod
7+
import tcod.event
88
import tcod.sdl.render
99
import tcod.sdl.video
1010

examples/thread_jobs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import timeit
2121
from typing import Callable, List, Tuple
2222

23-
import tcod
23+
import tcod.map
2424

2525
THREADS = multiprocessing.cpu_count()
2626

examples/ttf.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
import numpy as np
1515
from numpy.typing import NDArray
1616

17-
import tcod
17+
import tcod.console
18+
import tcod.context
19+
import tcod.event
20+
import tcod.tileset
1821

1922
FONT = "VeraMono.ttf"
2023

@@ -60,7 +63,7 @@ def load_ttf(path: str, size: Tuple[int, int]) -> tcod.tileset.Tileset:
6063

6164
def main() -> None:
6265
"""True-type font example script."""
63-
console = tcod.Console(16, 12, order="F")
66+
console = tcod.console.Console(16, 12, order="F")
6467
with tcod.context.new(
6568
columns=console.width,
6669
rows=console.height,

tcod/console.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ def draw_frame(
10871087
10881088
Example::
10891089
1090-
>>> console = tcod.Console(12, 6)
1090+
>>> console = tcod.console.Console(12, 6)
10911091
>>> console.draw_frame(x=0, y=0, width=3, height=3)
10921092
>>> console.draw_frame(x=3, y=0, width=3, height=3, decoration="╔═╗║ ║╚═╝")
10931093
>>> console.draw_frame(x=6, y=0, width=3, height=3, decoration="123456789")
@@ -1272,7 +1272,8 @@ def load_xp(path: str | PathLike[str], order: Literal["C", "F"] = "C") -> tuple[
12721272
Example::
12731273
12741274
import numpy as np
1275-
import tcod
1275+
import tcod.console
1276+
import tcod.tileset
12761277
12771278
path = "example.xp" # REXPaint file with one layer.
12781279
@@ -1321,9 +1322,10 @@ def save_xp(
13211322
Example::
13221323
13231324
import numpy as np
1324-
import tcod
1325+
import tcod.console
1326+
import tcod.tileset
13251327
1326-
console = tcod.Console(80, 24) # Example console.
1328+
console = tcod.console.Console(80, 24) # Example console.
13271329
13281330
# Convert from Unicode to REXPaint's encoding.
13291331
# Required to load this console correctly in the REXPaint tool.

0 commit comments

Comments
 (0)