Repository: FlexMeasures/flexmeasures (language: python)

Issue:
Modernize packaging 
Packaging of FlexMeasures needs some attention, [to stop calling `setup.py`](https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html) and to fix some packaging.

In any case, we should switch to `python -m build` in the to_pypi script, and to `pip install -e` in the Makefile.

Also, running `/to_pypi.sh --dry-run`, I see this error:

```
/home/nicolas/envs/fm-3.10/lib/python3.10/site-packages/setuptools/command/build_py.py:201: _Warning: Package 'flexmeasures.api.common.schemas' is absent from the `packages` configuration.
```

Maybe we need to be more explicit. There is some help in the warnings.



Discussion / hints:

Fix patch:
diff --git a/.gitignore b/.gitignore
index db26adc49..2ce31f0d1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,6 +29,7 @@ notebooks/.ipynb_checkpoints/
 
 flexmeasures/ui/static/documentation
 documentation/img/screenshot_*
+generic_asset_fm_user_ownership.sql
 
 uml_diagram.png
 db_schema.png
diff --git a/Makefile b/Makefile
index 7f6aa66be..2e789d537 100644
--- a/Makefile
+++ b/Makefile
@@ -46,7 +46,7 @@ install-deps:
 	pip-sync requirements/app.txt
 
 install-flexmeasures:
-	python setup.py develop
+	pip install -e
 
 install-pip-tools:
 	pip3 install -q "pip-tools>=6.4"
diff --git a/documentation/changelog.rst b/documentation/changelog.rst
index c4bbe0d96..acf39dfd5 100644
--- a/documentation/changelog.rst
+++ b/documentation/changelog.rst
@@ -19,6 +19,7 @@ Infrastructure / Support
 ----------------------
 
 * The setting FLEXMEASURES_PLUGINS can be set as environment variable now (as a comma-separated list) [see `PR #660 <https://www.github.com/FlexMeasures/flexmeasures/pull/660>`_]
+* Packaging was modernized to stop calling setup.py directly [see `PR #671 <https://www.github.com/FlexMeasures/flexmeasures/pull/671>`_]
 * Remove API versions 1.0, 1.1, 1.2, 1.3 and 2.0, while allowing hosts to switch between ``HTTP status 410 (Gone)`` and ``HTTP status 404 (Not Found)`` responses [see `PR #667 <https://www.github.com/FlexMeasures/flexmeasures/pull/667>`_]
 
 .. warning:: The setting `FLEXMEASURES_PLUGIN_PATHS` has been deprecated since v0.7. It has now been sunset. Please replace it with :ref:`plugin-config`.
diff --git a/flexmeasures/api/common/schemas/__init__.py b/flexmeasures/api/common/schemas/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/setup.py b/setup.py
index e989d8cdb..e610a7480 100644
--- a/setup.py
+++ b/setup.py
@@ -26,7 +26,11 @@ def load_requirements(use_case):
     install_requires=load_requirements("app"),
     setup_requires=["setuptools_scm"],
     use_scm_version={"local_scheme": "no-local-version"},  # handled by setuptools_scm
-    packages=find_packages(),  # will include *.py files and some other types
+    packages=find_packages()
+    + [
+        "flexmeasures.ui.templates",
+        "flexmeasures.ui.static",
+    ],  # will include *.py files and some other types
     include_package_data=True,  # now setuptools_scm adds all files under source control
     entry_points={
         "console_scripts": [
diff --git a/to_pypi.sh b/to_pypi.sh
index 41224be1c..349d93c50 100755
--- a/to_pypi.sh
+++ b/to_pypi.sh
@@ -66,12 +66,11 @@ pip -q install twine
 pip -q install wheel
 
 echo "[TO_PYPI] Packaging ..."
-python setup.py egg_info sdist
-python setup.py egg_info bdist_wheel
+python -m build
 
 if [ "$1" == "--dry-run" ]; then
     echo "[TO_PYPI] Not uploading to Pypi (--dry-run active) ..."
-    exit
+else
+    echo "[TO_PYPI] Uploading to Pypi ..."
+    twine upload dist/*
 fi
-echo "[TO_PYPI] Uploading to Pypi ..."
-twine upload dist/*


Test patch:
diff --git a/flexmeasures/api/common/schemas/tests/__init__.py b/flexmeasures/api/common/schemas/tests/__init__.py
new file mode 100644
index 000000000..e69de29bb