Skip to content

Commit

Permalink
feat(no-release): bind initial apis (#1)
Browse files Browse the repository at this point in the history
* binding initial apis
* Ignore pyi from pylint
* Ignore tests from *-macosx_arm64
* Optimize lib7zip configuration
* Disable armv7l
* Link to bit7z
* Add api comments

---------

Signed-off-by: msclock <[email protected]>
Signed-off-by: l.feng <[email protected]>
  • Loading branch information
msclock authored Dec 29, 2024
1 parent eddde87 commit 35af881
Show file tree
Hide file tree
Showing 14 changed files with 4,312 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reuseable_cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-24.04] # renovate: github-runner
arch: [aarch64, ppc64le, s390x, armv7l, x86_64, i686]
arch: [aarch64, ppc64le, s390x, x86_64, i686]
build: [manylinux, musllinux]
qemu_arch: [aarch64 ppc64le s390x armv7l]
include:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ repos:
hooks:
- id: codespell
args:
- -L=lang
- -L=lang,TE,Characts
- --check-filenames
- --write-changes

Expand Down
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
"numbers": "cpp",
"semaphore": "cpp",
"codecvt": "cpp",
"source_location": "cpp"
"source_location": "cpp",
"complex": "cpp",
"csignal": "cpp",
"regex": "cpp",
"typeindex": "cpp",
"valarray": "cpp"
}
}
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ write_to = "src/pybit7z/_version.py"
build-verbosity = 1
test-command = "pytest {project}/tests"
test-extras = ["test"]
test-skip = ["*-win_arm64", "*-macosx_universal2:arm64"]
test-skip = ["*-win_arm64", "*-macosx_arm64"]

[tool.cibuildwheel.linux]
before-build = [
Expand Down Expand Up @@ -148,6 +148,8 @@ extend-select = [
"PD", # pandas-vet
]
ignore = [
"UP006", # pyupgrade removes f-strings
"UP007", # pyupgrade removes dict comprehensions
"PLR09", # Too many <...>
"PLR2004", # Magic value used in comparison
"ISC001", # Conflicts with formatter
Expand All @@ -162,7 +164,7 @@ isort.required-imports = ["from __future__ import annotations"]

[tool.pylint]
py-version = "3.8"
ignore-paths = [".*/_version.py"]
ignore-paths = [".*/_version.py", ".*/*.pyi"]
extension-pkg-allow-list = ["pybit7z._core"]
reports.output-format = "colorized"
similarities.ignore-imports = "yes"
Expand Down
5 changes: 2 additions & 3 deletions src/_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ target_include_interface_directories(
${target_name_internal} ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/git_version)

if(VCPKG_TARGET_ARCHITECTURE MATCHES [[64]])
if(NOT VCPKG_TARGET_ARCHITECTURE MATCHES [[86]])
set(bit7z_suffix 64)
endif()

Expand All @@ -39,8 +39,7 @@ target_link_libraries(${target_name_internal}
# parts that need to be verified and tested in the target target_name_internal
set(target_name _core)

pybind11_add_module(${target_name} MODULE ${internal_srcs} ${internal_hdrs}
src/pybind.cpp)
pybind11_add_module(${target_name} MODULE src/pybind.cpp)
warn_target(${target_name})
harden_target(${target_name})
sanitize_target(${target_name})
Expand Down
1 change: 0 additions & 1 deletion src/_core/include/_core.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once

#include "_version.hpp"
#include "pybit7z.hpp"
24 changes: 15 additions & 9 deletions src/_core/include/pybit7z.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
#include <bit7z/bit7z.hpp>

namespace _core {
#ifdef WIN32
#if defined(_MSC_VER)
constexpr auto default_lib7zip = "7zip.dll";
#else
constexpr auto default_lib7zip = "lib7zip.dll";
#endif
#else
constexpr auto default_lib7zip = "lib7zip.so";
#endif

std::string& default_library_path();

class Bit7zipSingleton {
public:
static const bit7z::Bit7zLibrary& getInstance();

private:
Bit7zipSingleton() = default;
~Bit7zipSingleton() = default;

Bit7zipSingleton(const Bit7zipSingleton&) = delete;
Bit7zipSingleton& operator=(const Bit7zipSingleton&) = delete;
};

} // namespace _core
1,637 changes: 1,633 additions & 4 deletions src/_core/src/pybind.cpp

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions src/_core/src/pybit7z.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
#include "pybit7z.hpp"

namespace _core {

std::string& default_library_path() {
#ifdef WIN32
#if defined(_MSC_VER)
constexpr auto default_lib7zip = "7zip.dll";
#else
constexpr auto default_lib7zip = "lib7zip.dll";
#endif
#elif __APPLE__
constexpr auto default_lib7zip = "lib7zip.dylib";
#else
constexpr auto default_lib7zip = "lib7zip.so";
#endif
static std::string default_path(default_lib7zip);
return default_path;
}

const bit7z::Bit7zLibrary& Bit7zipSingleton::getInstance() {
static const bit7z::Bit7zLibrary instance(default_library_path());
return instance;
}

} // namespace _core
28 changes: 23 additions & 5 deletions src/_core/tests/test_core.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "gtest/gtest.h"

#include "_core.hpp"
#include "pybit7z.hpp"
#include "utils.hpp"

TEST(_core, version) {
Expand All @@ -13,8 +14,7 @@ using _core_pybit7z_test = test::utils::rc_dir_test;
TEST_F(_core_pybit7z_test, compress) {
using namespace bit7z;

Bit7zLibrary lib{_core::default_lib7zip};
BitFileCompressor compressor{lib, BitFormat::Zip};
BitFileCompressor compressor{_core::Bit7zipSingleton::getInstance(), BitFormat::Zip};

std::vector<std::string> files = {this->tests_dir.string() + "/test_core.cpp"};

Expand All @@ -40,15 +40,14 @@ TEST_F(_core_pybit7z_test, compress) {

// Compressing a single file into a buffer
std::vector<bit7z::byte_t> buffer;
BitFileCompressor compressor2{lib, BitFormat::BZip2};
BitFileCompressor compressor2{_core::Bit7zipSingleton::getInstance(), BitFormat::BZip2};
compressor2.compressFile(files[0], buffer);
}

TEST_F(_core_pybit7z_test, archive_writer) {
using namespace bit7z;

Bit7zLibrary lib{_core::default_lib7zip};
BitArchiveWriter archive{lib, BitFormat::SevenZip};
BitArchiveWriter archive{_core::Bit7zipSingleton::getInstance(), BitFormat::SevenZip};

// Adding the items to be compressed (no compression is performed here)
archive.addFile(this->tests_dir.string() + "/test_core.cpp");
Expand All @@ -58,3 +57,22 @@ TEST_F(_core_pybit7z_test, archive_writer) {
// Compressing the added items to the output archive
archive.compressTo(this->system_test_tmp_dir_.string() + "/output.7z");
}

TEST_F(_core_pybit7z_test, bzip) {
using namespace bit7z;

BitFileCompressor compressor{_core::Bit7zipSingleton::getInstance(), BitFormat::BZip2};
BitFileExtractor extractor{_core::Bit7zipSingleton::getInstance(), BitFormat::BZip2};

auto file = this->tests_dir / "test_core.cpp";
std::vector<std::string> files = {file.string()};

auto archive_file_name = file.filename().string() + ".bz2";
// Bzip requires output file to have the same name as the file entry
compressor.compress(files, this->system_test_tmp_dir_.string() + "/" + archive_file_name);

extractor.extract(this->system_test_tmp_dir_.string() + "/" + archive_file_name,
this->system_test_tmp_dir_.string() + "/" + archive_file_name + ".extracted");
EXPECT_TRUE(std::filesystem::exists(this->system_test_tmp_dir_.string() + "/" + archive_file_name + ".extracted"
+ "/" + file.filename().string()));
}
14 changes: 14 additions & 0 deletions src/pybit7z/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@

from __future__ import annotations

from pathlib import Path

from importlib_metadata import distribution

from pybit7z import _core

from ._version import version as __version__

__all__ = ["__version__"]

if not Path(_core.set_lib7zip_path()).exists():
lib7zip_path = (
distribution(__package__).locate_file(__package__) / _core.set_lib7zip_path()
)
if lib7zip_path.exists():
_core.set_lib7zip_path(str(lib7zip_path))
_core.set_large_page_mode()
Loading

0 comments on commit 35af881

Please sign in to comment.