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

feat: change Makefile to generate dedicated python requirements.txt files #776

Merged
merged 16 commits into from Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint-and-test.yml
Expand Up @@ -38,13 +38,13 @@ jobs:
run: |
git fetch --prune --unshallow
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
- name: "Caching dependencies (txt)"
- name: "Caching for dependencies (.txt) - restore existing or ensure new cache will be made"
uses: actions/cache@v2
id: cache
with:
path: ${{ env.pythonLocation }}
# manually disable a cache if needed by (re)setting CACHE_DATE
key: ${{ runner.os }}-pip-${{ env.pythonLocation }}-${{ SECRETS.CACHE_DATE }}-${{ hashFiles('**/requirements/**.txt') }}
key: ${{ runner.os }}-pip-${{ env.pythonLocation }}-${{ SECRETS.CACHE_DATE }}-${{ hashFiles('**/requirements/**/*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- run: |
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Expand Up @@ -12,7 +12,10 @@ WORKDIR /app
COPY requirements /app/requirements

# py dev tooling
RUN python3 -m pip install --no-cache-dir --upgrade pip && python3 --version && pip3 install --no-cache-dir --upgrade setuptools && pip3 install highspy && pip3 install --no-cache-dir -r requirements/app.txt -r requirements/dev.txt -r requirements/test.txt
RUN python3 -m pip install --no-cache-dir --upgrade pip && python3 --version && \
pip3 install --no-cache-dir --upgrade setuptools && pip3 install highspy && \
PYV=$(python3 -c "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)") && \
pip3 install --no-cache-dir -r requirements/$PYV/app.txt -r requirements/$PYV/dev.txt -r requirements/$PYV/test.txt

# Copy code and meta/config data
COPY setup.* .flaskenv wsgi.py /app/
Expand Down
48 changes: 34 additions & 14 deletions Makefile
@@ -1,3 +1,7 @@
# Check Python major and minor version
# For more information, see https://stackoverflow.com/a/22105036
PYV = $(shell python -c "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)")

# Note: use tabs
# actions which are virtual, i.e. not a script
.PHONY: install install-for-dev install-for-test install-deps install-flexmeasures run-local test freeze-deps upgrade-deps update-docs update-docs-pdf show-file-space show-data-model clean-db
Expand Down Expand Up @@ -35,14 +39,15 @@ install: install-deps install-flexmeasures

install-for-dev:
make freeze-deps
pip-sync requirements/app.txt requirements/dev.txt requirements/test.txt
make ensure-deps-folder
pip-sync requirements/${PYV}/app.txt requirements/${PYV}/dev.txt requirements/${PYV}/test.txt
make install-flexmeasures

install-for-test:
make install-pip-tools
# Pass pinned=no if you want to test against latest stable packages, default is our pinned dependency set
ifneq ($(pinned), no)
pip-sync requirements/app.txt requirements/test.txt
pip-sync requirements/${PYV}/app.txt requirements/${PYV}/test.txt
else
# cutting off the -c inter-layer dependency (that's pip-tools specific)
tail -n +3 requirements/test.in >> temp-test.in
Expand All @@ -56,7 +61,7 @@ install-deps:
make freeze-deps
# Pass pinned=no if you want to test against latest stable packages, default is our pinned dependency set
ifneq ($(pinned), no)
pip-sync requirements/app.txt
pip-sync requirements/${PYV}/app.txt
else
pip install --upgrade -r requirements/app.in
endif
Expand All @@ -68,23 +73,35 @@ install-pip-tools:
pip3 install -q "pip-tools>=7.0"

install-docs-dependencies:
pip install -r requirements/docs.txt
pip install -r requirements/${PYV}/docs.txt

freeze-deps:
make ensure-deps-folder
make install-pip-tools
pip-compile -o requirements/app.txt requirements/app.in
pip-compile -o requirements/test.txt requirements/test.in
pip-compile -o requirements/dev.txt requirements/dev.in
pip-compile -o requirements/docs.txt requirements/docs.in
pip-compile -o requirements/${PYV}/app.txt requirements/app.in
# Create app.txt to create constraints for test.txt and dev.txt
cat requirements/${PYV}/app.txt > requirements/app.txt
pip-compile -o requirements/${PYV}/test.txt requirements/test.in
cat requirements/${PYV}/test.txt > requirements/test.txt
pip-compile -o requirements/${PYV}/dev.txt requirements/dev.in
pip-compile -o requirements/${PYV}/docs.txt requirements/docs.in
rm requirements/app.txt
rm requirements/test.txt

upgrade-deps:
make ensure-deps-folder
make install-pip-tools
pip-compile --upgrade -o requirements/app.txt requirements/app.in
pip-compile --upgrade -o requirements/test.txt requirements/test.in
pip-compile --upgrade -o requirements/dev.txt requirements/dev.in
pip-compile --upgrade -o requirements/docs.txt requirements/docs.in
make test
pip-compile --upgrade -o requirements/${PYV}/app.txt requirements/app.in
# Create app.txt to create constraints for test.txt and dev.txt
cat requirements/${PYV}/app.txt > requirements/app.txt
pip-compile --upgrade -o requirements/${PYV}/test.txt requirements/test.in
cat requirements/${PYV}/test.txt > requirements/test.txt
pip-compile --upgrade -o requirements/${PYV}/dev.txt requirements/dev.in
pip-compile --upgrade -o requirements/${PYV}/docs.txt requirements/docs.in
rm requirements/app.txt
rm requirements/test.txt

make test

# ---- Data ----

Expand All @@ -104,5 +121,8 @@ show-data-model:
# Use --help to learn more.
./flexmeasures/data/scripts/visualize_data_model.py --uml

ensure-deps-folder:
mkdir -p requirements/${PYV}

clean-db:
./flexmeasures/data/scripts/clean_database.sh ${db_name} ${db_user}
./flexmeasures/data/scripts/clean_database.sh ${db_name} ${db_user}
1 change: 1 addition & 0 deletions documentation/changelog.rst
Expand Up @@ -41,6 +41,7 @@ Infrastructure / Support
* Document the `device_scheduler` linear program [see `PR #764 <https://www.github.com/FlexMeasures/flexmeasures/pull/764>`_].
* Add support for `HiGHS <https://highs.dev/>`_ solver [see `PR #766 <https://www.github.com/FlexMeasures/flexmeasures/pull/766>`_].
* Add support for installing FlexMeasures under Python 3.11 [see `PR #771 <https://www.github.com/FlexMeasures/flexmeasures/pull/771>`_].
* Start keeping sets of pinned requirements per supported Python version. Also fixes recent Docker build problem. [see `PR #776 <https://www.github.com/FlexMeasures/flexmeasures/pull/776>`_]
* Removed obsolete code dealing with deprecated data models (e.g. assets, markets and weather sensors), and sunset the fm0 scheme for entity addresses [see `PR #695 <https://www.github.com/FlexMeasures/flexmeasures/pull/695>`_ and `project 11 <https://www.github.com/FlexMeasures/flexmeasures/projects/11>`_]

v0.14.2 | July 25, 2023
Expand Down
2 changes: 2 additions & 0 deletions flexmeasures/api/v3_0/tests/conftest.py
@@ -1,3 +1,5 @@
from __future__ import annotations

from datetime import timedelta

import pandas as pd
Expand Down
7 changes: 3 additions & 4 deletions requirements/app.txt → requirements/3.10/app.txt
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements/app.txt requirements/app.in
# pip-compile --output-file=requirements/3.10/app.txt requirements/app.in
#
alembic==1.11.1
# via flask-migrate
Expand Down Expand Up @@ -208,7 +208,7 @@ patsy==0.5.3
# via statsmodels
pillow==9.5.0
# via matplotlib
pint==0.22
pint==0.21.1
# via -r requirements/app.in
ply==3.11
# via pyomo
Expand Down Expand Up @@ -278,7 +278,7 @@ scikit-learn==1.2.2
# via
# sktime
# timetomodel
scipy==1.11.1
scipy==1.10.1
# via
# properscoring
# scikit-learn
Expand Down Expand Up @@ -323,7 +323,6 @@ typing-extensions==4.7.0
# via
# alembic
# altair
# pint
# py-moneyed
# pydantic
tzdata==2023.3
Expand Down
8 changes: 5 additions & 3 deletions requirements/dev.txt → requirements/3.10/dev.txt
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements/dev.txt requirements/dev.in
# pip-compile --output-file=requirements/3.10/dev.txt requirements/dev.in
#
black==22.3.0
# via -r requirements/dev.in
Expand Down Expand Up @@ -56,8 +56,10 @@ pyinstrument==4.5.0
# via -r requirements/dev.in
pytest-runner==6.0.0
# via -r requirements/dev.in
pyyaml==6.0
# via pre-commit
pyyaml==6.0.1
# via
# -c requirements/app.txt
# pre-commit
setuptools-scm==7.1.0
# via -r requirements/dev.in
tomli==2.0.1
Expand Down
2 changes: 1 addition & 1 deletion requirements/docs.txt → requirements/3.10/docs.txt
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements/docs.txt requirements/docs.in
# pip-compile --output-file=requirements/3.10/docs.txt requirements/docs.in
#
alabaster==0.7.13
# via sphinx
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt → requirements/3.10/test.txt
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements/test.txt requirements/test.in
# pip-compile --output-file=requirements/3.10/test.txt requirements/test.in
#
async-timeout==4.0.2
# via
Expand Down