diff --git a/python-development-environment/LICENSE b/python-development-environment/LICENSE new file mode 100644 index 00000000..b7715948 --- /dev/null +++ b/python-development-environment/LICENSE @@ -0,0 +1,193 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (excluding those notices that do not pertain to any part of + the derivatives of the Work). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based upon (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and derivative works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control + systems, and issue tracking systems that are managed by, or on behalf + of, the Licensor for the purpose of discussing and improving the Work, + but excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to use, reproduce, modify, distribute, sublicense, + and/or sell copies of the Work, and to permit persons to whom the + Work is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Work. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, trademark, patent, + attribution and other notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright notice to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. When redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +Copyright 2025 DongilMin + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/python-development-environment/README.md b/python-development-environment/README.md new file mode 100644 index 00000000..93ce81ae --- /dev/null +++ b/python-development-environment/README.md @@ -0,0 +1,212 @@ +# Python Development Environment Blueprint + +This Cloudify blueprint automatically sets up a complete, production-ready Python development environment with essential tools and scientific computing packages. + +## Features + +- **Python Installation**: Automatic Python 3.8+ installation with pip and venv +- **Package Management**: Pre-configured virtual environment with essential packages +- **Development Tools**: pytest, black, flake8, ipython for professional development +- **Scientific Computing**: NumPy and Pandas for data analysis +- **HTTP Library**: Requests for API interactions +- **Organized Workspace**: Structured directories for projects, tests, and data +- **Configuration**: Useful aliases and startup configurations +- **Example Project**: Ready-to-use example with tests and documentation + +## Quick Start + +### 1. Upload Blueprint +```bash +cfy blueprints upload -b python-dev blueprint.yaml +``` + +### 2. Create Deployment +```bash +# For general development +cfy deployments create -b python-dev -i inputs/local-dev.yaml python-dev-deployment + +# For data science +cfy deployments create -b python-dev -i inputs/data-science.yaml python-ds-deployment + +# For web development +cfy deployments create -b python-dev -i inputs/web-dev.yaml python-web-deployment +``` + +### 3. Install Environment +```bash +cfy executions start -d python-dev-deployment install +``` + +## Configuration Options + +### Inputs + +| Input | Type | Default | Description | +|-------|------|---------|-------------| +| `python_version` | string | "3.9" | Python version (3.8, 3.9, 3.10, 3.11) | +| `workspace_path` | string | "~/python-workspace" | Development workspace path | +| `dev_packages` | string | See below | Python packages to install | + +### Default Packages + +**Local Development**: `pytest black flake8 ipython requests numpy pandas` + +**Data Science**: `pytest black flake8 ipython requests numpy pandas matplotlib seaborn scikit-learn` + +**Web Development**: `pytest black flake8 ipython requests flask django fastapi uvicorn gunicorn` + +## Usage After Installation + +### Activate Environment +```bash +source ~/python-dev-env/bin/activate +# or use the alias +activate-python +``` + +### Navigate to Workspace +```bash +cd ~/python-workspace +# or use the alias +python-workspace +``` + +### Development Commands +```bash +# Run tests +run-tests + +# Format code +format-code + +# Lint code +lint-code + +# Check environment setup +bash setup-environment.sh +``` + +### Directory Structure +``` +~/python-workspace/ +├── projects/ # Your Python projects +├── scripts/ # Utility scripts +├── data/ # Data files +├── tests/ # Test files +├── example-project/ # Example project with tests +│ ├── src/calculator.py # Example module +│ ├── tests/ # Example tests +│ └── README.md # Project documentation +└── setup-environment.sh # Environment verification script +``` + +## Tested Environments + +- **CentOS 7+ Docker containers** (source compilation when needed) +- **Ubuntu 18.04+ systems** (package installation) +- **macOS 10.14+ systems** (Homebrew integration) +- **Cloudify Manager** (production deployment tested) + +## System Requirements + +- **Operating System**: Ubuntu 18.04+, CentOS 7+, macOS 10.14+ +- **Memory**: 2GB RAM minimum +- **Disk Space**: 2GB free space +- **Network**: Internet connection for package downloads + +## Example Usage + +After installation, try the example project: + +```bash +# Activate environment +source ~/python-dev-env/bin/activate + +# Navigate to example project +cd ~/python-workspace/example-project + +# Run the example +python src/calculator.py + +# Run tests +python -m pytest tests/ + +# Format and lint code +python -m black src/ tests/ +python -m flake8 src/ tests/ +``` + +## Package Details + +### Core Development Tools +- **pytest**: Professional testing framework +- **black**: Uncompromising code formatter +- **flake8**: Code style and error checker +- **ipython**: Enhanced interactive Python shell + +### Scientific Computing +- **numpy**: Fundamental package for scientific computing +- **pandas**: Data manipulation and analysis library + +### Utilities +- **requests**: HTTP library for API interactions + +### Optional Extensions +The blueprint supports additional packages like: +- **matplotlib, seaborn**: Data visualization +- **scikit-learn**: Machine learning +- **flask, django, fastapi**: Web frameworks + +## Blueprint Architecture + +### Lifecycle Operations +1. **Create Phase**: Python installation and build tools setup +2. **Configure Phase**: Virtual environment creation and package installation +3. **Verification**: Package import testing and workspace setup + +### Package Installation Strategy +- **Binary wheel preference**: Avoids compilation issues in containerized environments +- **Graceful fallback handling**: Multiple installation strategies for each package +- **Dependency resolution**: Proper handling of NumPy/Pandas dependencies +- **Cross-platform detection**: Automatic OS detection and package manager usage + +## Troubleshooting + +### Common Issues + +1. **Permission Errors**: The blueprint attempts to install build tools but falls back gracefully +2. **Package Installation Failures**: Binary wheels are preferred to avoid compilation issues +3. **Virtual Environment Issues**: The script handles existing environments gracefully + +### Verification + +Check your installation: +```bash +source ~/python-dev-env/bin/activate +python -c "import numpy, pandas, requests; print('All packages working!')" +``` + +## Use Cases + +- **Individual Developer Setup**: Quick local environment initialization +- **Team Standardization**: Consistent development environments across team members +- **CI/CD Pipeline Preparation**: Standardized testing environment setup +- **Educational Environments**: Classroom or workshop Python environment provisioning +- **Containerized Development**: Development environment setup in Docker containers + +## Future Extensions + +This blueprint provides a foundation that can be extended for: +- Node.js development environments +- Go programming environments +- R statistical computing setups +- Multi-language polyglot environments +- IDE and editor integration + +## Contributing + +This blueprint provides a foundation for Python development environment automation that can be extended for specific use cases or additional tools. + +## License + +Apache License 2.0 diff --git a/python-development-environment/blueprint.yaml b/python-development-environment/blueprint.yaml new file mode 100644 index 00000000..c74872df --- /dev/null +++ b/python-development-environment/blueprint.yaml @@ -0,0 +1,81 @@ +tosca_definitions_version: cloudify_dsl_1_3 + +description: > + Python Development Environment Blueprint - Production Ready Setup. + Automates cross-platform Python development environment with essential packages, + scientific computing libraries, and professional development tools. + +metadata: + template_name: python-development-environment + template_author: DongilMin + template_version: 1.0.0 + cloudify_min_version: 6.3.0 + template_tags: + - development + - python + - environment + - automation + - cross-platform + +imports: + - cloudify/types/types.yaml + +inputs: + python_version: + type: string + default: "3.9" + description: Python version to install (3.8, 3.9, 3.10, 3.11) + constraints: + - valid_values: ["3.8", "3.9", "3.10", "3.11"] + + workspace_path: + type: string + default: "~/python-workspace" + description: Development workspace directory path + + dev_packages: + type: string + default: "pytest black flake8 ipython requests numpy pandas" + description: Python packages to install (space-separated) + +node_templates: + python_dev_environment: + type: cloudify.nodes.Root + interfaces: + cloudify.interfaces.lifecycle: + create: + implementation: scripts/install-python-nosudo.sh + executor: central_deployment_agent + inputs: + python_version: { get_input: python_version } + configure: + implementation: scripts/setup-dev-tools-nosudo.sh + executor: central_deployment_agent + inputs: + workspace_path: { get_input: workspace_path } + dev_packages: { get_input: dev_packages } + +outputs: + python_version: + description: Installed Python version + value: { get_input: python_version } + + workspace_path: + description: Development workspace location + value: { get_input: workspace_path } + + dev_packages: + description: Installed development packages + value: { get_input: dev_packages } + + status: + description: Setup completion status + value: "Python development environment ready for production use!" + + usage_instructions: + description: Quick start instructions + value: > + To use the environment: + 1. source ~/python-dev-env/bin/activate + 2. cd ~/python-workspace + 3. python example-project/src/calculator.py diff --git a/python-development-environment/inputs/data-science.yaml b/python-development-environment/inputs/data-science.yaml new file mode 100644 index 00000000..b9d5afa4 --- /dev/null +++ b/python-development-environment/inputs/data-science.yaml @@ -0,0 +1,3 @@ +python_version: "3.9" +workspace_path: "~/data-science-workspace" +dev_packages: "pytest black flake8 ipython requests numpy pandas matplotlib seaborn scikit-learn" diff --git a/python-development-environment/inputs/local-dev.yaml b/python-development-environment/inputs/local-dev.yaml new file mode 100644 index 00000000..ff14d860 --- /dev/null +++ b/python-development-environment/inputs/local-dev.yaml @@ -0,0 +1,3 @@ +python_version: "3.9" +workspace_path: "~/python-workspace" +dev_packages: "pytest black flake8 ipython requests numpy pandas" diff --git a/python-development-environment/inputs/web-dev.yaml b/python-development-environment/inputs/web-dev.yaml new file mode 100644 index 00000000..85dff921 --- /dev/null +++ b/python-development-environment/inputs/web-dev.yaml @@ -0,0 +1,3 @@ +python_version: "3.9" +workspace_path: "~/web-dev-workspace" +dev_packages: "pytest black flake8 ipython requests flask django fastapi uvicorn gunicorn" diff --git a/python-development-environment/scripts/install-python-nosudo.sh b/python-development-environment/scripts/install-python-nosudo.sh new file mode 100755 index 00000000..d829d16a --- /dev/null +++ b/python-development-environment/scripts/install-python-nosudo.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -e + +echo "=== Python Development Environment Setup (Fixed) ===" +echo "Date: $(date)" +echo "User: $(whoami)" + +# 컴파일러 확인 및 설치 +echo "=== Checking and Installing Build Tools ===" +if ! command -v gcc &> /dev/null; then + echo "GCC not found. Installing build tools..." + if command -v yum &> /dev/null; then + # CentOS/RHEL + yum groupinstall -y "Development Tools" || echo "Development tools installation attempted" + yum install -y gcc gcc-c++ make python3-devel || echo "GCC installation attempted" + elif command -v apt-get &> /dev/null; then + # Ubuntu/Debian + apt-get update + apt-get install -y build-essential python3-dev + fi +else + echo "Build tools already available" +fi + +# 현재 Python 확인 +echo "=== Current Python Status ===" +python3 --version +pip3 --version + +# 컴파일러 상태 확인 +echo "=== Build Tools Status ===" +gcc --version || echo "GCC not available" +make --version || echo "Make not available" + +echo "=== Python Setup Phase Completed ===" diff --git a/python-development-environment/scripts/install-python.sh b/python-development-environment/scripts/install-python.sh new file mode 100755 index 00000000..5e760df0 --- /dev/null +++ b/python-development-environment/scripts/install-python.sh @@ -0,0 +1,181 @@ +#!/bin/bash +set -e + +PYTHON_VERSION="${python_version:-3.9}" + +echo "=== Starting Python ${PYTHON_VERSION} Development Environment Setup ===" +echo "Date: $(date)" +echo "User: $(whoami)" +echo "OS: $(cat /etc/os-release | grep PRETTY_NAME | cut -d'"' -f2 2>/dev/null || echo 'Unknown')" + +# Function to run command with or without sudo +run_cmd() { + if [[ $EUID -eq 0 ]]; then + # Running as root, no sudo needed + "$@" + else + # Not root, use sudo + sudo "$@" + fi +} + +# Detect OS and install Python +if [[ -f /etc/debian_version ]]; then + echo "=== Detected Debian/Ubuntu - Installing Python ${PYTHON_VERSION} ===" + run_cmd apt-get update + run_cmd apt-get install -y software-properties-common + run_cmd add-apt-repository -y ppa:deadsnakes/ppa || true + run_cmd apt-get update + run_cmd apt-get install -y \ + python${PYTHON_VERSION} \ + python${PYTHON_VERSION}-pip \ + python${PYTHON_VERSION}-venv \ + python${PYTHON_VERSION}-dev \ + build-essential \ + curl \ + wget \ + git \ + vim + +elif [[ -f /etc/redhat-release ]]; then + echo "=== Detected RedHat/CentOS - Installing Python ${PYTHON_VERSION} ===" + + # Fix CentOS 7 repository issues + if grep -q "CentOS Linux 7" /etc/redhat-release 2>/dev/null; then + echo "=== Fixing CentOS 7 repositories ===" + run_cmd sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo + run_cmd sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*.repo + fi + + run_cmd yum clean all + run_cmd yum update -y + run_cmd yum groupinstall -y "Development Tools" || echo "Development Tools group installation failed, continuing..." + + # Try to install Python 3.9 from packages first + echo "=== Attempting to install Python ${PYTHON_VERSION} from packages ===" + if yum list available python39 python39-pip python39-devel >/dev/null 2>&1; then + echo "Python 3.9 packages found, installing..." + run_cmd yum install -y python39 python39-pip python39-devel curl wget git vim + else + echo "Python 3.9 packages not available, compiling from source..." + + # Install build dependencies including SQLite + echo "=== Installing build dependencies ===" + run_cmd yum install -y \ + gcc \ + openssl-devel \ + bzip2-devel \ + libffi-devel \ + zlib-devel \ + sqlite-devel \ + readline-devel \ + tk-devel \ + curl \ + wget \ + git \ + vim \ + make + + # Compile Python from source + echo "=== Compiling Python ${PYTHON_VERSION} from source ===" + cd /tmp + + # Download Python source + echo "Downloading Python ${PYTHON_VERSION} source..." + wget https://www.python.org/ftp/python/3.9.18/Python-3.9.18.tgz + tar xzf Python-3.9.18.tgz + cd Python-3.9.18 + + # Configure compilation + echo "Configuring Python build..." + ./configure --enable-optimizations --prefix=/usr/local --enable-shared + + # Compile (this may take several minutes) + echo "Compiling Python (this may take 5-15 minutes)..." + make -j$(nproc) + + # Install + echo "Installing Python..." + run_cmd make altinstall + + # Configure library path + echo "/usr/local/lib" | run_cmd tee /etc/ld.so.conf.d/python3.9.conf + run_cmd ldconfig + + # Create symlinks + run_cmd ln -sf /usr/local/bin/python3.9 /usr/local/bin/python3 + run_cmd ln -sf /usr/local/bin/pip3.9 /usr/local/bin/pip3 + + # Cleanup + cd / + rm -rf /tmp/Python-3.9.18* + + echo "Python compilation and installation completed." + fi + +elif [[ "$OSTYPE" == "darwin"* ]]; then + echo "=== Detected macOS - Installing Python ${PYTHON_VERSION} ===" + if ! command -v brew &> /dev/null; then + echo "Installing Homebrew..." + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + fi + brew install python@${PYTHON_VERSION} git vim curl wget +fi + +# Find Python executable +PYTHON_CMD="" +PIP_CMD="" + +echo "=== Locating Python installation ===" +for cmd in python${PYTHON_VERSION} python3.9 python3; do + if command -v $cmd &> /dev/null; then + PYTHON_CMD=$cmd + echo "Found Python command: $cmd" + break + fi +done + +for cmd in pip${PYTHON_VERSION} pip3.9 pip3; do + if command -v $cmd &> /dev/null; then + PIP_CMD=$cmd + echo "Found pip command: $cmd" + break + fi +done + +# Verify Python installation +echo "=== Verifying Python Installation ===" +if [[ -n "$PYTHON_CMD" ]]; then + echo "Found Python: $PYTHON_CMD" + $PYTHON_CMD --version +else + echo "ERROR: Python installation failed!" + echo "Debugging information:" + echo "Checked for: python${PYTHON_VERSION}, python3.9, python3" + echo "PATH: $PATH" + ls -la /usr/local/bin/ | grep python || echo "No python in /usr/local/bin/" + exit 1 +fi + +if [[ -n "$PIP_CMD" ]]; then + echo "Found pip: $PIP_CMD" + $PIP_CMD --version +else + echo "pip not found, installing..." + $PYTHON_CMD -m ensurepip --default-pip + $PYTHON_CMD -m pip install --upgrade pip + PIP_CMD="$PYTHON_CMD -m pip" +fi + +# Create convenient symlinks if they don't exist and we have permission +if [[ ! -f /usr/local/bin/python3 ]] && [[ -w /usr/local/bin/ || $EUID -eq 0 ]]; then + run_cmd ln -sf $(which $PYTHON_CMD) /usr/local/bin/python3 || true +fi + +if [[ ! -f /usr/local/bin/pip3 ]] && [[ -w /usr/local/bin/ || $EUID -eq 0 ]]; then + run_cmd ln -sf $(which $PIP_CMD) /usr/local/bin/pip3 || true +fi + +echo "=== Python ${PYTHON_VERSION} Installation Completed Successfully ===" +echo "Python command: $PYTHON_CMD" +echo "Pip command: $PIP_CMD" diff --git a/python-development-environment/scripts/prepare-centos7.sh b/python-development-environment/scripts/prepare-centos7.sh new file mode 100755 index 00000000..5887b467 --- /dev/null +++ b/python-development-environment/scripts/prepare-centos7.sh @@ -0,0 +1,70 @@ + +#!/bin/bash +# CentOS 7 Preparation Script for Python Development Environment +# This script fixes CentOS 7 repository issues and installs git + +set -e + +echo "=== CentOS 7 Preparation Script ===" +echo "Date: $(date)" +echo "User: $(whoami)" + +# Check if this is CentOS 7 +if [[ ! -f /etc/redhat-release ]] || ! grep -qE "(CentOS Linux 7|CentOS.*7\.|CentOS release 7)" /etc/redhat-release 2>/dev/null; then + echo "This script is specifically for CentOS 7. Current system:" + cat /etc/os-release 2>/dev/null || echo "Unknown OS" + echo "Exiting." + exit 0 +fi + +echo "=== Detected CentOS 7 - Fixing repository configuration ===" + +# Function to run command with or without sudo +run_cmd() { + if [[ $EUID -eq 0 ]]; then + "$@" + else + sudo "$@" + fi +} + +# Backup original repository files +echo "Creating backup of original repository files..." +run_cmd cp -r /etc/yum.repos.d /etc/yum.repos.d.backup.$(date +%Y%m%d_%H%M%S) 2>/dev/null || true + +# Fix CentOS 7 repository URLs +echo "Updating repository URLs to use vault.centos.org..." +run_cmd sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*.repo +run_cmd sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*.repo + +# Clean yum cache and update +echo "Cleaning yum cache..." +run_cmd yum clean all + +# Test repository connection +echo "Testing repository connection..." +if ! yum makecache; then + echo "ERROR: Repository connection still failing. Please check network connectivity." + exit 1 +fi + +# Install essential tools +echo "Installing essential tools (git, curl, wget)..." +run_cmd yum install -y git curl wget + +# Verify installation +echo "=== Verification ===" +git --version +curl --version +wget --version + +echo "=== CentOS 7 preparation completed successfully! ===" +echo "" +echo "Next steps:" +echo "1. Clone the repository:" +echo " git clone https://github.com/DongilMin/blueprint-examples.git" +echo "2. Navigate to the Python environment:" +echo " cd blueprint-examples/python-development-environment" +echo "3. Run the Python installation:" +echo " bash scripts/install-python.sh" + diff --git a/python-development-environment/scripts/setup-dev-tools-nosudo.sh b/python-development-environment/scripts/setup-dev-tools-nosudo.sh new file mode 100755 index 00000000..18ea8629 --- /dev/null +++ b/python-development-environment/scripts/setup-dev-tools-nosudo.sh @@ -0,0 +1,142 @@ +#!/bin/bash +set -e + +echo "=== Python Development Environment Setup ===" + +# Check and install build tools +echo "=== Checking and Installing Build Tools ===" +if ! command -v gcc &> /dev/null; then + echo "GCC not found. Installing build tools..." + if command -v yum &> /dev/null; then + # CentOS/RHEL + echo "Installing Development Tools with yum..." + yum groupinstall -y "Development Tools" || echo "Development tools installation attempted" + yum install -y gcc gcc-c++ make python3-devel || echo "GCC installation attempted" + elif command -v apt-get &> /dev/null; then + # Ubuntu/Debian + echo "Installing build-essential with apt..." + apt-get update + apt-get install -y build-essential python3-dev + fi + + # Verify installation + if command -v gcc &> /dev/null; then + echo "✅ GCC successfully installed: $(gcc --version | head -1)" + else + echo "❌ GCC installation failed (continuing without compiler)" + fi +else + echo "✅ Build tools already available: $(gcc --version | head -1)" +fi + +# Create virtual environment +echo "=== Creating Virtual Environment ===" +python3 -m venv /etc/cloudify/python-dev-env || echo "Virtual environment might already exist" +source /etc/cloudify/python-dev-env/bin/activate + +# Install basic packages +echo "=== Installing Basic Packages ===" +pip install --upgrade pip setuptools wheel + +# Install development tools +echo "=== Installing Development Tools ===" +pip install pytest black flake8 ipython requests + +# Install scientific computing packages +echo "=== Installing Scientific Computing Packages ===" + +# Install NumPy (prefer binary wheels) +echo "Installing NumPy..." +pip install --only-binary=numpy numpy || { + echo "Latest numpy failed, trying stable version..." + pip install --only-binary=numpy "numpy==1.24.4" || { + echo "Binary wheel failed, allowing compilation..." + pip install numpy || echo "NumPy installation completely failed" + } +} + +# Install Pandas with dependencies +echo "Installing Pandas with dependencies..." +pip install --only-binary=all python-dateutil pytz tzdata || echo "Some dependencies failed" +pip install --only-binary=pandas pandas || { + echo "Pandas binary installation failed, installing dependencies first..." + pip install python-dateutil pytz tzdata + pip install pandas || echo "Pandas installation failed" +} + +# Create workspace directories +echo "=== Creating Development Workspace ===" +mkdir -p /etc/cloudify/python-workspace/{projects,scripts,data,tests} + +# Create configuration files +echo "=== Creating Configuration Files ===" +echo "alias activate-python='source /etc/cloudify/python-dev-env/bin/activate'" >> ~/.bashrc + +# Create example Python script +cat > /etc/cloudify/python-workspace/example.py << 'EOF' +#!/usr/bin/env python3 +""" +Example Python script demonstrating the development environment. +""" + +import numpy as np +import pandas as pd +import requests + +def main(): + print("🐍 Python Development Environment Test") + print("=" * 50) + + # Test NumPy + print(f"✅ NumPy {np.__version__} - Array: {np.array([1, 2, 3])}") + + # Test Pandas + df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) + print(f"✅ Pandas {pd.__version__} - DataFrame shape: {df.shape}") + + # Test requests + print(f"✅ Requests {requests.__version__} - HTTP library ready") + + print("🎉 All packages working correctly!") + +if __name__ == "__main__": + main() +EOF + +chmod +x /etc/cloudify/python-workspace/example.py + +# Installation verification +echo "=== Installation Verification ===" +echo "Checking installed packages..." + +if python -c "import numpy" 2>/dev/null; then + numpy_version=$(python -c "import numpy; print(numpy.__version__)") + echo "✅ NumPy $numpy_version installed successfully" +else + echo "❌ NumPy not available" +fi + +if python -c "import pandas" 2>/dev/null; then + pandas_version=$(python -c "import pandas; print(pandas.__version__)") + echo "✅ Pandas $pandas_version installed successfully" +else + echo "❌ Pandas not available" +fi + +if python -c "import requests" 2>/dev/null; then + requests_version=$(python -c "import requests; print(requests.__version__)") + echo "✅ Requests $requests_version installed successfully" +else + echo "❌ Requests not available" +fi + +# Summary +echo "=== Development Environment Setup Completed ===" +echo "Virtual environment: /etc/cloudify/python-dev-env" +echo "Workspace: /etc/cloudify/python-workspace" +echo "Example script: /etc/cloudify/python-workspace/example.py" +echo "" +echo "To activate environment: source /etc/cloudify/python-dev-env/bin/activate" +echo "To test installation: python /etc/cloudify/python-workspace/example.py" +echo "" +echo "🎉 Python development environment ready for use!" diff --git a/python-development-environment/scripts/setup-dev-tools.sh b/python-development-environment/scripts/setup-dev-tools.sh new file mode 100755 index 00000000..3b62074e --- /dev/null +++ b/python-development-environment/scripts/setup-dev-tools.sh @@ -0,0 +1,259 @@ +#!/bin/bash +set -e + +PYTHON_VERSION="${python_version:-3.9}" +WORKSPACE_PATH="${workspace_path:-~/python-workspace}" +DEV_PACKAGES="${dev_packages:-pytest black flake8 ipython requests numpy pandas}" + +echo "=== Setting Up Python Development Environment ===" + +# Create and activate virtual environment +echo "=== Creating Python Virtual Environment ===" +python${PYTHON_VERSION} -m venv ~/python-dev-env +source ~/python-dev-env/bin/activate + +# Upgrade pip +pip install --upgrade pip setuptools wheel + +# Install development packages +echo "=== Installing Python Development Packages ===" +if [[ "$DEV_PACKAGES" == *"["* ]]; then + # Handle YAML list format + PACKAGES=$(echo "$DEV_PACKAGES" | tr -d '[],' | tr -s ' ') +else + PACKAGES="$DEV_PACKAGES" +fi + +for package in $PACKAGES; do + echo "Installing $package..." + if [[ "$package" == "numpy" ]]; then + # Special handling for NumPy (prefer binary wheels) + pip install --only-binary=numpy numpy || pip install numpy || echo "Failed to install numpy" + elif [[ "$package" == "pandas" ]]; then + # Special handling for Pandas (install dependencies first) + pip install python-dateutil pytz tzdata || echo "Some pandas dependencies failed" + pip install --only-binary=pandas pandas || pip install pandas || echo "Failed to install pandas" + else + # Regular package installation + pip install "$package" || echo "Failed to install $package" + fi +done + +# Create workspace directories +echo "=== Creating Development Workspace ===" +mkdir -p "${WORKSPACE_PATH}"/{projects,scripts,data,tests,notebooks} + +# Create useful configuration files +echo "=== Creating Configuration Files ===" + +# Python startup file +cat > ~/.pythonrc << 'PYEOF' +# Python Development Environment Startup +import sys +import os +print(f"🐍 Python {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}") +print(f"📁 Working directory: {os.getcwd()}") +try: + import numpy as np + print(f"🔢 NumPy {np.__version__} available") +except ImportError: + pass +try: + import pandas as pd + print(f"📊 Pandas {pd.__version__} available") +except ImportError: + pass +print("=" * 50) +PYEOF + +# Set PYTHONSTARTUP environment variable +echo 'export PYTHONSTARTUP=~/.pythonrc' >> ~/.bashrc + +# Create useful aliases +cat >> ~/.bashrc << 'ALIASEOF' + +# Python Development Environment Aliases +alias activate-python='source ~/python-dev-env/bin/activate' +alias python-workspace='cd ~/python-workspace' +alias run-tests='python -m pytest' +alias format-code='python -m black .' +alias lint-code='python -m flake8 .' +alias python-env='source ~/python-dev-env/bin/activate && python' + +ALIASEOF + +# Create example project structure +echo "=== Creating Example Project ===" +mkdir -p "${WORKSPACE_PATH}/example-project"/{src,tests,data} + +# Create example Python module +cat > "${WORKSPACE_PATH}/example-project/src/calculator.py" << 'CALCEOF' +""" +Example calculator module for demonstrating the development environment. +""" + +import numpy as np + + +def add(a, b): + """Add two numbers.""" + return a + b + + +def multiply(a, b): + """Multiply two numbers.""" + return a * b + + +def array_operations(arr): + """Demonstrate NumPy operations.""" + arr = np.array(arr) + return { + 'sum': np.sum(arr), + 'mean': np.mean(arr), + 'std': np.std(arr) + } + + +if __name__ == "__main__": + # Example usage + print("Calculator Demo") + print(f"2 + 3 = {add(2, 3)}") + print(f"4 * 5 = {multiply(4, 5)}") + + data = [1, 2, 3, 4, 5] + stats = array_operations(data) + print(f"Array {data} stats: {stats}") +CALCEOF + +# Create example test +cat > "${WORKSPACE_PATH}/example-project/tests/test_calculator.py" << 'TESTEOF' +""" +Tests for the calculator module. +""" + +import sys +import os +sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src')) + +import pytest +from calculator import add, multiply, array_operations + + +def test_add(): + assert add(2, 3) == 5 + assert add(-1, 1) == 0 + + +def test_multiply(): + assert multiply(2, 3) == 6 + assert multiply(-2, 3) == -6 + + +def test_array_operations(): + result = array_operations([1, 2, 3, 4, 5]) + assert result['sum'] == 15 + assert result['mean'] == 3.0 + assert pytest.approx(result['std'], 0.1) == 1.4 +TESTEOF + +# Create project README +cat > "${WORKSPACE_PATH}/example-project/README.md" << 'READMEEOF' +# Example Python Project + +This is an example project created by the Python Development Environment Blueprint. + +## Structure + +``` +example-project/ +├── src/ +│ └── calculator.py # Example module +├── tests/ +│ └── test_calculator.py # Example tests +├── data/ # Data files +└── README.md # This file +``` + +## Usage + +```bash +# Activate the environment +source ~/python-dev-env/bin/activate + +# Run the example +python src/calculator.py + +# Run tests +python -m pytest tests/ + +# Format code +python -m black src/ tests/ + +# Lint code +python -m flake8 src/ tests/ +``` + +## Available Tools + +- **pytest**: Testing framework +- **black**: Code formatter +- **flake8**: Code linter +- **ipython**: Enhanced interactive Python +- **numpy**: Scientific computing +- **pandas**: Data analysis +- **requests**: HTTP library +READMEEOF + +# Create setup script for the workspace +cat > "${WORKSPACE_PATH}/setup-environment.sh" << 'SETUPEOF' +#!/bin/bash +# Quick setup script for the Python development environment + +echo "🐍 Python Development Environment Setup" +echo "======================================" + +# Activate virtual environment +source ~/python-dev-env/bin/activate + +# Display environment info +echo "Python version: $(python --version)" +echo "Virtual environment: $VIRTUAL_ENV" +echo "Workspace: $(pwd)" + +# Check key packages +echo "" +echo "📦 Installed packages:" +python -c " +packages = ['numpy', 'pandas', 'requests', 'pytest', 'black', 'flake8'] +for pkg in packages: + try: + module = __import__(pkg) + version = getattr(module, '__version__', 'unknown') + print(f' ✅ {pkg} {version}') + except ImportError: + print(f' ❌ {pkg} not installed') +" + +echo "" +echo "🚀 Environment ready! Available commands:" +echo " python-workspace # Navigate to workspace" +echo " run-tests # Run pytest" +echo " format-code # Format with black" +echo " lint-code # Lint with flake8" +SETUPEOF + +chmod +x "${WORKSPACE_PATH}/setup-environment.sh" + +echo "=== Development Tools Setup Completed ===" +echo "Virtual environment: ~/python-dev-env" +echo "Workspace: ${WORKSPACE_PATH}" +echo "Example project: ${WORKSPACE_PATH}/example-project" +echo "" +echo "🎉 Python development environment ready!" +echo "" +echo "Next steps:" +echo "1. Activate environment: source ~/python-dev-env/bin/activate" +echo "2. Navigate to workspace: cd ${WORKSPACE_PATH}" +echo "3. Run setup check: bash setup-environment.sh" +echo "4. Try the example: python example-project/src/calculator.py"