Skip to content

Commit

Permalink
add: copy flags to reduce bundle size, bump macos 10.15, remove: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cathaypacific8747 committed Jul 17, 2023
1 parent 558e98f commit 52eab31
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 13 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ jobs:
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }}
CIBW_MANYLINUX_X86_64_IMAGE: "quay.io/pypa/manylinux_2_28_x86_64"
CIBW_ARCHS: all
MACOSX_DEPLOYMENT_TARGET: 10.14
CIBW_TEST_SKIP: "*"
MACOSX_DEPLOYMENT_TARGET: 10.15
run: pipx run cibuildwheel --output-dir wheelhouse

- name: Store artifacts
Expand All @@ -91,8 +92,6 @@ jobs:
upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Build and install am4utils
run: pip3 install --verbose "src/am4utils/.[dev]"
run: pip3 install --verbose "src/am4utils/.[dev]" --config-settings=cmake.define.COPY_DATA=1

- name: Test everything
run: pytest
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"cmake.buildArgs": [],
"files.associations": {
"*.spec": "python",
},
"cmake.sourceDirectory": "${workspaceFolder}/src/am4utils",
"cmake.buildDirectory": "${workspaceFolder}/src/am4utils/build-vscode",
"cmake.configureArgs": [
"-DCOPY_DATA=1"
],
"C_Cpp.autoAddFileAssociations": false
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{
"label": "py: install",
"type": "shell",
"command": "${command:python.interpreterPath} -m pip install --verbose \"src/am4utils/.[dev]\""
"command": "${command:python.interpreterPath} -m pip install --verbose \"src/am4utils/.[dev]\" --config-settings=cmake.define.COPY_DATA=1"
},
{
"label": "py: reinstall",
Expand Down
9 changes: 7 additions & 2 deletions src/am4utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ if (NOT DEFINED BUILD_PYBIND)
set(BUILD_PYBIND 1)
endif()

if (NOT DEFINED COPY_DATA)
set(COPY_DATA 0)
endif()

project(am4utils LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
include(libduckdb.cmake)
Expand Down Expand Up @@ -53,10 +57,11 @@ target_link_libraries(_core PRIVATE duckdb)

install(TARGETS _core DESTINATION .)
install(FILES $<TARGET_FILE:duckdb> DESTINATION .)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/data DESTINATION .)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/stubs/ DESTINATION . OPTIONAL) # / is important!
install(DIRECTORY ${CMAKE_SOURCE_DIR}/py/ DESTINATION .)

if (COPY_DATA)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/data DESTINATION .)
endif()

# debug executable
add_executable(_core_executable
Expand Down
24 changes: 20 additions & 4 deletions src/am4utils/cpp/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <duckdb.hpp>
#include <algorithm>
#include <queue>
#include <optional>

#include "include/db.hpp"
#include "include/ext/jaro.hpp"
Expand Down Expand Up @@ -480,19 +479,36 @@ void _debug_query(string query) {

#if BUILD_PYBIND == 1
#include "include/binder.hpp"
#include <optional>
#include <filesystem>

void pybind_init_db(py::module_& m) {
py::module_ m_db = m.def_submodule("db");

m_db
.def("init", [](std::optional<string> home_dir) {
py::gil_scoped_acquire acquire;
if (!home_dir.has_value()) {
py::gil_scoped_acquire acquire;
init(py::module::import("am4utils").attr("__path__").cast<py::list>()[0].cast<string>()); // am4utils.__path__[0]
py::gil_scoped_release release;
string hdir = py::module::import("am4utils").attr("__path__").cast<py::list>()[0].cast<string>(); // am4utils.__path__[0]
py::function urlretrieve = py::module::import("urllib.request").attr("urlretrieve");
if (!std::filesystem::exists(hdir + "/data")) {
std::cout << "WARN: data directory not found, creating..." << std::endl;
std::filesystem::create_directory(hdir + "/data");
}
for (const std::string fn : {"airports.parquet", "aircrafts.parquet", "routes.parquet"}) {
if (!std::filesystem::exists(hdir + "/data/" + fn)) {
std::cout << "WARN: " << fn << " not found, downloading from GitHub..." << std::endl;
urlretrieve(
"https://github.com/cathaypacific8747/am4bot/releases/latest/download/" + fn,
hdir + "/data/" + fn
);
}
}
init(hdir);
} else {
init(home_dir.value());
}
py::gil_scoped_release release;
}, "home_dir"_a = py::none())
.def("_debug_query", &_debug_query, "query"_a);

Expand Down
2 changes: 1 addition & 1 deletion src/am4utils/stubs/_core/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ __all__ = [
]


__version__ = '0.1.4'
__version__ = '0.1.6'

0 comments on commit 52eab31

Please sign in to comment.