1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
|
#! /usr/bin/env python3
from glob import glob
from os import listdir
from os.path import isdir, isfile
import os
import site
import sys
import subprocess
this_dir = os.path.dirname(os.path.abspath(__file__))
sys.path = [os.path.join(this_dir, "lib")] + sys.path
msi = False
if "bdist_msi" in sys.argv[1:]:
try:
from cx_Freeze import setup, Executable
msi = True
except ImportError:
print("ERROR: can't import cx_Freeze!")
sys.exit(1)
else:
from setuptools import setup
if sys.platform == "win32":
try:
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
print(
"Gtk version is %s.%s.%s"
% (Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION, Gtk.MICRO_VERSION),
)
except ImportError:
print("ERROR: PyChess in Windows Platform requires to install PyGObject.")
print("Installing from http://sourceforge.net/projects/pygobjectwin32")
sys.exit(1)
import importlib.util
import importlib.machinery
spec = importlib.machinery.PathFinder().find_spec("pychess", ["lib"])
pychess = importlib.util.module_from_spec(spec)
spec.loader.exec_module(pychess)
VERSION = pychess.VERSION
NAME = "pychess"
DESC = "Chess client"
LONG_DESC = """PyChess is a chess client for playing and analyzing chess games. It is
intended to be usable both for those totally new to chess as well as
advanced users who want to use a computer to further enhance their play.
PyChess has a builtin python chess engine and auto-detects most
popular chess engines (Stockfish, Rybka, Houdini, Shredder, GNU Chess,
Crafty, Fruit, and many more). These engines are available as opponents,
and are used to provide hints and analysis. PyChess also shows analysis
from opening books and Gaviota end-game tablebases.
When you get sick of playing computer players you can login to FICS (the
Free Internet Chess Server) and play against people all over the world.
PyChess has a built-in Timeseal client, so you won't lose clock time during
a game due to lag. PyChess also has pre-move support, which means you can
make (or start making) a move before your opponent has made their move.
PyChess has many other features including:
- CECP and UCI chess engine support with customizable engine configurations
- Polyglot opening book support
- Hint and Spy move arrows
- Hint, Score, and Annotation panels
- Play and analyze games in separate game tabs
- 18 chess variants including Chess960, Suicide, Crazyhouse, Shuffle, Losers, Piece Odds, and Atomic
- Reads and writes PGN, EPD and FEN chess file formats
- Undo and pause chess games
- Move animation in games
- Drag and drop chess files
- Optional game move and event sounds
- Chess piece themes with 40 built-in piece themes
- Legal move highlighting
- Direct copy+paste pgn game input via Enter Game Notation open-game dialog
- Internationalised text and Figurine Algebraic Notation (FAN) support
- Translated into 38 languages (languages with +5% strings translated)
- Easy to use and intuitive look and feel"""
CLASSIFIERS = [
"Development Status :: 3 - Alpha",
"Environment :: X11 Applications :: GTK",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: POSIX",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Games/Entertainment :: Board Games",
]
os.chdir(os.path.abspath(os.path.dirname(__file__)))
# save
stderr = sys.stderr
stdout = sys.stdout
if not isfile("eco.db"):
print(
"ERROR: File 'eco.db' is missing, please generate using command:\n"
" # PYTHONPATH=lib python3 pgn2ecodb.py",
file=sys.stderr,
)
sys.exit(1)
if not isfile(os.path.abspath("pieces/Spatial.png")):
print(
"ERROR: Preview images of pieces themes are missing, please generate using command:\n"
" # PYTHONPATH=lib python3 create_theme_preview.py",
file=sys.stderr,
)
sys.exit(1)
# restore
sys.stderr = stderr
sys.stdout = stdout
DATA_FILES = [
(
"share/pychess",
[
"README.md",
"AUTHORS",
"ARTISTS",
"DOCUMENTERS",
"LICENSE",
"TRANSLATORS",
"pychess_book.bin",
"eco.db",
],
)
]
# UI
DATA_FILES += [("share/pychess/glade", glob("glade/*.glade"))]
DATA_FILES += [("share/pychess/glade", ["glade/background.jpg"])]
DATA_FILES += [("share/pychess/glade", glob("glade/*.png"))]
DATA_FILES += [("share/pychess/glade/16x16", glob("glade/16x16/*.png"))]
DATA_FILES += [("share/pychess/glade/48x48", glob("glade/48x48/*.png"))]
DATA_FILES += [("share/pychess/glade", glob("glade/*.svg"))]
DATA_FILES += [("share/pychess/flags", glob("flags/*.png"))]
DATA_FILES += [("share/pychess/boards", glob("boards/*.png"))]
# Data
DATA_FILES += [("share/mime/packages", ["pychess.xml"])]
DATA_FILES += [("share/metainfo", ["pychess.metainfo.xml"])]
DATA_FILES += [("share/applications", ["pychess.desktop"])]
DATA_FILES += [("share/icons/hicolor/scalable/apps", ["pychess.svg"])]
if sys.platform == "win32":
DATA_FILES += [("share/pychess/sounds", glob("sounds/*.wav"))]
DATA_FILES += [("share/pychess/engines", glob("engines/*.*"))]
else:
DATA_FILES += [("share/pychess/sounds", glob("sounds/*.ogg"))]
DATA_FILES += [("share/icons/hicolor/24x24/apps", ["pychess.png"])]
DATA_FILES += [
(
"share/gtksourceview-3.0/language-specs",
["gtksourceview-3.0/language-specs/pgn.lang"],
)
]
# Piece sets
DATA_FILES += [("share/pychess/pieces", glob("pieces/*.png"))]
if not isfile(os.path.abspath("learn/puzzles/mate_in_4.sqlite")):
from pychess.Savers.pgn import PGNFile
from pychess.System.protoopen import protoopen
# Lectures, puzzles, lessons
for filename in glob("learn/puzzles/*.pgn"):
chessfile = PGNFile(protoopen(filename))
chessfile.init_tag_database()
for filename in glob("learn/lessons/*.pgn"):
chessfile = PGNFile(protoopen(filename))
chessfile.init_tag_database()
DATA_FILES += [("share/pychess/learn/puzzles", glob("learn/puzzles/*.olv"))]
DATA_FILES += [("share/pychess/learn/puzzles", glob("learn/puzzles/*.pgn"))]
DATA_FILES += [("share/pychess/learn/puzzles", glob("learn/puzzles/*.sqlite"))]
DATA_FILES += [("share/pychess/learn/lessons", glob("learn/lessons/*.pgn"))]
DATA_FILES += [("share/pychess/learn/lessons", glob("learn/lessons/*.sqlite"))]
DATA_FILES += [("share/pychess/learn/lectures", glob("learn/lectures/*.txt"))]
for dir in [d for d in listdir("pieces") if isdir(os.path.join("pieces", d))]:
DATA_FILES += [("share/pychess/pieces/" + dir, glob("pieces/" + dir + "/*.svg"))]
# Manpages
DATA_FILES += [("share/man/man1", ["manpages/pychess.1.gz"])]
# Language
pofile = "LC_MESSAGES/pychess"
if sys.platform == "win32":
argv0_path = os.path.dirname(os.path.abspath(sys.executable))
if pychess.MSYS2:
major, minor, micro, releaselevel, serial = sys.version_info
msgfmt_path = argv0_path + "/../lib/python{}.{}/tools/i18n/".format(
major, minor
)
else:
msgfmt_path = argv0_path + "/tools/i18n/"
msgfmt = f"{os.path.abspath(sys.executable)} {msgfmt_path}msgfmt.py"
else:
msgfmt = "msgfmt"
pychess_langs = []
for dir in [d for d in listdir("lang") if isdir("lang/" + d) and d != "en"]:
if sys.platform == "win32":
command = f"{msgfmt} lang/{dir}/{pofile}.po"
else:
command = "{} lang/{}/{}.po -o lang/{}/{}.mo".format(
msgfmt, dir, pofile, dir, pofile
)
subprocess.call(command.split())
DATA_FILES += [
("share/locale/" + dir + "/LC_MESSAGES", ["lang/" + dir + "/" + pofile + ".mo"])
]
pychess_langs.append(dir)
PACKAGES = []
if msi:
if pychess.MSYS2:
gtk_data_path = sys.prefix
gtk_exec_path = os.path.join(sys.prefix, "bin")
lang_path = os.path.join(sys.prefix, "share", "locale")
else:
# Get the site-package folder, not everybody will install
# Python into C:\PythonXX
site_dir = site.getsitepackages()[1]
gtk_data_path = os.path.join(site_dir, "gnome")
gtk_exec_path = os.path.join(site_dir, "gnome")
lang_path = os.path.join(site_dir, "gnome", "share", "locale")
# gtk3.0 .mo files
gtk_mo = [
f + "/LC_MESSAGES/gtk30.mo" for f in os.listdir(lang_path) if f in pychess_langs
]
# Collect the list of missing dll when cx_freeze builds the app
gtk_exec = [
"libgtksourceview-3.0-1.dll",
"libjpeg-8.dll",
"librsvg-2-2.dll",
"libwinpthread-1.dll",
]
# We need to add all the libraries too (for themes, etc..)
gtk_data = [
"etc",
"lib/gdk-pixbuf-2.0",
"lib/girepository-1.0",
"share/icons/Adwaita/icon-theme.cache",
"share/icons/Adwaita/index.theme",
"share/icons/Adwaita/16x16",
"share/icons/Adwaita/scalable",
"share/glib-2.0",
]
# Create the list of includes as cx_freeze likes
include_files = []
for mo in gtk_mo:
mofile = os.path.join(lang_path, mo)
if os.path.isfile(mofile):
include_files.append((mofile, "share/locale/" + mo))
for dll in gtk_exec:
include_files.append((os.path.join(gtk_exec_path, dll), dll))
# Let's add gtk data
for lib in gtk_data:
include_files.append((os.path.join(gtk_data_path, lib), lib))
base = None
# Lets not open the console while running the app
if sys.platform == "win32":
base = "Win32GUI"
executables = [
Executable(
"pychess",
base=base,
icon="pychess.ico",
shortcut_name="PyChess",
shortcut_dir="DesktopFolder",
),
Executable(
script="lib/__main__.py", target_name="pychess-engine.exe", base=base
),
]
bdist_msi_options = {
"upgrade_code": "{5167584f-c196-428f-be40-4c861025e90a}",
"add_to_path": False,
}
perspectives = ["pychess.perspectives"]
for persp in ("welcome", "games", "fics", "database", "learn"):
perspectives.append("pychess.perspectives.%s" % persp)
build_exe_options = {
"path": sys.path + ["lib"],
"includes": ["gi"],
"packages": [
"asyncio",
"gi",
"sqlalchemy.dialects.sqlite",
"sqlalchemy.sql.default_comparator",
"pexpect",
"pychess",
]
+ perspectives,
"include_files": include_files,
}
if pychess.MSYS2:
build_exe_options["excludes"] = ["tkinter"]
else:
build_exe_options["include_msvcr"] = True
kwargs = dict(
options={"build_exe": build_exe_options, "bdist_msi": bdist_msi_options},
executables=executables,
)
else:
PACKAGES = [
"pychess",
"pychess.gfx",
"pychess.ic",
"pychess.ic.managers",
"pychess.Players",
"pychess.Savers",
"pychess.System",
"pychess.Utils",
"pychess.Utils.lutils",
"pychess.Variants",
"pychess.Database",
"pychess.widgets",
"pychess.widgets.pydock",
"pychess.perspectives",
"pychess.perspectives.welcome",
"pychess.perspectives.games",
"pychess.perspectives.fics",
"pychess.perspectives.database",
"pychess.perspectives.learn",
"pychess.external",
]
kwargs = {}
setup(
name=NAME,
version=VERSION,
author="Pychess team",
author_email="pychess-people@googlegroups.com",
maintainer="Thomas Dybdahl Ahle",
classifiers=CLASSIFIERS,
keywords="python gtk chess xboard gnuchess game pgn epd board linux",
description=DESC,
long_description=LONG_DESC,
license="GPL3",
url="https://pychess.github.io/",
download_url="https://github.com/pychess/pychess/releases",
python_requires=">=3.8",
install_requires=[
"pexpect",
"psutil",
"pycairo",
"PyGObject",
"SQLAlchemy>=2",
"websockets",
],
extras_require={
"gbulb": [
"gbulb",
],
},
package_dir={"": "lib"},
packages=PACKAGES,
data_files=DATA_FILES,
scripts=["pychess"],
**kwargs,
)
|