summaryrefslogtreecommitdiff
path: root/wrappers/python
diff options
context:
space:
mode:
Diffstat (limited to 'wrappers/python')
-rw-r--r--wrappers/python/Makefile26
-rw-r--r--wrappers/python/README.md27
-rw-r--r--wrappers/python/eduvpn_common/loader.py21
-rw-r--r--wrappers/python/pyproject.toml39
-rwxr-xr-xwrappers/python/setup.py124
5 files changed, 51 insertions, 186 deletions
diff --git a/wrappers/python/Makefile b/wrappers/python/Makefile
index d5e9071..9d51c15 100644
--- a/wrappers/python/Makefile
+++ b/wrappers/python/Makefile
@@ -1,24 +1,18 @@
-.PHONY: pack test clean
+.DEFAULT_GOAL := pack
+.PHONY: install-lib pack test clean
-EXPORTS_PATH ?= ../../exports
-include $(EXPORTS_PATH)/common.mk
+VERSION := $(shell grep -o 'const Version = "[^"]*' ../../internal/version/version.go | cut -d '"' -f 2)
-ifdef PLAT_NAME
-override SETUP_ARGS += --plat-name=$(PLAT_NAME)
-endif
+install-lib:
+ rm -rf eduvpn_common/lib/*
+ install "../../lib/libeduvpn_common-${VERSION}.so" -Dt "eduvpn_common/lib"
# Build for current platform only
-pack:
- mkdir -p ./eduvpn_common/lib
- ./setup.py bdist_wheel $(SETUP_ARGS) --exports-lib-path="$(EXPORTS_LIB_PATH)"
+pack: install-lib
+ python3 -m build --sdist --wheel .
-test: .try-build-lib
- install "$(EXPORTS_LIB_SUBFOLDER_PATH)/$(LIB_FILE)" -Dt "eduvpn_common/lib"
+test: install-lib
python3 -m unittest tests
- rm eduvpn_common/lib/*
clean:
- rm -rf build/ dist/ *.egg-info/ lib/*
-ifeq ($(CLEAN_ALL),1)
- rm -rf venv/
-endif
+ rm -rf build/ dist/ *.egg-info/ eduvpn_common/lib/* venv
diff --git a/wrappers/python/README.md b/wrappers/python/README.md
index 6f0bec1..905d7d4 100644
--- a/wrappers/python/README.md
+++ b/wrappers/python/README.md
@@ -2,42 +2,25 @@
## Requirements
-Python 3.6+ is assumed, but it may work with older versions. To build, `setuptools` and `wheel` are required.
+Python 3.6+ is assumed, but it may work with older versions. To build, `setuptools`, `wheel` and `build` are required.
-## Build & test
+## Building
-First build the shared Go library. Next:
+First build the shared Go library by following the instructions in the root directory of this Repo.
-Build wheel using library for current platform:
+Then, to build the wheel use:
```shell
make pack
```
-(This does not build the shared Go library.)
-
-Build wheel using library for specified platform (passed to setuptools `--plat-name`,
-see [`get_build_platform`](https://setuptools.pypa.io/en/latest/pkg_resources.html?highlight=get_build_platform#platform-utilities)
-for more):
-
-```shell
-make pack PLAT_NAME=win32
-```
-
To install the wheel, run:
```shell
pip install dist/eduvpncommon-[version]-py3-none-[platform].whl
```
-You could also reference the discovery module directly and copy the library for the platform to the `eduvpncommon/lib/`
-folder.
-
-If you do not build this as part of the full repository, specify `EXPORTS_PATH="path/to/exports-folder"` when calling
-make. This folder must contain `common.mk` and the `lib/` folder with built libraries.
-
-Test:
-
+## Running tests
```shell
make test
```
diff --git a/wrappers/python/eduvpn_common/loader.py b/wrappers/python/eduvpn_common/loader.py
index f1e27e1..ca0fd20 100644
--- a/wrappers/python/eduvpn_common/loader.py
+++ b/wrappers/python/eduvpn_common/loader.py
@@ -1,5 +1,4 @@
import pathlib
-import platform
from collections import defaultdict
from ctypes import CDLL, c_char_p, c_int, c_void_p, cdll
@@ -24,25 +23,7 @@ def load_lib() -> CDLL:
:return: The Go shared library loaded with cdll.LoadLibrary from ctypes
:rtype: CDLL
"""
- lib_prefixes = defaultdict(
- lambda: "lib",
- {
- "windows": "",
- },
- )
-
- lib_suffixes = defaultdict(
- lambda: ".so",
- {
- "windows": ".dll",
- "darwin": ".dylib",
- },
- )
-
- os = platform.system().lower()
-
- libname = "eduvpn_common"
- libfile = f"{lib_prefixes[os]}{libname}-{__version__}{lib_suffixes[os]}"
+ libfile = f"libeduvpn_common-{__version__}.so"
lib = None
diff --git a/wrappers/python/pyproject.toml b/wrappers/python/pyproject.toml
index 44836bb..b43aa5a 100644
--- a/wrappers/python/pyproject.toml
+++ b/wrappers/python/pyproject.toml
@@ -1,6 +1,37 @@
[build-system]
-requires = [
- "setuptools",
- "wheel",
-]
+requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
+
+[project]
+name = "eduvpn_common"
+version = "1.99.1"
+description = "eduvpn-common library"
+authors = [
+ {name = "Jeroen Wijenbergh", email = "jeroen.wijenbergh@geant.org"},
+]
+requires-python = ">=3.6"
+readme = "README.md"
+license = {text = "MIT"}
+
+[project.urls]
+Homepage = "https://github.com/eduvpn/eduvpn-common"
+
+[project.optional-dependencies]
+lint = ["ruff" ]
+mypy = [ "mypy" ]
+
+[tool.setuptools.packages.find]
+include = ["eduvpn_common*"]
+
+[tool.ruff]
+line-length = 120
+
+[tool.ruff.lint]
+extend-select = [
+ # isort
+ "I",
+]
+ignore = ['E402']
+
+[tool.ruff.lint.isort]
+case-sensitive = true
diff --git a/wrappers/python/setup.py b/wrappers/python/setup.py
deleted file mode 100755
index 37ff577..0000000
--- a/wrappers/python/setup.py
+++ /dev/null
@@ -1,124 +0,0 @@
-#!/usr/bin/env python3
-
-import os
-import shutil
-import sys
-import typing
-from collections import defaultdict
-
-from setuptools import setup
-from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
-
-_libname = "eduvpn_common"
-__version__ = "1.99.1"
-
-
-def getlibpath(plat_name: str) -> typing.Union[str, None]:
- """Get library path for plat_name relative to exports/lib/ folder."""
-
- plat_map = defaultdict(
- lambda: plat_name,
- {
- "win32": "win-x86",
- },
- )
-
- plat_split = plat_map[plat_name].split("-", 1)
- if len(plat_split) != 2:
- return None
- plat_os, plat_arch = plat_split
-
- os_map = defaultdict(
- lambda: plat_os,
- {
- "win": "windows",
- },
- )
- lib_prefixes = defaultdict(
- lambda: "lib",
- {
- "windows": "",
- },
- )
- lib_suffixes = defaultdict(
- lambda: ".so",
- {
- "windows": ".dll",
- "darwin": ".dylib",
- },
- )
- arch_map = defaultdict(
- lambda: plat_arch,
- {
- "aarch64_be": "arm64",
- "aarch64": "arm64",
- "armv8b": "arm64",
- "armv8l": "arm64",
- "x86": "386",
- "x86pc": "386",
- "i86pc": "386",
- "i386": "386",
- "i686": "386",
- "x86_64": "amd64",
- "i686-64": "amd64",
- },
- )
-
- processed_os = os_map[plat_os]
- return (
- processed_os
- + "/"
- + arch_map[plat_arch]
- + "/"
- + lib_prefixes[processed_os]
- + _libname
- + "-"
- + __version__
- + lib_suffixes[processed_os]
- )
-
-
-# Adapted from https://stackoverflow.com/a/51794740
-# You would say there would be a better way to do all of this, but I couldn't find it
-
-
-class bdist_wheel(_bdist_wheel):
- user_options = _bdist_wheel.user_options + [
- ("exports-lib-path=", None, "path to exports/lib directory"),
- ]
-
- def initialize_options(self):
- super().initialize_options()
- self.exports_lib_path = "../../exports/lib" # default
-
- def run(self):
- self.plat_name_supplied = True # Force use platform
-
- libpath = getlibpath(self.plat_name)
- if not libpath:
- print("Unknown platform:", self.plat_name)
- sys.exit(1)
-
- print("Building wheel for platform:", self.plat_name)
-
- # setuptools will only use paths inside the package for package_data, so we copy the library
- p = "eduvpn_common/lib"
- if os.path.isdir(p):
- shutil.rmtree(p)
- os.makedirs(p)
- shutil.copyfile(
- self.exports_lib_path + "/" + libpath, p + "/" + libpath.split("/")[-1]
- )
- _bdist_wheel.run(self)
- shutil.rmtree(p)
-
-
-setup(
- name="eduvpn_common",
- version=__version__,
- packages=["eduvpn_common"],
- python_requires=">=3.6",
- package_dir={"eduvpn_common": "eduvpn_common"},
- package_data={"eduvpn_common": ["lib/*" + _libname + "*", "py.typed"]},
- cmdclass={"bdist_wheel": bdist_wheel},
-)