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

global: replace FLASK_ENV with FLASK_DEBUG #382

Merged
merged 3 commits into from
Feb 19, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2025 CERN.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

name: Publish

on:
push:
tags:
- v*

jobs:
build-n-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel babel
- name: Build package
run: |
python setup.py sdist bdist_wheel
- name: pypi-publish
uses: pypa/gh-action-pypi-publish@v1.3.1
with:
user: __token__
password: ${{ secrets.pypi_token }}
Build-N-Publish:
uses: inveniosoftware/workflows/.github/workflows/pypi-publish.yml@master
secrets: inherit
36 changes: 6 additions & 30 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2020 CERN.
# Copyright (C) 2020-2025 CERN.
# Copyright (C) 2022 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or modify it
Expand All @@ -28,32 +28,8 @@ on:
default: 'Manual trigger'

jobs:
python-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.12']
requirements-level: [pypi]

env:
EXTRAS: tests

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: setup.cfg

- name: Install dependencies
run: |
pip install -e .[$EXTRAS]
pip freeze

- name: Run tests
run: |
./run-tests.sh
Python:
uses: inveniosoftware/workflows/.github/workflows/tests-python.yml@master
with:
db-service: '[""]'
search-service: '[""]'
2 changes: 1 addition & 1 deletion invenio_cli/cli/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def build(cli_config, no_wipe, production, node_log_file):
commands = AssetsCommands(cli_config)
commands.update_statics_and_assets(
force=not no_wipe, # If no_wipe=True, it means force=False
flask_env="production" if production else "development",
debug=not production,
log_file=node_log_file,
)

Expand Down
7 changes: 5 additions & 2 deletions invenio_cli/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ def install(cli_config, pre, dev, production):
builds front-end assets.
"""
commands = InstallCommands(cli_config)
flask_env = "production" if production else "development"
steps = commands.install(pre=pre, dev=dev, flask_env=flask_env)
steps = commands.install(
pre=pre,
dev=dev,
debug=not production,
)
on_fail = "Failed to install dependencies."
on_success = "Dependencies installed successfully."

Expand Down
3 changes: 1 addition & 2 deletions invenio_cli/cli/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

"""Invenio module to ease the creation and management of applications."""


import click

from ..commands import AssetsCommands, PackagesCommands
Expand Down Expand Up @@ -70,7 +69,7 @@ def install(cli_config, packages, skip_build, pip_log_file, node_log_file):
if not skip_build:
click.secho("Rebuilding assets...")
AssetsCommands(cli_config).update_statics_and_assets(
force=True, flask_env="development", log_file=node_log_file
force=True, debug=True, log_file=node_log_file
)


Expand Down
5 changes: 2 additions & 3 deletions invenio_cli/commands/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

"""Invenio module to ease the creation and management of applications."""


import subprocess
from pathlib import Path

Expand Down Expand Up @@ -73,7 +72,7 @@ def _npm_install_command(path):
)
else:
return ProcessResponse(
error=f"Unable to install dependent packages. "
error="Unable to install dependent packages. "
"Got error code {status_code}",
status_code=status_code,
)
Expand Down Expand Up @@ -118,7 +117,7 @@ def watch_assets(self):
prefix = ["pipenv", "run"]
watch_cmd = prefix + ["invenio", "webpack", "run", "start"]

with env(FLASK_ENV="development"):
with env(FLASK_DEBUG="true"):
# Collect into statics/ and assets/ folder
click.secho(
"Starting assets watching (press CTRL+C to stop)...", fg="green"
Expand Down
2 changes: 1 addition & 1 deletion invenio_cli/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def shell(cls):
@classmethod
def pyshell(cls, debug=False):
"""Start a Python shell."""
with env(FLASK_ENV="development" if debug else "production"):
with env(FLASK_DEBUG=str(debug)):
command = ["pipenv", "run", "invenio", "shell"]
return run_interactive(command, env={"PIPENV_VERBOSITY": "-1"})

Expand Down
14 changes: 7 additions & 7 deletions invenio_cli/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

"""Invenio module to ease the creation and management of applications."""

from ..helpers import env, filesystem
from ..helpers import filesystem
from ..helpers.process import run_cmd
from .local import LocalCommands
from .packages import PackagesCommands
from .steps import CommandStep, FunctionStep
from .steps import FunctionStep


class InstallCommands(LocalCommands):
Expand Down Expand Up @@ -61,7 +61,7 @@ def symlink_project_file_or_folder(self, target):

return filesystem.force_symlink(target_path, link_path)

def install(self, pre, dev=False, flask_env="production"):
def install(self, pre, dev=False, debug=False):
"""Development installation steps."""
steps = self.install_py_dependencies(pre=pre, dev=dev)
steps.append(
Expand All @@ -73,27 +73,27 @@ def install(self, pre, dev=False, flask_env="production"):
FunctionStep(
func=self.symlink_project_file_or_folder,
args={"target": "invenio.cfg"},
message=f"Symlinking 'invenio.cfg'...",
message="Symlinking 'invenio.cfg'...",
)
)
steps.append(
FunctionStep(
func=self.symlink_project_file_or_folder,
args={"target": "templates"},
message=f"Symlinking 'templates'...",
message="Symlinking 'templates'...",
)
)
steps.append(
FunctionStep(
func=self.symlink_project_file_or_folder,
args={"target": "app_data"},
message=f"Symlinking 'app_data'...",
message="Symlinking 'app_data'...",
)
)
steps.append(
FunctionStep(
func=self.update_statics_and_assets,
args={"force": True, "flask_env": flask_env},
args={"force": True, "debug": debug},
message="Updating statics and assets...",
)
)
Expand Down
6 changes: 3 additions & 3 deletions invenio_cli/commands/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _statics(self):
status_code=0,
)

def update_statics_and_assets(self, force, flask_env="production", log_file=None):
def update_statics_and_assets(self, force, debug=False, log_file=None):
"""High-level command to update less/js/images/... files.

Needed here (parent) because is used by Assets and Install commands.
Expand All @@ -101,7 +101,7 @@ def update_statics_and_assets(self, force, flask_env="production", log_file=None
"install": "Installing JS dependencies...",
}

with env(FLASK_ENV=flask_env):
with env(FLASK_DEUBG="true" if debug else "false"):
for op in ops:
if callable(op):
response = op()
Expand Down Expand Up @@ -153,7 +153,7 @@ def signal_handler(sig, frame):

click.secho("Starting up local (development) server...", fg="green")
run_env = environ.copy()
run_env["FLASK_ENV"] = "development" if debug else "production"
run_env["FLASK_DEBUG"] = str(debug)
run_env["INVENIO_SITE_UI_URL"] = f"https://{host}:{port}"
run_env["INVENIO_SITE_API_URL"] = f"https://{host}:{port}/api"
server = popen(
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ install_requires =

[options.extras_require]
tests =
pytest-black==0.3.9
pytest-black>=0.6.0
pytest-invenio>=1.4.0
Sphinx>=4.2.0

Expand Down
6 changes: 2 additions & 4 deletions tests/commands/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ def test_install(mock_cli_config):
commands._update_instance_path.assert_called()
expected_symlink_calls = [call("invenio.cfg"), call("templates"), call("app_data")]
assert commands._symlink_project_file_or_folder.mock_calls == expected_symlink_calls
commands.update_statics_and_assets.assert_called_with(
force=True, flask_env="production"
)
commands.update_statics_and_assets.assert_called_with(force=True, debug=False)


@pytest.mark.skip()
Expand Down Expand Up @@ -285,7 +283,7 @@ def test_run(
commands.run(host=host, port=port, debug=True)

run_env = environ.copy()
run_env["FLASK_ENV"] = "development"
run_env["FLASK_DEBUG"] = "True"
run_env["INVENIO_SITE_HOSTNAME"] = f"{host}:{port}"
expected_calls = [
call(["pipenv", "run", "celery", "--app", "invenio_app.celery", "worker"]),
Expand Down
8 changes: 4 additions & 4 deletions tests/helpers/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

def test_env():
"""Test environment variables context manager."""
assert "FLASK_ENV" not in os.environ
assert "SERVER_NAME" not in os.environ
assert "FLASK_DEBUG" not in os.environ

os.environ["FLASK_DEBUG"] = "true"
with env(FLASK_ENV="production", FLASK_DEBUG="false"):
assert os.environ["FLASK_ENV"] == "production"
with env(SERVER_NAME="example.com", FLASK_DEBUG="false"):
assert os.environ["SERVER_NAME"] == "example.com"
assert os.environ["FLASK_DEBUG"] == "false"

assert os.environ["FLASK_DEBUG"] == "true"
assert "FLASK_ENV" not in os.environ
assert "SERVER_NAME" not in os.environ
Loading