Don't use invalid python constant
[vapoursynth.git] / setup.py
blobf925ba57fd9999c761947e3452f177f6807ef03c
1 #!/usr/bin/env python
3 from os import curdir
4 from os.path import dirname, exists, join
5 from pathlib import Path
6 from platform import architecture
7 from shutil import which
9 from setuptools import Extension, setup
11 is_win = (architecture()[1] == "WindowsPE")
12 is_64 = (architecture()[0] == "64bit")
14 extra_data = {}
16 library_dirs = [curdir, "build"]
18 is_portable = False
19 self_path = Path(__file__).resolve()
20 CURRENT_RELEASE = self_path.parent.joinpath('VAPOURSYNTH_VERSION').read_text('utf8').split(' ')[-1].strip().split('-')[0]
22 if is_win:
23 if is_64:
24 library_dirs.append(join("msvc_project", "x64", "Release"))
25 lib_suffix = "lib64"
26 else:
27 library_dirs.append(join("msvc_project", "Release"))
28 lib_suffix = "lib32"
31 # This code detects the library directory by querying the Windows Registry
32 # for the current VapourSynth directory location.
35 import winreg
36 REGISTRY_PATH = r"SOFTWARE\VapourSynth"
37 REGISTRY_KEY = "VapourSynthDLL"
38 REGISTRY_KEY_PATH = "Path"
40 def query(hkey, path, key):
41 reg_key = None
42 try:
43 reg_key = winreg.OpenKey(hkey, path, 0, winreg.KEY_READ)
44 value, _ = winreg.QueryValueEx(reg_key, key)
45 finally:
46 if reg_key is not None:
47 winreg.CloseKey(reg_key)
49 return value
51 # Locate the vapoursynth dll inside the library directories first
52 # should we find it, it is a clear indicator that VapourSynth
53 # has been compiled by the user.
54 for path in library_dirs:
55 dll_path = join(path, "vapoursynth.dll")
56 if exists(dll_path):
57 break
58 else:
59 # In case the user did not compile vapoursynth by themself, we will then
60 # hit the path.
62 # This is an indicator for portable installations.
63 is_portable = True
65 dll_path = which("vapoursynth.dll")
66 if dll_path is None:
67 # If the vapoursynth.dll is not located in PATH, we then hit the registry
68 try:
69 dll_path = query(winreg.HKEY_LOCAL_MACHINE, REGISTRY_PATH, REGISTRY_KEY)
70 except:
71 # Give up.
72 raise OSError("Couldn't detect vapoursynth installation path")
73 else:
74 # Since the SDK is on a different directory than the DLL insert the SDK to library_dirs
75 sdkpath = join(query(winreg.HKEY_LOCAL_MACHINE, REGISTRY_PATH, REGISTRY_KEY_PATH), "sdk", lib_suffix)
76 if not exists(sdkpath):
77 raise OSError("It appears you don't have the sdk installed. Please make sure you installed the sdk before running setup.py")
78 library_dirs.append(sdkpath)
80 # Insert the DLL Path to the library dirs
81 if dll_path:
82 library_dirs.append(dirname(dll_path))
84 # Make sure the setup process copies the VapourSynth.dll into the site-package folder
85 print("Found VapourSynth.dll at:", dll_path)
87 extra_data["data_files"] = [(r"Lib\site-packages", [dll_path])]
90 setup(
91 name="VapourSynth",
92 description="A frameserver for the 21st century",
93 url="https://www.vapoursynth.com/",
94 download_url="https://github.com/vapoursynth/vapoursynth",
95 author="Fredrik Mellbin",
96 author_email="fredrik.mellbin@gmail.com",
97 license="LGPL 2.1 or later",
98 version=CURRENT_RELEASE,
99 long_description="A portable replacement for Avisynth" if is_portable else "A modern replacement for Avisynth",
100 platforms="All",
101 ext_modules=[
102 Extension(
103 "vapoursynth", [join("src", "cython", "vapoursynth.pyx")],
104 define_macros=[("VS_USE_LATEST_API", None), ("VS_GRAPH_API", None), ("VS_CURRENT_RELEASE", CURRENT_RELEASE)],
105 libraries=["vapoursynth"],
106 library_dirs=library_dirs,
107 include_dirs=[
108 curdir,
109 join("src", "cython"),
110 join("src", "vsscript")
114 setup_requires=[
115 'setuptools>=18.0',
116 "Cython",
118 exclude_package_data={"": ("VAPOURSYNTH_VERSION",)},
119 **extra_data