Skip to content

Commit

Permalink
chore: improved inclusion of header and source files
Browse files Browse the repository at this point in the history
Should make it possible to handle missing header files.
  • Loading branch information
joamag committed May 29, 2024
1 parent 75165b7 commit da6e2c9
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 80 deletions.
37 changes: 27 additions & 10 deletions scripts/make_crx.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,47 @@
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"):
local_app_path = os.environ["LOCALAPPDATA"]
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:
Expand Down
8 changes: 6 additions & 2 deletions scripts/make_xpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
121 changes: 53 additions & 68 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]",
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="[email protected]",
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",
Expand All @@ -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",):
Expand Down
1 change: 1 addition & 0 deletions src/python/npcolony_py/test/global.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import npcolony


class GlobalTest(unittest.TestCase):

def test_basic(self):
Expand Down

0 comments on commit da6e2c9

Please sign in to comment.