From 68a5be4bfec32afcd9067636dc543d0ad45ad757 Mon Sep 17 00:00:00 2001 From: Olivier Vitrac Date: Thu, 27 Feb 2025 17:22:28 +0100 Subject: [PATCH] refactored release --- utils/generate_mermaid.py | 4 +-- utils/generate_setup.py | 61 ++++++++++++++++++------------------ utils/pdocme.sh | 2 +- utils/refresh_allreleases.sh | 2 +- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/utils/generate_mermaid.py b/utils/generate_mermaid.py index 890de5d..0a0168f 100755 --- a/utils/generate_mermaid.py +++ b/utils/generate_mermaid.py @@ -31,7 +31,7 @@ ## **Running SFPPy** > **SFPPy** enables the **compliance assessment of food contact materials** and facilitates **risk assessments** through **migration modeling**. -> The term *"[Migration Modeling]("./MigrationModeling/")"* refers to the **simulation of mass transfer** (primarily diffusive) from packaging materials into food. +> The term *"[Migration Modeling]("MigrationModeling/")"* refers to the **simulation of mass transfer** (primarily diffusive) from packaging materials into food. #### **What this guide covers:** 1. **Running SFPPy/example1.py** (or `example2.py`, `example3.py`) immediately after cloning the repository. @@ -45,7 +45,7 @@ ### **📌 Prerequisites** Before running SFPPy, make sure you have: -✅ **A basic understanding of Migration Modeling** → Read this [document]("./MigrationModeling/"). +✅ **A basic understanding of Migration Modeling** → Read this [document]("MigrationModeling/"). ✅ **Python 3.x (≥3.8) installed**. ✅ **Dependencies installed**: - If your Python distribution does **not include scientific libraries** (NumPy, SciPy, Matplotlib, Pandas), install them using: diff --git a/utils/generate_setup.py b/utils/generate_setup.py index da1a2db..afa54b5 100755 --- a/utils/generate_setup.py +++ b/utils/generate_setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ -Generates setup.py for SETUP +Generates setup.py, requirements and environment.yml for SETUP The following project structure is assumed. @@ -47,36 +47,33 @@ """ - import os import sys import re from pathlib import Path -# Define dependencies (same for pip and Conda) +# Define dependencies dependencies = [ - "numpy>=1.21.0", # Matrix computations (finite-volume method) - "matplotlib>=3.4.0", # Modern plotting functions - "scipy>=1.7.0", # Numerical integration and solvers - "pandas>=1.3.0", # Data manipulation and Excel support - "openpyxl>=3.0.10" # Save to .xlsx format + "numpy>=1.21.0", + "matplotlib>=3.4.0", + "scipy>=1.7.0", + "pandas>=1.3.0", + "openpyxl>=3.0.10" ] -conda_channels = ["conda-forge", "defaults"] # Recommended Conda channels - +conda_channels = ["conda-forge", "defaults"] def is_utils_directory(current_path): """Verify that the script is run from the 'utils/' directory.""" return current_path.name == 'utils' - def get_version(parent_dir): """Extract the version number of SFPPy from VERSION.txt.""" version_file = parent_dir / "utils" / "VERSION.txt" if not version_file.exists(): sys.stderr.write(f"Error: {version_file} not found. Please create a file with content: version=\"XX.YY.ZZ\"\n") sys.exit(1) - + with open(version_file, "r") as f: for line in f: match = re.match(r'^version\s*=\s*"(.*?)"$', line.strip()) @@ -86,7 +83,6 @@ def get_version(parent_dir): sys.stderr.write(f"Error: No valid version string found in {version_file}. Ensure it contains: version=\"XX.YY.ZZ\"\n") sys.exit(1) - def prompt_overwrite(file_path): """Prompt the user to overwrite an existing file.""" while True: @@ -98,7 +94,6 @@ def prompt_overwrite(file_path): else: print("Please enter 'Y' or 'N'.") - def generate_setup_py(parent_dir, dependencies): """Generate setup.py with specified dependencies.""" setup_path = parent_dir / "setup.py" @@ -133,9 +128,8 @@ def generate_setup_py(parent_dir, dependencies): with open(setup_path, 'w') as f: f.write(setup_content) - - print(f"✔ setup.py created successfully in '{parent_dir}'.") + print(f"✔ setup.py created successfully in '{parent_dir}'.") def generate_environment_yml(parent_dir, dependencies, conda_channels): """Generate environment.yml for Conda users.""" @@ -145,42 +139,49 @@ def generate_environment_yml(parent_dir, dependencies, conda_channels): print("Skipping environment.yml generation.") return - # Convert dependencies for Conda (removes version constraints if necessary) conda_deps = [dep.replace(">=", "=") for dep in dependencies] env_content = f"""name: sfppy - channels: - {chr(10).join(f" - {channel}" for channel in conda_channels)} - dependencies: - - python=3.10 - {chr(10).join(f" - {dep}" for dep in conda_deps)} - """ - +channels: +{chr(10).join(f" - {channel}" for channel in conda_channels)} +dependencies: +- python=3.10 +{chr(10).join(f" - {dep}" for dep in conda_deps)} +""" with open(env_path, 'w') as f: f.write(env_content) print(f"✔ environment.yml created successfully in '{parent_dir}'.") +def generate_requirements_txt(parent_dir, dependencies): + """Generate requirements.txt for pip users.""" + req_path = parent_dir / "requirements.txt" + + if req_path.exists() and not prompt_overwrite(req_path): + print("Skipping requirements.txt generation.") + return + + req_content = "\n".join(dependencies) + + with open(req_path, 'w') as f: + f.write(req_content) + + print(f"✔ requirements.txt created successfully in '{parent_dir}'.") def main(): """Main script execution.""" current_dir = Path.cwd() - # Ensure the script is run from 'utils/' if not is_utils_directory(current_dir): print("Error: This script must be run from the 'utils/' directory of the SFPPy project.") sys.exit(1) - # Define parent project directory parent_dir = current_dir.parent - # Generate setup.py generate_setup_py(parent_dir, dependencies) - - # Generate environment.yml generate_environment_yml(parent_dir, dependencies, conda_channels) - + generate_requirements_txt(parent_dir, dependencies) if __name__ == '__main__': main() diff --git a/utils/pdocme.sh b/utils/pdocme.sh index bc2e315..e0a9d99 100755 --- a/utils/pdocme.sh +++ b/utils/pdocme.sh @@ -729,7 +729,7 @@ cat > "$index_file" < If you are looking for the concepts of migration modeling and risk assessment, please follow this - link. + link. diff --git a/utils/refresh_allreleases.sh b/utils/refresh_allreleases.sh index a920490..13bfa5d 100755 --- a/utils/refresh_allreleases.sh +++ b/utils/refresh_allreleases.sh @@ -173,7 +173,7 @@ generate_release_type() { # Generate Full Release generate_release_type "$generate_simple_manifest" "$generate_release" "Full" -# Generate Minimalist Release +# Generate Minimalist Release (not needed yet) #generate_release_type "$generate_mini_manifest" "$generate_mini_release" "Minimalist" echo ""