Skip to content

Commit

Permalink
refactored release
Browse files Browse the repository at this point in the history
  • Loading branch information
ovitrac committed Feb 27, 2025
1 parent c4fdfd8 commit 68a5be4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 34 deletions.
4 changes: 2 additions & 2 deletions utils/generate_mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down
61 changes: 31 additions & 30 deletions utils/generate_setup.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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())
Expand All @@ -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:
Expand All @@ -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"
Expand Down Expand Up @@ -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."""
Expand All @@ -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()
2 changes: 1 addition & 1 deletion utils/pdocme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ cat > "$index_file" <<EOF
<div id="notification-banner" class="notification-banner">
<span>
If you are looking for the concepts of migration modeling and risk assessment, please follow this
<a href="./MigrationModeling/" target="_book">link</a>.
<a href="MigrationModeling/" target="_book">link</a>.
</span>
<button class="close-button" onclick="closeBanner()">&times;</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion utils/refresh_allreleases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down

0 comments on commit 68a5be4

Please sign in to comment.