Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Python bindings #14

Open
wants to merge 21 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,33 @@ task:
build_script: env PATH="$HOME/.cargo/bin:$PATH" cargo build
test_script: env PATH="$HOME/.cargo/bin:$PATH" cargo test
before_cache_script: rm -rf $CARGO_HOME/registry/index

task:
freebsd_instance:
matrix:
image: freebsd-12-0-release-amd64
image: freebsd-11-2-release-amd64
matrix:
env:
PYTHON: python3.6
PYTHON_PKG: python36
PYPREFIX: py36
env:
PYTHON: python2.7
PYTHON_PKG: python27
PYPREFIX: py27
install_script: |
pkg install -y curl ${PYTHON_PKG} ${PYPREFIX}-pip
${PYTHON} -m pip install setuptools-rust pytest pytest-benchmark
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly
. $HOME/.cargo/env
build_script: |
export PYTHON_SYS_EXECUTABLE=$(which ${PYTHON})
. $HOME/.cargo/env
cd bindings/python
${PYTHON} setup.py install
test_script: |
export PYTHON_SYS_EXECUTABLE=$(which ${PYTHON})
. $HOME/.cargo/env
cd bindings/python
${PYTHON} setup.py test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
**/*.rs.bk

Cargo.lock

/bindings/*/target
104 changes: 104 additions & 0 deletions bindings/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
21 changes: 21 additions & 0 deletions bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "jail-python"
version = "0.0.5"
authors = ["Fabian Freyer <[email protected]>"]
description = "Python bindings to FreeBSD jail library"
license = "BSD-3-Clause"
repository = "https://github.com/fubarnetes/libjail-rs"

[lib]
name = "jail_python"
crate-type = ["cdylib"]

[dependencies]
rctl = "^0"

[dependencies.jail]
path = "../../"

[dependencies.pyo3]
version = "0.5"
features = ["extension-module"]
4 changes: 4 additions & 0 deletions bindings/python/jail/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from .jail import RunningJail, StoppedJail, Jls

__all__ = ['RunningJail', 'StoppedJail', 'Jls']
1 change: 1 addition & 0 deletions bindings/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
setuptools-rust
51 changes: 51 additions & 0 deletions bindings/python/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import sys

from setuptools import setup
from setuptools.command.test import test as TestCommand

try:
from setuptools_rust import RustExtension
except ImportError:
import subprocess
errno = subprocess.call([sys.executable, '-m', 'pip', 'install', 'setuptools-rust'])
if errno:
print("Please install setuptools-rust package")
raise SystemExit(errno)
else:
from setuptools_rust import RustExtension

class PyTest(TestCommand):
user_options = []

def run(self):
self.run_command("test_rust")

import subprocess
import sys
errno = subprocess.call(['pytest', '-v', 'tests'])
raise SystemExit(errno)

setup_requires = ['setuptools-rust>=0.10.1']
install_requires = []
tests_require = install_requires + ['pytest', 'pytest-benchmark']

setup(
name='jail',
version='0.0.5',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Programming Language :: Python',
'Programming Language :: Rust',
'Operating System :: POSIX :: BSD :: FreeBSD',
],
packages=['jail'],
rust_extensions=[RustExtension('jail.jail', 'Cargo.toml')],
install_requires=install_requires,
tests_require=tests_require,
setup_requires=setup_requires,
include_package_data=True,
zip_safe=False,
cmdclass=dict(test=PyTest)
)

Loading