Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

Commit 25a2df3

Browse files
committed
Switched to setuptools build system for cpp
Rather than using cppimport, use the simpler method of building a module with setuptools to be installed from disk with pip. This reduces startup time in some cases.
1 parent 6106c8b commit 25a2df3

11 files changed

+26
-17
lines changed

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ EU4img.zip
44
#Files created upon testing
55
__pycache__/
66
final.png
7-
*.pyd
8-
.rendered.*.cpp
97
venv/
108

9+
#Build
10+
/cpp/build/
11+
/cpp/*.egg-info/
12+
1113
#Shortcuts
1214
save games.lnk
1315
Screenshots.lnk

.vscode/c_cpp_properties.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
{
44
"name": "Win32",
55
"includePath": [
6-
"${workspaceFolder}/**",
7-
"C:/Users/2kai2/AppData/Local/Programs/Python/Python310/Include",
8-
"${workspaceFolder}/venv/lib/site-packages/pybind11/include"
6+
"${workspaceFolder}/**"
97
],
108
"defines": [
119
"_DEBUG",

EU4Bot.py

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import Any, Dict, List, Optional, Tuple, Union
77

88
import aiohttp
9-
import cppimport.import_hook
109
import EU4cpplib
1110
import discord
1211
from discord.errors import DiscordException

EU4Date.h cpp/EU4Date.h

File renamed without changes.

EU4cpplib.cpp cpp/EU4cpplib.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/*cppimport
2-
<%
3-
import pybind11
4-
import sysconfig
5-
setup_pybind11(cfg)
6-
cfg['include_dirs'] = [pybind11.get_include(), sysconfig.get_path("include")]
7-
%>
8-
*/
9-
101
#include <pybind11/operators.h>
112
#include <pybind11/pybind11.h>
123
#include <pybind11/stl.h>

cpp/pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel", "pybind11"]
3+
build-backend = "setuptools.build_meta"

cpp/setup.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from setuptools import setup
2+
from pybind11.setup_helpers import Pybind11Extension, build_ext
3+
4+
ext_modules = [
5+
Pybind11Extension(
6+
"EU4cpplib._cpplib",
7+
["EU4cpplib.cpp"]
8+
)
9+
]
10+
setup(cmdclass={"build_ext": build_ext}, ext_modules=ext_modules,
11+
name="EU4cpplib",
12+
packages=["EU4cpplib"],
13+
package_dir={"EU4cpplib": "wrapper"},
14+
package_data={"EU4cpplib": ["*.pyi", "py.typed"]},
15+
include_package_data=True
16+
)

cpp/wrapper/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from _cpplib import *
File renamed without changes.

cpp/wrapper/py.typed

Whitespace-only changes.

requirements.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
./cpp
12
aiohttp>=3.7.4
23
discord.py>=1.7.1
34
Pillow>=8.3.2
@@ -6,6 +7,4 @@ python-dateutil>=2.8.1
67
python-dotenv>=0.17.0
78
pyyaml>=6.0
89
requests>=2.25.1
9-
cppimport>=21.3.7
10-
pybind11>=2.6.2
1110
typing>=3.7.4.3

0 commit comments

Comments
 (0)