22
33from __future__ import annotations
44
5- import contextlib
65import ctypes .util
76import functools
87import os
98import platform
109import shutil
1110import sys
1211from configparser import ConfigParser
13- from distutils .util import get_platform
1412from fnmatch import fnmatch
13+ from sysconfig import get_platform
1514from time import strftime
1615
1716from py2exe import freeze
1817
19-
20- # Borrowed from setuptools
21- def _find_all_simple (path : str ) -> list [str ]:
22- """Find all files under 'path'.
23-
24- Args:
25- path (str): The directory path to search for files.
26-
27- Returns:
28- list[str]: A list of full filenames found under the specified path.
29- """
30- results = (
31- os .path .join (base , file )
32- for base , dirs , files in os .walk (path , followlinks = True )
33- for file in files
34- )
35- return filter (os .path .isfile , results )
36-
37-
38- def findall (directory : str = os .curdir ) -> list [str ]:
39- """Find all files under 'dir' and return the list of full filenames.
40-
41- Unless dir is '.', return full filenames with dir prepended.
42-
43- Args:
44- directory (str, optional): The directory path to search for files.
45- Defaults to the current directory.
46-
47- Returns:
48- list[str]: A list of full filenames found under the specified
49- directory.
50- """
51- files = _find_all_simple (directory )
52- if directory == os .curdir :
53- make_rel = functools .partial (os .path .relpath , start = directory )
54- files = map (make_rel , files )
55- return list (files )
56-
57-
58- import distutils .filelist
59-
60- distutils .filelist .findall = findall # Fix findall bug in distutils
61-
62-
63- bits = platform .architecture ()[0 ][:2 ]
6418pypath = os .path .abspath (__file__ )
6519pydir = os .path .dirname (pypath )
6620source_dir = os .path .dirname (pydir )
@@ -73,15 +27,7 @@ def findall(directory: str = os.curdir) -> list[str]:
7327from DisplayCAL .meta import (
7428 APPSTREAM_ID ,
7529 AUTHOR ,
76- AUTHOR_ASCII ,
77- AUTHOR_EMAIL ,
78- DESCRIPTION ,
79- DEVELOPMENT_HOME_PAGE ,
80- DOMAIN ,
81- LONG_DESCRIPTION ,
8230 NAME ,
83- PY_MAXVERSION ,
84- PY_MINVERSION ,
8531 VERSION_STRING ,
8632 VERSION_TUPLE ,
8733 script2pywname ,
@@ -339,9 +285,7 @@ def build_py2exe() -> None:
339285 use_sdl = False
340286 sys .path .insert (1 , os .path .join (pydir , ".." , "util" ))
341287
342- setuptools = True
343288 debug = False
344- dry_run = False
345289 # do_full_install = False
346290
347291 doc = "."
@@ -355,11 +299,6 @@ def build_py2exe() -> None:
355299 else :
356300 print ("WARNING: cacert.pem from certifi project not found!" )
357301
358- # on Mac OS X and Windows, we want data files in the package dir
359- # (package_data will be ignored when using py2exe)
360- package_data = {
361- NAME : ["theme/icons/22x22/*.png" , "theme/icons/24x24/*.png" ],
362- }
363302 scripts = get_scripts ()
364303 # Doc files
365304 data_files = []
@@ -485,95 +424,14 @@ def build_py2exe() -> None:
485424 desktopicons ,
486425 )
487426 )
488- ext_modules = []
489- requires = []
490- requires .append ("pywin32 (>= 213.0)" )
491- packages = [NAME , f"{ NAME } .lib" , f"{ NAME } .lib.agw" ]
492- # On Windows we want separate libraries
493- packages .extend (
494- [
495- f"{ NAME } .lib{ bits } " ,
496- f"{ NAME } .lib{ bits } .python{ sys .version_info [0 ]} { sys .version_info [1 ]} " ,
497- ]
498- )
499-
427+ # `attrs` only carries the fields py2exe_kwargs (further below) actually
428+ # reads: name/version/classifiers/description/license/entry_points/
429+ # package_data/etc. all live in pyproject.toml's `[project]` table (see
430+ # DisplayCAL/setup.py's own `attrs`), and were never passed to a real
431+ # setup() call from here to begin with.
500432 attrs = {
501- "author" : AUTHOR_ASCII ,
502- "author_email" : AUTHOR_EMAIL ,
503- "classifiers" : [
504- "Development Status :: 5 - Production/Stable" ,
505- "Environment :: MacOS X" ,
506- "Environment :: Win32 (MS Windows)" ,
507- "Environment :: X11 Applications" ,
508- "Intended Audience :: End Users/Desktop" ,
509- "License :: OSI Approved :: GNU General Public License v3 "
510- "or later (GPLv3+)" ,
511- "Operating System :: OS Independent" ,
512- "Programming Language :: Python :: 3.9" ,
513- "Programming Language :: Python :: 3.10" ,
514- "Programming Language :: Python :: 3.11" ,
515- "Programming Language :: Python :: 3.12" ,
516- "Programming Language :: Python :: 3.13" ,
517- "Programming Language :: Python :: 3.14" ,
518- "Topic :: Multimedia :: Graphics" ,
519- ],
520433 "data_files" : data_files ,
521- "description" : DESCRIPTION ,
522- "download_url" : f"{ DEVELOPMENT_HOME_PAGE } /releases/download/"
523- f"{ VERSION_STRING } /{ NAME } -{ VERSION_STRING } .tar.gz" ,
524- "ext_modules" : ext_modules ,
525- "license" : "GPL v3" ,
526- "long_description" : LONG_DESCRIPTION ,
527- "long_description_content_type" : "text/x-rst" ,
528- "name" : NAME ,
529- "packages" : packages ,
530- "package_data" : package_data ,
531- "package_dir" : {NAME : NAME },
532- "platforms" : [
533- "Python >= {} <= {}" .format (
534- "." .join (str (n ) for n in PY_MINVERSION ),
535- "." .join (str (n ) for n in PY_MAXVERSION ),
536- ),
537- "Linux/Unix with X11" ,
538- "Mac OS X >= 10.4" ,
539- "Windows 2000 and newer" ,
540- ],
541- "requires" : requires ,
542- "provides" : [NAME ],
543- "scripts" : [],
544- "url" : f"https://{ DOMAIN } /" ,
545- "version" : msiversion if "bdist_msi" in sys .argv [1 :] else VERSION_STRING ,
546434 }
547- if setuptools :
548- attrs ["entry_points" ] = {
549- "gui_scripts" : [
550- "{} = {}.main:main{}" .format (
551- script ,
552- NAME ,
553- (
554- ""
555- if script == NAME .lower ()
556- else script [len (NAME ) :].lower ().replace ("-" , "_" )
557- ),
558- )
559- for script , desc in scripts
560- ]
561- }
562- attrs ["exclude_package_data" ] = {}
563- attrs ["include_package_data" ] = False
564- install_requires = [req .replace ("(" , "" ).replace (")" , "" ) for req in requires ]
565- attrs ["install_requires" ] = install_requires
566- attrs ["zip_safe" ] = False
567- else :
568- attrs ["scripts" ].extend (
569- os .path .join ("scripts" , script )
570- for script , desc in [
571- script_desc
572- for script_desc in scripts
573- if script_desc [0 ] != f"{ NAME .lower ()} -apply-profiles"
574- or sys .platform != "darwin"
575- ]
576- )
577435
578436 from winmanifest_util import getmanifestxml
579437
@@ -748,91 +606,8 @@ def build_py2exe() -> None:
748606 attrs ["options" ]["py2exe" ].update (
749607 {"bundle_files" : 3 , "compressed" : 0 , "optimize" : 0 , "skip_archive" : 1 }
750608 )
751- if setuptools :
752- attrs ["setup_requires" ] = ["py2exe" ]
753609 attrs ["zipfile" ] = os .path .join ("lib" , "library.zip" )
754610
755- # To have a working sdist and bdist_rpm when using distutils,
756- # we go to the length of generating MANIFEST.in from scratch everytime,
757- # using the information available from setup.
758- manifest_in = ["# This file will be re-generated by setup.py - do not edit" ]
759- manifest_in .extend (
760- [
761- "include LICENSE.txt" ,
762- "include MANIFEST" ,
763- "include MANIFEST.in" ,
764- "include README.html" ,
765- "include README-fr.html" ,
766- "include CHANGES.html" ,
767- f"include { NAME } *.pyw" ,
768- f"include { NAME } -*.pyw" ,
769- f"include { NAME } -*.py" ,
770- "include use-distutils" ,
771- f"include { NAME } /VERSION" ,
772- ]
773- )
774- manifest_in .append ("include " + os .path .basename (sys .argv [0 ]))
775- manifest_in .append (
776- "include " + os .path .splitext (os .path .basename (sys .argv [0 ]))[0 ] + ".cfg"
777- )
778- for _datadir , datafiles in attrs .get ("data_files" , []):
779- for datafile in datafiles :
780- datafile_relpath = None
781- with contextlib .suppress (ValueError ):
782- datafile_relpath = os .path .relpath (
783- os .path .sep .join (datafile .split ("/" )), source_dir
784- )
785- manifest_in .append (f"include { datafile_relpath or datafile } " )
786- for extmod in attrs .get ("ext_modules" , []):
787- manifest_in .extend (
788- f"include { os .path .sep .join (src .split ('/' ))} " for src in extmod .sources
789- )
790- for pkg in attrs .get ("packages" , []):
791- pkg = os .path .join (* pkg .split ("." ))
792- pkgdir = os .path .sep .join (attrs .get ("package_dir" , {}).get (pkg , pkg ).split ("/" ))
793- manifest_in .append ("include " + os .path .join (pkgdir , "*.py" ))
794- # manifest_in.append("include " + os.path.join(pkgdir, "*.pyd"))
795- # manifest_in.append("include " + os.path.join(pkgdir, "*.so"))
796- for obj in attrs .get ("package_data" , {}).get (pkg , []):
797- print (f"obj: { obj } " )
798- manifest_in .append (f"include { os .path .sep .join ([pkgdir , * obj .split ('/' )])} " )
799- manifest_in .extend (
800- "include {}" .format (os .path .join (* pymod .split ("." )))
801- for pymod in attrs .get ("py_modules" , [])
802- )
803- manifest_in .append (
804- "include {}" .format (os .path .join (NAME , "theme" , "theme-info.txt" ))
805- )
806- manifest_in .append (
807- "recursive-include {} {} {}" .format (
808- os .path .join (NAME , "theme" , "icons" ), "*.icns" , "*.ico"
809- )
810- )
811- manifest_in .append ("include {}" .format (os .path .join ("man" , "*.1" )))
812- manifest_in .append ("recursive-include misc *" )
813- # if skip_instrument_conf_files:
814- # manifest_in.extend(
815- # [
816- # "exclude misc/Argyll",
817- # "exclude misc/*.rules",
818- # "exclude misc/*.usermap",
819- # ]
820- # )
821- manifest_in .append ("include {}" .format (os .path .join ("screenshots" , "*.png" )))
822- manifest_in .append ("include {}" .format (os .path .join ("scripts" , "*" )))
823- manifest_in .append ("include {}" .format (os .path .join ("tests" , "*" )))
824- manifest_in .append ("recursive-include theme *" )
825- manifest_in .append ("recursive-include util *.cmd *.py *.sh" )
826- manifest_in .append ("global-exclude *~" )
827- manifest_in .append ("global-exclude *.backup" )
828- manifest_in .append ("global-exclude *.bak" )
829- manifest_in .append ("global-exclude */__pycache__/*" )
830- if not dry_run :
831- with open ("MANIFEST.in" , "w" ) as manifest :
832- manifest .write ("\n " .join (manifest_in ))
833- if os .path .exists ("MANIFEST" ):
834- os .remove ("MANIFEST" )
835-
836611 py2exe_kwargs = {
837612 "console" : attrs ["console" ],
838613 "windows" : attrs ["windows" ],
0 commit comments