From da6e2c9432a040c1c0e12ab6ae38ef67ea57b1e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= Date: Wed, 29 May 2024 23:02:15 +0100 Subject: [PATCH] chore: improved inclusion of header and source files Should make it possible to handle missing header files. --- scripts/make_crx.py | 37 +++++--- scripts/make_xpi.py | 8 +- setup.py | 121 +++++++++++--------------- src/python/npcolony_py/test/global.py | 1 + 4 files changed, 87 insertions(+), 80 deletions(-) diff --git a/scripts/make_crx.py b/scripts/make_crx.py index cedea21..759f37d 100644 --- a/scripts/make_crx.py +++ b/scripts/make_crx.py @@ -12,17 +12,29 @@ not os.path.exists(target_path) and os.mkdir(target_path) not os.path.exists(temporary_path) and os.mkdir(temporary_path) -specification_path = os.path.normpath(os.path.join(directory_path, "../src/colony_npapi/descriptors/manifest.json")) -library_win_path = os.path.normpath(os.path.join(directory_path, "../" + base_path + "/npcolony.dll")) -library_linux_path = os.path.normpath(os.path.join(directory_path, "../" + base_path + "/libnpcolony.so")) -library_mac_path = os.path.normpath(os.path.join(directory_path, "../" + base_path + "/npcolony.plugin")) -images_path = os.path.normpath(os.path.join(directory_path, "../src/colony_npapi/descriptors/images")) +specification_path = os.path.normpath( + os.path.join(directory_path, "../src/colony_npapi/descriptors/manifest.json") +) +library_win_path = os.path.normpath( + os.path.join(directory_path, "../" + base_path + "/npcolony.dll") +) +library_linux_path = os.path.normpath( + os.path.join(directory_path, "../" + base_path + "/libnpcolony.so") +) +library_mac_path = os.path.normpath( + os.path.join(directory_path, "../" + base_path + "/npcolony.plugin") +) +images_path = os.path.normpath( + os.path.join(directory_path, "../src/colony_npapi/descriptors/images") +) shutil.copyfile(specification_path, temporary_path + "/manifest.json") shutil.copyfile(library_win_path, temporary_path + "/npcolony.dll") shutil.copytree(images_path, temporary_path + "/images") -if os.path.exists(library_linux_path): shutil.copyfile(library_linux_path, temporary_path + "/libnpcolony.so") -if os.path.exists(library_mac_path): shutil.copytree(library_mac_path, temporary_path + "/npcolony.plugin") +if os.path.exists(library_linux_path): + shutil.copyfile(library_linux_path, temporary_path + "/libnpcolony.so") +if os.path.exists(library_mac_path): + shutil.copytree(library_mac_path, temporary_path + "/npcolony.plugin") try: if os.name in ("nt", "os"): @@ -30,12 +42,17 @@ program_files_path = os.environ["PROGRAMFILES"] program_files_path = os.environ.get("PROGRAMFILES(X86)", program_files_path) chrome_path = "%s/Google/Chrome/Application/chrome.exe" % local_app_path - global_chrome_path = "%s/Google/Chrome/Application/chrome.exe" % program_files_path - if os.path.exists(global_chrome_path): chrome_path = global_chrome_path + global_chrome_path = ( + "%s/Google/Chrome/Application/chrome.exe" % program_files_path + ) + if os.path.exists(global_chrome_path): + chrome_path = global_chrome_path else: chrome_path = "chrome" - subprocess.call([chrome_path, "--pack-extension=%s" % temporary_path, "--no-message-box"]) + subprocess.call( + [chrome_path, "--pack-extension=%s" % temporary_path, "--no-message-box"] + ) try: shutil.copyfile(directory_path + "/npcolony.crx", target_path + "/npcolony.crx") finally: diff --git a/scripts/make_xpi.py b/scripts/make_xpi.py index 7d44432..47c95a9 100644 --- a/scripts/make_xpi.py +++ b/scripts/make_xpi.py @@ -8,8 +8,12 @@ not os.path.exists(target_path) and os.mkdir(target_path) directory_path = os.path.dirname(os.path.realpath(__file__)) -specification_path = os.path.normpath(os.path.join(directory_path, "../src/colony_npapi/descriptors/install.rdf")) -library_path = os.path.normpath(os.path.join(directory_path, "../" + base_path + "/npcolony.dll")) +specification_path = os.path.normpath( + os.path.join(directory_path, "../src/colony_npapi/descriptors/install.rdf") +) +library_path = os.path.normpath( + os.path.join(directory_path, "../" + base_path + "/npcolony.dll") +) zip_file = zipfile.ZipFile(target_path + "/npcolony.xpi", "w") try: diff --git a/setup.py b/setup.py index b762c1b..a4f6c61 100644 --- a/setup.py +++ b/setup.py @@ -29,91 +29,72 @@ """ The license for the module """ import os +import glob import setuptools -def rename_sources(sources, base = ".c", target = ".cpp"): + +def rename_sources(sources, base=".c", target=".cpp"): renamed = [] for source in sources: source_extension = os.path.splitext(source)[1] - if not source_extension == base: continue + if not source_extension == base: + continue source_name = os.path.splitext(source)[0] new_source_path = source_name + target os.rename(source, new_source_path) renamed.append(new_source_path) return renamed -def rollback_sources(sources, base = ".cpp", target = ".c"): - return rename_sources(sources, base = base, target = target) + +def rollback_sources(sources, base=".cpp", target=".c"): + return rename_sources(sources, base=base, target=target) + module = setuptools.Extension( "npcolony", - define_macros = [ - ("MAJOR_VERSION", "1"), - ('MINOR_VERSION', '0') - ], - include_dirs = [ - ".", - "src/colony_npapi/", - "/usr/local/include" - ], - libraries = [ - "user32", - "gdi32", - "winspool", - "comdlg32" - ] if os.name in ("nt",) else ["cups"], - library_dirs = ["/usr/local/lib"], - extra_compile_args = [ - "/DHAVE_LIBPYTHON", - "/DHAVE_LIBPYTHON_UNDEF" - ] if os.name in ("nt",) else [ - "-std=c99", - "-pedantic", - "-finline-functions", - "-Wall", - "-Wno-long-long", - "-Wno-variadic-macros", - "-Wno-strict-aliasing", - "-Wno-strict-prototypes", - "-DNO_CONFIG_H", - "-DCOLONY_PLATFORM_UNIX" - ], - sources = [ - "src/colony_npapi/stdafx.c", - "src/colony_npapi/encoding/base_64.c", - "src/colony_npapi/plugin/base.c", - "src/colony_npapi/plugin/python.c", - "src/colony_npapi/plugin/util.c", - "src/colony_npapi/print/print_unix.c", - "src/colony_npapi/print/print_win32.c", - "src/colony_npapi/system/gui_unix.c", - "src/colony_npapi/system/gui_win32.c" - ] + define_macros=[("MAJOR_VERSION", "1"), ("MINOR_VERSION", "0")], + include_dirs=[".", "src/colony_npapi/", "/usr/local/include"], + libraries=( + ["user32", "gdi32", "winspool", "comdlg32"] if os.name in ("nt",) else ["cups"] + ), + library_dirs=["/usr/local/lib"], + extra_compile_args=( + ["/DHAVE_LIBPYTHON", "/DHAVE_LIBPYTHON_UNDEF"] + if os.name in ("nt",) + else [ + "-std=c99", + "-pedantic", + "-finline-functions", + "-Wall", + "-Wno-long-long", + "-Wno-variadic-macros", + "-Wno-strict-aliasing", + "-Wno-strict-prototypes", + "-DNO_CONFIG_H", + "-DCOLONY_PLATFORM_UNIX", + ] + ), + sources=glob.glob("src/colony_npapi/**/*.c") + glob.glob("src/colony_npapi/**/*.h"), ) if os.name in ("nt",): module.sources = rename_sources(module.sources) try: setuptools.setup( - name = "npcolony", - version = "1.2.1", - author = "Hive Solutions Lda.", - author_email = "development@hive.pt", - description = "Colony Framework", - license = "Apache License, Version 2.0", - keywords = "colony npapi native", - url = "http://colony_npapi.hive.pt", - packages = [ - "npcolony_py", - "npcolony_py.test" - ], - test_suite = "npcolony_py.test", - package_dir = { - "" : os.path.normpath("src/python") - }, - zip_safe = False, - ext_modules = [module], - classifiers = [ + name="npcolony", + version="1.2.1", + author="Hive Solutions Lda.", + author_email="development@hive.pt", + description="Colony Framework", + license="Apache License, Version 2.0", + keywords="colony npapi native", + url="http://colony_npapi.hive.pt", + packages=["npcolony_py", "npcolony_py.test"], + test_suite="npcolony_py.test", + package_dir={"": os.path.normpath("src/python")}, + zip_safe=False, + ext_modules=[module], + classifiers=[ "Development Status :: 5 - Production/Stable", "Topic :: Utilities", "License :: OSI Approved :: Apache Software License", @@ -133,10 +114,14 @@ def rollback_sources(sources, base = ".cpp", target = ".c"): "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12" + "Programming Language :: Python :: 3.12", ], - long_description = open(os.path.join(os.path.dirname(__file__), "README.md"), "rb").read().decode("utf-8"), - long_description_content_type = "text/markdown" + long_description=open( + os.path.join(os.path.dirname(__file__), "README.md"), "rb" + ) + .read() + .decode("utf-8"), + long_description_content_type="text/markdown", ) finally: if os.name in ("nt",): diff --git a/src/python/npcolony_py/test/global.py b/src/python/npcolony_py/test/global.py index 31e3fbb..0ba7bed 100644 --- a/src/python/npcolony_py/test/global.py +++ b/src/python/npcolony_py/test/global.py @@ -5,6 +5,7 @@ import npcolony + class GlobalTest(unittest.TestCase): def test_basic(self):