From 3250571844cab074babf4532fcfb6b9876a21f66 Mon Sep 17 00:00:00 2001
From: Nico Alt <nicoalt@posteo.org>
Date: Thu, 19 Dec 2019 10:34:54 +0100
Subject: [PATCH] Set up flit for briar-wrapper

Closes
https://code.briarproject.org/briar/python-briar-wrapper/issues/2.
---
 .gitignore                                    |  1 +
 README.md                                     | 12 ++++++++
 meson.build => briar_wrapper/__init__.py      |  8 ++---
 {src/briar/api => briar_wrapper}/api.py       |  4 +--
 {src/briar/api => briar_wrapper}/constants.py |  0
 {src/briar/api => briar_wrapper}/model.py     |  0
 .../api => briar_wrapper}/models/contacts.py  |  4 +--
 .../models/private_chat.py                    |  4 +--
 .../models/socket_listener.py                 |  4 +--
 pyproject.toml                                | 29 +++++++++++++++++++
 src/meson.build                               | 15 ----------
 .../models/test_contacts.py                   |  2 +-
 .../models/test_private_chat.py               |  2 +-
 .../api => briar_wrapper}/test_constants.py   |  4 +--
 tools/tests/test-pycodestyle.sh               |  2 +-
 tools/tests/test-pylint.sh                    |  2 +-
 tools/tests/test-pytest.sh                    |  2 +-
 17 files changed, 59 insertions(+), 36 deletions(-)
 rename meson.build => briar_wrapper/__init__.py (52%)
 rename {src/briar/api => briar_wrapper}/api.py (95%)
 rename {src/briar/api => briar_wrapper}/constants.py (100%)
 rename {src/briar/api => briar_wrapper}/model.py (100%)
 rename {src/briar/api => briar_wrapper}/models/contacts.py (93%)
 rename {src/briar/api => briar_wrapper}/models/private_chat.py (93%)
 rename {src/briar/api => briar_wrapper}/models/socket_listener.py (94%)
 create mode 100644 pyproject.toml
 delete mode 100644 src/meson.build
 rename tests/{briar/api => briar_wrapper}/models/test_contacts.py (96%)
 rename tests/{briar/api => briar_wrapper}/models/test_private_chat.py (95%)
 rename tests/{briar/api => briar_wrapper}/test_constants.py (82%)

diff --git a/.gitignore b/.gitignore
index 7a7e68f..9163101 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 .coverage
 __pycache__
+dist
diff --git a/README.md b/README.md
index 215076d..7f1f4ad 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,18 @@ It uses the
 [Briar REST API](https://code.briarproject.org/briar/briar/blob/master/briar-headless/README.md)
 and therefore requires Java.
 
+## Installation
+
+The easiest way to install Briar Wrapper is to
+install [the package from PyPi.org](https://pypi.org/project/briar_wrapper/):
+`pip install briar_wrapper`
+
+You can also build it yourself by runninng the following command:
+`flit build`
+
+Note that you need to [have installed flit](https://pypi.org/project/flit/) to
+do this.
+
 ## Design Goals
 
 * Main platform is GNU/Linux, but should also support (at least) Windows and macOS
diff --git a/meson.build b/briar_wrapper/__init__.py
similarity index 52%
rename from meson.build
rename to briar_wrapper/__init__.py
index e8f8a28..2a7c41c 100644
--- a/meson.build
+++ b/briar_wrapper/__init__.py
@@ -2,10 +2,6 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 # License-Filename: LICENSE.md
 
-project(
-  'briar-wrapper',
-  version: '0.1.0',
-  meson_version: '>= 0.50.0',
-)
+"""Wrapper for the Briar REST API"""
 
-subdir('src')
+__version__ = "0.0.2"
diff --git a/src/briar/api/api.py b/briar_wrapper/api.py
similarity index 95%
rename from src/briar/api/api.py
rename to briar_wrapper/api.py
index cf83576..cfc04d2 100644
--- a/src/briar/api/api.py
+++ b/briar_wrapper/api.py
@@ -9,8 +9,8 @@ from time import sleep
 from urllib.error import HTTPError, URLError
 from urllib.request import urlopen
 
-from briar.api.constants import BASE_HTTP_URL, BRIAR_AUTH_TOKEN, BRIAR_DB
-from briar.api.models.socket_listener import SocketListener
+from briar_wrapper.constants import BASE_HTTP_URL, BRIAR_AUTH_TOKEN, BRIAR_DB
+from briar_wrapper.models.socket_listener import SocketListener
 
 
 class Api:
diff --git a/src/briar/api/constants.py b/briar_wrapper/constants.py
similarity index 100%
rename from src/briar/api/constants.py
rename to briar_wrapper/constants.py
diff --git a/src/briar/api/model.py b/briar_wrapper/model.py
similarity index 100%
rename from src/briar/api/model.py
rename to briar_wrapper/model.py
diff --git a/src/briar/api/models/contacts.py b/briar_wrapper/models/contacts.py
similarity index 93%
rename from src/briar/api/models/contacts.py
rename to briar_wrapper/models/contacts.py
index 6d4f6cf..a146885 100644
--- a/src/briar/api/models/contacts.py
+++ b/briar_wrapper/models/contacts.py
@@ -7,8 +7,8 @@ from urllib.parse import urljoin
 from requests import get as _get
 from requests import post as _post
 
-from briar.api.constants import BASE_HTTP_URL
-from briar.api.model import Model
+from briar_wrapper.constants import BASE_HTTP_URL
+from briar_wrapper.model import Model
 
 
 class Contacts(Model):
diff --git a/src/briar/api/models/private_chat.py b/briar_wrapper/models/private_chat.py
similarity index 93%
rename from src/briar/api/models/private_chat.py
rename to briar_wrapper/models/private_chat.py
index 09e42af..1b5e4df 100644
--- a/src/briar/api/models/private_chat.py
+++ b/briar_wrapper/models/private_chat.py
@@ -7,8 +7,8 @@ from urllib.parse import urljoin
 from requests import get as _get
 from requests import post as _post
 
-from briar.api.constants import BASE_HTTP_URL
-from briar.api.model import Model
+from briar_wrapper.constants import BASE_HTTP_URL
+from briar_wrapper.model import Model
 
 
 class PrivateChat(Model):
diff --git a/src/briar/api/models/socket_listener.py b/briar_wrapper/models/socket_listener.py
similarity index 94%
rename from src/briar/api/models/socket_listener.py
rename to briar_wrapper/models/socket_listener.py
index c5b39ee..84e2408 100644
--- a/src/briar/api/models/socket_listener.py
+++ b/briar_wrapper/models/socket_listener.py
@@ -8,8 +8,8 @@ from threading import Thread
 
 import websockets
 
-from briar.api.constants import WEBSOCKET_URL
-from briar.api.model import Model
+from briar_wrapper.constants import WEBSOCKET_URL
+from briar_wrapper.model import Model
 
 
 class SocketListener(Model):  # pylint: disable=too-few-public-methods
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..c9f60b0
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,29 @@
+[build-system]
+requires = ["flit"]
+build-backend = "flit.buildapi"
+
+[tool.flit.metadata]
+module = "briar_wrapper"
+author = "Briar Community"
+author-email = "contact@briarproject.org"
+home-page = "https://code.briarproject.org/briar/python-briar-wrapper"
+requires = [
+	"requests2>=2.16.0",
+	"websockets>=8.0.2",
+]
+requires-python=">=3"
+description-file="README.md"
+classifiers = [
+	"Development Status :: 3 - Alpha",
+	"Intended Audience :: Developers",
+	"License :: OSI Approved :: GNU Affero General Public License v3",
+	"Natural Language :: English",
+	"Operating System :: OS Independent",
+	"Programming Language :: Java",
+	"Programming Language :: Python :: 3",
+	"Topic :: Communications :: Chat",
+]
+
+[tool.flit.metadata.urls]
+"Bug Tracker" = "https://code.briarproject.org/briar/python-briar-wrapper/issues/"
+"Briar REST API" = "https://code.briarproject.org/briar/briar/blob/master/briar-headless/README.md"
diff --git a/src/meson.build b/src/meson.build
deleted file mode 100644
index a85b92f..0000000
--- a/src/meson.build
+++ /dev/null
@@ -1,15 +0,0 @@
-# Copyright (c) 2019 Nico Alt
-# SPDX-License-Identifier: AGPL-3.0-only
-# License-Filename: LICENSE.md
-
-PACKAGE_DATA_DIR = join_paths(get_option('prefix'), get_option('datadir'), meson.project_name())
-MODULE_DIR = join_paths(PACKAGE_DATA_DIR, 'briar')
-
-python3 = import('python3')
-
-conf = configuration_data()
-conf.set('PYTHON', python3.find_python().path())
-conf.set('VERSION', meson.project_version())
-conf.set('PACKAGE_DATA_DIR', PACKAGE_DATA_DIR)
-
-install_subdir('briar/api', install_dir: MODULE_DIR)
diff --git a/tests/briar/api/models/test_contacts.py b/tests/briar_wrapper/models/test_contacts.py
similarity index 96%
rename from tests/briar/api/models/test_contacts.py
rename to tests/briar_wrapper/models/test_contacts.py
index 988a632..f20ed4a 100644
--- a/tests/briar/api/models/test_contacts.py
+++ b/tests/briar_wrapper/models/test_contacts.py
@@ -6,7 +6,7 @@ import json
 
 import requests_mock
 
-from briar.api.models.contacts import Contacts
+from briar_wrapper.models.contacts import Contacts
 
 BASE_HTTP_URL = "http://localhost:7000/v1/contacts/"
 
diff --git a/tests/briar/api/models/test_private_chat.py b/tests/briar_wrapper/models/test_private_chat.py
similarity index 95%
rename from tests/briar/api/models/test_private_chat.py
rename to tests/briar_wrapper/models/test_private_chat.py
index 60222f5..d454a8b 100644
--- a/tests/briar/api/models/test_private_chat.py
+++ b/tests/briar_wrapper/models/test_private_chat.py
@@ -6,7 +6,7 @@ import json
 
 import requests_mock
 
-from briar.api.models.private_chat import PrivateChat
+from briar_wrapper.models.private_chat import PrivateChat
 
 BASE_HTTP_URL = "http://localhost:7000/v1/messages/%s"
 
diff --git a/tests/briar/api/test_constants.py b/tests/briar_wrapper/test_constants.py
similarity index 82%
rename from tests/briar/api/test_constants.py
rename to tests/briar_wrapper/test_constants.py
index 45376bc..7f6f807 100644
--- a/tests/briar/api/test_constants.py
+++ b/tests/briar_wrapper/test_constants.py
@@ -7,8 +7,8 @@ from pathlib import Path
 
 import pytest
 
-from briar.api.constants import BASE_HTTP_URL, BRIAR_AUTH_TOKEN
-from briar.api.constants import BRIAR_DB, WEBSOCKET_URL
+from briar_wrapper.constants import BASE_HTTP_URL, BRIAR_AUTH_TOKEN
+from briar_wrapper.constants import BRIAR_DB, WEBSOCKET_URL
 
 
 def test_base_http_url():
diff --git a/tools/tests/test-pycodestyle.sh b/tools/tests/test-pycodestyle.sh
index 1b4d28e..51a23d6 100755
--- a/tools/tests/test-pycodestyle.sh
+++ b/tools/tests/test-pycodestyle.sh
@@ -3,4 +3,4 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 # License-Filename: LICENSE.md
 
-pycodestyle --show-source --show-pep8 src tests
+pycodestyle --show-source --show-pep8 briar_wrapper tests
diff --git a/tools/tests/test-pylint.sh b/tools/tests/test-pylint.sh
index 427e9b3..1a9dd98 100755
--- a/tools/tests/test-pylint.sh
+++ b/tools/tests/test-pylint.sh
@@ -3,4 +3,4 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 # License-Filename: LICENSE.md
 
-pylint src tests
+pylint briar_wrapper tests
diff --git a/tools/tests/test-pytest.sh b/tools/tests/test-pytest.sh
index 4c8d078..d175030 100755
--- a/tools/tests/test-pytest.sh
+++ b/tools/tests/test-pytest.sh
@@ -3,4 +3,4 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 # License-Filename: LICENSE.md
 
-PYTHONPATH=src pytest --cov=src tests/
+PYTHONPATH=briar_wrapper pytest --cov=briar_wrapper tests/
-- 
GitLab