Skip to content

Commit

Permalink
improved build system
Browse files Browse the repository at this point in the history
improve readme
don't support python 3.6 anymore
auto format
use avx instead of avx2
  • Loading branch information
Dobatymo committed Jul 19, 2024
1 parent dbb03c2 commit 4ef214c
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 130 deletions.
63 changes: 28 additions & 35 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,82 +3,75 @@ name: Python package
on:
push:
branches:
- '**'
- '**'
tags-ignore:
- '**'
- '**'
paths-ignore:
- '.pre-commit-config.yaml'
- .pre-commit-config.yaml
pull_request:
release:
types:
- published
- published

jobs:
test:
strategy:
matrix:
os: ["windows-latest", "ubuntu-20.04", "macos-latest"]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
os: [windows-latest, ubuntu-20.04, macos-13]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install -r requirements-build.txt
python -m pip install -r requirements-dev.txt
- name: Build
run: |
python setup.py build_ext --inplace
- name: Run tests
run: |
python -m unittest discover -v tests "*.py"
python -m pip install .[test]
cd tests && python -m unittest
build-wheels:
if: github.event_name == 'release' && github.event.action == 'published'
needs: test

strategy:
matrix:
os: ["ubuntu-20.04", "macos-latest", "windows-latest"]
os: [ubuntu-20.04, macos-13, windows-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install -U pip setuptools wheel cibuildwheel
python -m pip install cibuildwheel==2.11.2
- name: Build
run: |
python -m cibuildwheel
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
path: wheelhouse/*.whl

build-sdist:
if: github.event_name == 'release' && github.event.action == 'published'
needs: test

runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install -U pip setuptools Cython==3.0.0a11
python -m pip install build
- name: Build dists
run: |
python setup.py sdist
- uses: actions/upload-artifact@v2
python -m build --sdist
- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz

Expand All @@ -89,12 +82,12 @@ jobs:
runs-on: ubuntu-20.04

steps:
- uses: actions/download-artifact@v2
with:
name: artifact
path: dist
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist

- uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_password }}
- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.pypi_password }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ dist/

# cython
cython_debug/
*.cpp
75 changes: 63 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,64 @@
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-json
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=no]
- id: requirements-txt-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.14.0
hooks:
- id: pretty-format-yaml
args: [--autofix]
- repo: https://github.com/tox-dev/pyproject-fmt
rev: 2.1.4
hooks:
- id: pyproject-fmt
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.8
hooks:
- id: clang-format
- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.16.2
hooks:
- id: cython-lint
- id: double-quote-cython-strings
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 7.1.0
hooks:
- id: flake8
additional_dependencies:
- flake8-annotations
- flake8-bugbear
- flake8-eradicate
- flake8-mutable
- flake8-simplify
- repo: https://github.com/Yelp/detect-secrets
rev: v1.5.0
hooks:
- id: detect-secrets
53 changes: 51 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,59 @@
# cpp-containers-python

Python wrapper for the C++ Standard Library containers. The behaviour of the containers might not be as expected, since for sorting and hashing the items only the pointer to the Python object is used, and not the actual content. That means items in ordered collections will be ordered according to memory layout and to object content. Furhermore, equality checks will work as pairwise `is` tests, because only the pointers are compared internally. Also certain operations will lead to *undefined behavior*, such as accessing out of bounds indices in `Vector`.
Python wrapper for the C++ Standard Library containers. The behavior of the containers might not be as expected, since for sorting and hashing the items, only the pointer to the Python object is used, and not the actual content. That means items in ordered collections will be ordered according to memory layout and not object content. Furthermore, equality checks will work as pairwise `is` tests, because only the pointers are compared internally. Also certain operations will lead to *undefined behavior*, such as accessing out of bounds indices in `Vector`.

This design decision was made for performance reasons and to keep the code as simple and close to C++ as possible. Real equality checks can still be implemented by pairwise comparison of the objects at Python level. This won't be any faster than doing so on normal Python collections.

For more documentation about the C++ containers see <https://en.cppreference.com/w/cpp/container>.

## Requirements
Python 3.7+.

## Install
`pip install cpp-containers` (not working yet)
`pip install cpp-containers`

## Examples
```
from cppcontainers import MultiSet
s = MultiSet()
s.insert(1)
s.insert(2)
s.insert(2)
assert list(s) == [1, 2, 2]
assert s.size() == 3
assert s.count(2) == 2
assert s.begin().deref() == 1
```

The containers store references to Python objects, not copies.

```
from cppcontainers import Vector
from sys import getrefcount
v = Vector()
a = "asd"
b = [1, 2, 3]
v.push_back(a)
v.push_back(b)
assert id(a) == id(v[0])
assert list(v) == [a, b]
b.append(4)
assert b[-1] == v[1][-1]
assert getrefcount(a) == 3
del v
assert getrefcount(a) == 2
```

The following crashes, just like in C++.

```
from cppcontainers import Vector
Vector()[0]
```

And this throws an exception like in C++.

```
from cppcontainers import Vector
Vector().at(0)
```
Loading

0 comments on commit 4ef214c

Please sign in to comment.