From 83d1be97faee539e5d756f444b761d02ce82ca76 Mon Sep 17 00:00:00 2001 From: Sissi Feng <38707787+SissiFeng@users.noreply.github.com> Date: Tue, 17 Sep 2024 06:24:24 -0400 Subject: [PATCH 1/9] update the MD. files --- docs/courses/software-dev/4.0-orientation.md | 85 +++++++ docs/courses/software-dev/4.1-vscode-setup.md | 147 ++++++++++++ .../software-dev/4.2-vscode-debugging.md | 210 ++++++++++++++++ docs/courses/software-dev/4.3-unit-testing.md | 209 ++++++++++++++++ .../software-dev/4.4-automated-docs.md | 226 ++++++++++++++++++ .../4.5-continuous-integration.md | 221 +++++++++++++++++ .../software-dev/4.6-project-templates.md | 219 +++++++++++++++++ .../courses/software-dev/4.7-cloud-servers.md | 187 +++++++++++++++ .../software-dev/4.8-cloud-computing.md | 221 +++++++++++++++++ 9 files changed, 1725 insertions(+) create mode 100644 docs/courses/software-dev/4.1-vscode-setup.md create mode 100644 docs/courses/software-dev/4.2-vscode-debugging.md create mode 100644 docs/courses/software-dev/4.3-unit-testing.md create mode 100644 docs/courses/software-dev/4.4-automated-docs.md create mode 100644 docs/courses/software-dev/4.5-continuous-integration.md create mode 100644 docs/courses/software-dev/4.6-project-templates.md create mode 100644 docs/courses/software-dev/4.7-cloud-servers.md create mode 100644 docs/courses/software-dev/4.8-cloud-computing.md diff --git a/docs/courses/software-dev/4.0-orientation.md b/docs/courses/software-dev/4.0-orientation.md index 95f9d94..07d3753 100644 --- a/docs/courses/software-dev/4.0-orientation.md +++ b/docs/courses/software-dev/4.0-orientation.md @@ -4,3 +4,88 @@ ```{contents} :depth: 3 ``` + +## 🔰 Getting Started + +First, open up the following quiz in Canvas that corresponds to your enrolled term. + +::::{tab-set} +:sync-group: category + +:::{tab-item} Sp/Su 2024 +:sync: w2024 + +[TBD] +::: + +:::{tab-item} Sp/Su 2025 +:sync: sp2024 + +[TBD] +::: + +:::: + +You will record your GitHub username and GitHub Classroom Student Identifier, which will be used later in the course. You can refer back to these quiz answers if you forget. See below for information on these two. + +### GitHub Account + +These courses are integrated with coding exercises via GitHub Classroom, so you will need to [create a GitHub account](https://github.com/join) if you don't already have one. Take note of your GitHub username since you will enter this as a quiz response. + +```{tip} +Two typical naming conventions for GitHub usernames are as follows: +- John H. Smith → `jhsmith` +- Jane M. Doe → `jane-doe` + +If you already have a GitHub account and you have used it infrequently, you may consider [renaming your GitHub account](https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-user-account-settings/changing-your-github-username) to adhere to one of the conventions above. This is completely optional. +``` + +### GitHub Starter Tutorial + +```{warning} +The student identifier that you choose on the next page **will appear only once** (e.g., `quirky-zebra`). Please record this somewhere safe and enter it into the corresponding Canvas quiz, since you will be using this at various points throughout the course. If you forget or lose your student identifier, please send a message to [sterling.baird@utoronto.ca](mailto:sterling.baird@utoronto.ca). +``` + +Click on the 🔗 [GitHub starter tutorial](https://classroom.github.com/a/g78UiC5K), ensure you're logged in to GitHub, link to a student identifier of your choice (write this down), and accept the assignment. See below for a walkthrough of this. + + + + + +```{margin} +There is a pre-populated list of student identifiers, none of which have been claimed! You may choose any of these. +``` + +Use this tutorial to familiarize yourself with git and GitHub terminology, which you will be quizzed on later. + +## 📄 GitHub Classroom Assignment + +Now that you're familiar with basic git and GitHub terminology, we can show you how to use GitHub Classroom for an autograded assignment. + +👉 **Second step**: This time, you will use an interactive development environment (IDE) called "Codespaces", with compute resources provided by the Acceleration Consortium through the GitHub Education program. Similar to the format before, click on the new assignment link 🔗 [Intro to GitHub Classroom](https://classroom.github.com/a/3yCVzX6I), ensure you're logged in to GitHub, accept the assignment, click the "Open in Codespaces" button, and follow the directions in the README.md file. Spinning up a new Codespace may take a minute or two, and a preview of the README.md file will automatically open up after a few seconds. A number of dialogue boxes and messages will appear during the loading process. Ensure that you sign into GitHub; use of Copilot is optional. The URL in your browser should be of the form `https://-.github.dev/` which is autogenerated and distinct from your course ID. For example, your URL might be `https://fuzzy-space-spork-9wggxx444g6h7rxq.github.dev/`. You can try the assignment as many times as you like, and you will self-report your autograded score on the next page. See below for a complete walkthrough of these steps. + + + + + +Additional resources: + +- [How students complete assignments](https://youtu.be/ObaFRGp_Eko?si=JMxjdheVKVc3Zwr8) +- [What is Codespaces?](https://youtu.be/sYJ3CHtT6WM) +- [Student developer pack](https://education.github.com/pack) + +```{tip} +If you're eligible, consider signing up for the [student developer pack](https://education.github.com/pack) so that **you can have free access to GitHub Copilot (and GitHub Copilot Chat)**, among other perks. **GitHub Copilot is also free for teachers**. + +If you're not eligible, you may consider a paid subscription (~$10 USD/month). It's kind of like having a personal coding assistant to bounce ideas off of and have it look at your code. At the same time, it can become a crutch, and there are still times where plain-old Google searches, reading stack overflow posts, and searching through a GitHub repository's issues and documentation is better. The Acceleration Consortium does not benefit from you signing up for GitHub Copilot, and it is not required for the completion of this course. +``` + +## 📄 Python Refresher Assignment + +Optionally, you may try out the [Python refresher assignment](https://classroom.github.com/a/oDMoonRK). This is ungraded. diff --git a/docs/courses/software-dev/4.1-vscode-setup.md b/docs/courses/software-dev/4.1-vscode-setup.md new file mode 100644 index 0000000..c199dd3 --- /dev/null +++ b/docs/courses/software-dev/4.1-vscode-setup.md @@ -0,0 +1,147 @@ + +(4.1-setup-vscode)= +# 🧩 4.1 Setting Up VS Code + +```{contents} +:depth: 3 +``` + +## 🔰 Tutorial + +In this module, you will learn how to set up VS Code and optimize it for Python development using tools like Miniconda, various extensions, and advanced features. + +1. Set up VS Code +2. Install Miniconda for environment management +3. Install key VS Code extensions for Python development +4. Configure SSH for remote development +5. Explore advanced tools such as Black formatter, Pylance, and GitHub Copilot Chat + +### Setting Up VS Code + +First, you will download and install Visual Studio Code (VS Code), a lightweight and powerful editor. Then, you'll learn how to configure it for efficient Python development. + +#### Steps: + +1. Download and install VS Code from the official site: [VS Code Download](https://code.visualstudio.com/). +2. Open VS Code and get familiar with the interface, including the command palette, sidebar, and settings menu. + +**Video Tutorial**: [Getting Started with VS Code](https://www.youtube.com/watch?v=VqCgcpAypFQ) + +### Installing Miniconda + +Miniconda is a lightweight distribution of Conda, an environment and package manager for Python. It allows you to manage multiple isolated environments on your machine. + +#### Steps: + +1. Download Miniconda from the [official site](https://docs.conda.io/en/latest/miniconda.html). +2. Install Miniconda by following the instructions for your operating system. +3. After installation, create a new Python environment: + ```bash + conda create -n myenv python=3.9 + conda activate myenv + ``` + +4. Ensure that VS Code is set up to use this environment for Python development. + +**Video Tutorial**: [How to Install Miniconda](https://www.youtube.com/watch?v=oHHbsMfyNR4&pp=ygUYSG93IHRvIEluc3RhbGwgTWluaWNvbmRh) + +### Installing Essential VS Code Extensions + +Extensions can enhance the functionality of VS Code, especially for Python development. Below are some essential extensions to install: + +- [Python Extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python): Adds Python language support. +- [Pylance](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance): A high-performance language server with type checking and autocompletion. +- [Black Formatter](https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter): Automatically formats your Python code. +- [autoDocstring](https://marketplace.visualstudio.com/items?itemName=njpwerner.autodocstring): Generates docstrings for your Python functions and methods. +- [GitHub Copilot](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot): An AI-powered coding assistant. +- [Remote - SSH](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh): For remote development using SSH. + +To install these extensions: +1. Open the **Extensions** view in VS Code (`Ctrl + Shift + X`). +2. Search for each extension by name and click **Install**. + +**Video Tutorial**: [Best VS Code Extensions for Python](https://www.youtube.com/watch?v=fj2tuTIcUys&pp=ygUiQmVzdCBWUyBDb2RlIEV4dGVuc2lvbnMgZm9yIFB5dGhvbg%3D%3D) + +### Using SSH for Remote Development + +VS Code supports remote development, allowing you to write and run code on a remote machine as if it were local. + +#### Steps: + +1. Install the **Remote - SSH** extension from the marketplace. +2. Set up SSH on your local machine by generating SSH keys: + ```bash + ssh-keygen -t rsa -b 4096 + ``` +3. Copy the public key to your remote server: + ```bash + ssh-copy-id username@hostname + ``` +4. Use VS Code's Remote Explorer to connect to the remote server using SSH. + +**Video Tutorial**: [VS Code Remote Development with SSH](https://www.youtube.com/watch?v=miyD4c1dnTU&pp=ygUjVlMgQ29kZSBSZW1vdGUgRGV2ZWxvcG1lbnQgd2l0aCBTU0g%3D) + +### Configuring Black Formatter + +Black is an opinionated Python code formatter that ensures code is formatted consistently. Here’s how to configure it in VS Code: + +1. Open the VS Code **Settings** (`Ctrl + ,`). +2. Search for `Python Formatting Provider` and set it to `Black`. +3. You can also configure VS Code to format your code on save by enabling the "Format on Save" option in settings. + +**Video Tutorial**: [How to Use Black in VS Code](https://www.youtube.com/watch?v=esZLCuWs_2Y) + +### GitHub Copilot Chat + +GitHub Copilot can assist you by suggesting code snippets, entire functions, and even refactoring your code. With **GitHub Copilot Chat**, you can interact with Copilot via a chat interface to get suggestions and resolve issues. + +#### Steps: + +1. Install **GitHub Copilot** and **GitHub Copilot Chat** extensions. +2. After installation, sign in to your GitHub account in VS Code. +3. Open the Copilot Chat interface and ask for help with coding, debugging, or writing functions. + +**Video Tutorial**: [GitHub Copilot Chat](https://www.youtube.com/watch?v=a2DDYMEPwbE&pp=ygUTR2l0SHViIENvcGlsb3QgQ2hhdA%3D%3D) + +### Additional Resources + +- [VS Code Documentation](https://code.visualstudio.com/docs) +- [Conda Environments Guide](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html) +- [Setting up VS Code for Python](https://code.visualstudio.com/docs/python/python-tutorial) +- [Black Formatter Documentation](https://black.readthedocs.io/en/stable/) +- [GitHub Copilot Documentation](https://docs.github.com/en/copilot) + +## 🚀 Quiz + +::::{tab-set} +:sync-group: category + +:::{tab-item} Sp/Su 2024 +:sync: sp2024 + +[URL] +::: + +:::: + +## 📄 Assignment + +1. **Set up VS Code**: + - Download and install VS Code, and create a Python virtual environment using Miniconda. + +2. **Install Extensions**: + - Install the recommended extensions and configure Black as the default formatter. + +3. **SSH Configuration**: + - Set up SSH access to a remote machine and use VS Code to write and run Python code remotely. + +::::{tab-set} +:sync-group: category + +:::{tab-item} Sp/Su 2024 +:sync: sp2024 + +[URL] +::: + +:::: diff --git a/docs/courses/software-dev/4.2-vscode-debugging.md b/docs/courses/software-dev/4.2-vscode-debugging.md new file mode 100644 index 0000000..9860e5c --- /dev/null +++ b/docs/courses/software-dev/4.2-vscode-debugging.md @@ -0,0 +1,210 @@ + +(4.2-debugging-vscode)= +# 🧩 4.2 Debugging in VS Code + +```{contents} +:depth: 3 +``` + +## 🔰 Tutorial + +In this module, you will learn how to debug Python code using VS Code's built-in debugging tools. By the end of this module, you'll be able to: + +1. Use print statements to debug code +2. Set breakpoints to pause code execution at specific lines +3. Inspect variables to check their values during execution +4. Step through code line by line +5. Use the debug console for live interaction with your running code +6. Configure custom debug settings in VS Code + +### Debugging with Print Statements + +The simplest form of debugging is using print statements to display the values of variables at different stages of execution. This method is great for tracking the flow of the program and spotting where things might be going wrong. + +#### Steps: +1. Add `print()` statements throughout your code to output the values of key variables. +2. Run your Python file and check the terminal output for these printed messages. + +#### Example: +```python +def calculate_area(radius): + area = 3.14 * radius ** 2 + print(f"Calculated area: {area}") # Debugging with a print statement + return area + +radius = 5 +print(f"Radius: {radius}") # Print the value of radius +area = calculate_area(radius) +print(f"Final area: {area}") # Print the final calculated area +``` + +**Video Tutorial**: [Debugging Python with Print Statements](https://www.youtube.com/watch?v=GbyXP3_7SBg) + +### Setting Breakpoints + +Breakpoints allow you to pause the execution of your code at specific lines so that you can inspect the state of the program and variables at that moment. Unlike print statements, breakpoints provide more flexibility and control during debugging. + +#### Steps: +1. Open your Python script in VS Code. +2. Click in the margin next to the line number where you want to set a breakpoint. A red dot will appear to indicate the breakpoint. +3. Run the debugger by pressing `F5`, and the code will pause when it hits the breakpoint. + +#### Example: +```python +def calculate_area(radius): + area = 3.14 * radius ** 2 + return area + +radius = 5 +area = calculate_area(radius) # Set a breakpoint on this line +print(f"Area: {area}") +``` + +**Video Tutorial**: [VS Code Breakpoints Tutorial](https://www.youtube.com/watch?v=cZhMgXgKQdI) + +### Inspecting Variables + +Once a breakpoint is hit, you can inspect the values of variables at that specific point in time. This helps in understanding the current state of the program and diagnosing any issues. + +#### Steps: +1. After the code pauses at a breakpoint, hover over any variable in the editor to see its current value. +2. Alternatively, use the **Variables** section in the Debug Sidebar to see the values of all local and global variables. + +#### Example: +```python +def calculate_area(radius): + area = 3.14 * radius ** 2 + return area + +radius = 10 # Inspect the value of radius here +area = calculate_area(radius) +``` + +**Video Tutorial**: [Inspecting Variables in VS Code](https://www.youtube.com/watch?v=qw--VYLpxG4) + +### Stepping Through Code + +Stepping allows you to move through your code line by line, giving you control over the pace of execution. You can "step into" functions, "step over" them, or "step out" of them. + +#### Steps: +1. Once the code hits a breakpoint, use the toolbar buttons to: + - **Step Over** (`F10`): Skip over a function call without entering it. + - **Step Into** (`F11`): Enter into a function to debug it. + - **Step Out** (`Shift + F11`): Exit the current function and return to the caller. + +#### Example: +```python +def multiply(a, b): + return a * b + +def main(): + x = 5 + y = 10 + result = multiply(x, y) # Step into this function + print(f"Result: {result}") + +main() +``` + +**Video Tutorial**: [Stepping Through Code in VS Code](https://www.youtube.com/watch?v=E8dGNupbI4U) + +### Using the Debug Console + +The debug console allows you to interact with your code while it’s paused. You can execute commands, print variable values, or run functions in real-time. + +#### Steps: +1. While the code is paused at a breakpoint, open the **Debug Console** from the bottom panel. +2. In the console, type in variable names to check their values or run Python expressions to see the output. + +#### Example: +```python +def divide(a, b): + return a / b + +x = 50 +y = 0 # Potential division by zero error +result = divide(x, y) # Set a breakpoint here and use the debug console to check variable values +``` + +**Video Tutorial**: [Using the Debug Console in VS Code](https://www.youtube.com/watch?v=-QRyPL5qupU) + +### Debug Configurations + +You can create custom debug configurations in VS Code to define how your program should be debugged. These configurations are defined in a `launch.json` file. + +#### Steps: +1. Open the Command Palette (`Ctrl + Shift + P`) and search for **"Debug: Open launch.json"**. +2. Select the Python environment. +3. Customize the configuration based on your project needs. + +#### Example Configuration (`launch.json`): +```json +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "args": ["--verbose"], # Pass arguments to the program + "env": { # Set environment variables + "DEBUG": "true" + } + } + ] +} +``` + +**Video Tutorial**: [Setting Up Debug Configurations in VS Code](https://www.youtube.com/watch?v=gLNIRwX3oM4) + +### Additional Resources + +- [VS Code Debugging Documentation](https://code.visualstudio.com/docs/editor/debugging) +- [Python Debugging in VS Code](https://code.visualstudio.com/docs/python/debugging) +- [Advanced Debugging in VS Code](https://www.youtube.com/watch?v=2oFKNL7vYV8) + +## 🚀 Quiz + +::::{tab-set} +:sync-group: category + +:::{tab-item} Sp/Su 2024 +:sync: sp2024 + +[URL] +::: + +:::: + +## 📄 Assignment + +1. **Use Print Statements**: + - Modify an existing Python script and add `print()` statements to debug it. Track key variables and their values at different points in the script. + +2. **Set Breakpoints**: + - In VS Code, set breakpoints in your code and run the debugger to pause execution at key lines. + +3. **Inspect Variables**: + - Use the hover feature or Debug Sidebar to inspect variables when the code hits a breakpoint. + +4. **Step Through Code**: + - Use the stepping controls (`F10`, `F11`, `Shift + F11`) to move through your code line by line. + +5. **Debug Console**: + - Use the Debug Console to print variable values and run functions while the debugger is paused. + +6. **Debug Configurations**: + - Create a custom debug configuration in VS Code by editing the `launch.json` file. + +::::{tab-set} +:sync-group: category + +:::{tab-item} Sp/Su 2024 +:sync: sp2024 + +[URL] +::: + +:::: diff --git a/docs/courses/software-dev/4.3-unit-testing.md b/docs/courses/software-dev/4.3-unit-testing.md new file mode 100644 index 0000000..05271ac --- /dev/null +++ b/docs/courses/software-dev/4.3-unit-testing.md @@ -0,0 +1,209 @@ + +(4.3-unit-testing)= +# 🧩 4.3 Unit Testing + +```{contents} +:depth: 3 +``` + +## 🔰 Tutorial + +In this module, you will learn the fundamentals of unit testing in Python using the **pytest** framework. You will also explore test-driven development (TDD) and how it can be applied to real-world projects. + +1. Explain the purpose of unit tests +2. Write unit tests for the light-mixing demo +3. Run and interpret unit tests to fix code +4. Explain test-driven development (TDD) + +### Purpose of Unit Tests + +Unit tests are small, isolated tests that validate the functionality of a specific section (unit) of your code, such as a function or a class. They help ensure that individual components of your program behave as expected, making debugging easier and reducing the chances of introducing bugs when making changes. + +#### Key Benefits: +- Validate the correctness of your code. +- Catch issues early in the development cycle. +- Provide a safety net for refactoring. +- Improve code quality and maintainability. + +**Example:** +```python +def add(a, b): + return a + b +``` + +A unit test for this function would check whether it correctly adds two numbers: +```python +def test_add(): + assert add(2, 3) == 5 +``` + +**Video Tutorial**: [What is Unit Testing?](https://www.youtube.com/watch?v=1Lfv5tUGsn8) + +### Writing Unit Tests with pytest + +**pytest** is a popular Python testing framework that simplifies the process of writing and running tests. It automatically discovers test files and functions, and provides a clean, easy-to-use syntax. + +#### Steps: +1. Install **pytest** using pip: + ```bash + pip install pytest + ``` +2. Create a test file (e.g., `test_light_mixing.py`) and define your unit tests inside it. +3. Use the `assert` statement to check whether the function outputs match the expected results. + +#### Example Unit Test for the Light-Mixing Demo: +```python +# light_mixing.py +def mix_colors(color1, color2): + if color1 == "red" and color2 == "blue": + return "purple" + elif color1 == "blue" and color2 == "yellow": + return "green" + elif color1 == "red" and color2 == "yellow": + return "orange" + else: + return "unknown" + +# test_light_mixing.py +def test_mix_colors(): + assert mix_colors("red", "blue") == "purple" + assert mix_colors("blue", "yellow") == "green" + assert mix_colors("red", "yellow") == "orange" +``` + +#### Running Tests: +1. Navigate to the folder containing your test file. +2. Run pytest from the command line: + ```bash + pytest + ``` + +pytest will automatically discover all files starting with `test_` and execute the tests. + +**Video Tutorial**: [Introduction to pytest](https://www.youtube.com/watch?v=Kt6QqGoAlvI&ab_channel=teclado) + +### Interpreting Test Results + +When you run pytest, it will display the results of your tests in the terminal. Here's how to interpret the output: + +- **Green (PASSED)**: The test passed successfully. +- **Red (FAILED)**: The test failed. pytest will show you the expected result and the actual result so you can identify the issue. +- **Yellow (SKIPPED)**: The test was skipped (typically because of a specific condition, such as platform dependency). + +#### Example Output: +```bash +============================= test session starts ============================== +collected 3 items + +test_light_mixing.py ... [100%] + +============================== 3 passed in 0.03s =============================== +``` + +If a test fails, pytest will provide a detailed report: +```bash +def test_mix_colors(): +> assert mix_colors("blue", "yellow") == "purple" +E AssertionError: assert 'green' == 'purple' + +test_light_mixing.py:5: AssertionError +``` + +In this case, you can see that the test expected "purple" but received "green," indicating an issue with the `mix_colors()` function. + +**Video Tutorial**: [Understanding pytest Output](https://www.youtube.com/watch?v=dN-pVt7i4Us&ab_channel=anthonywritescode) + +### Debugging with pytest + +When a test fails, you can use pytest's built-in debugging capabilities to help identify the issue. The `--pdb` flag can be used to drop into the Python debugger when a test fails, allowing you to inspect variables and step through the code. + +#### Steps: +1. Run pytest with the `--pdb` flag: + ```bash + pytest --pdb + ``` +2. When a test fails, pytest will drop into an interactive debugging session where you can inspect variables and explore the state of your program. + +#### Example: +```bash +(Pdb) print(color1) +'blue' +(Pdb) print(color2) +'yellow' +``` + +**Video Tutorial**: [Debugging with pytest](https://www.youtube.com/watch?v=by9ZU7h1cgk&ab_channel=SuperEngineer) + +### Test-Driven Development (TDD) + +**Test-driven development (TDD)** is a software development approach where you write tests before writing the actual code. This ensures that the code you write is directly influenced by the tests, leading to a more robust and bug-free implementation. + +#### TDD Workflow: +1. **Write a Test**: Begin by writing a test for the new functionality you want to implement. +2. **Run the Test**: Since the functionality doesn't exist yet, the test will fail. +3. **Write Code**: Write just enough code to make the test pass. +4. **Run the Tests Again**: Ensure all tests pass. If any tests fail, fix the code until they pass. +5. **Refactor**: Clean up the code while ensuring that the tests continue to pass. + +#### Example of TDD for Light Mixing: +1. **Write the Test**: + ```python + def test_mix_colors(): + assert mix_colors("red", "blue") == "purple" + ``` +2. **Run the Test**: It will fail because the `mix_colors()` function doesn’t exist yet. +3. **Write the Function**: + ```python + def mix_colors(color1, color2): + if color1 == "red" and color2 == "blue": + return "purple" + return "unknown" + ``` +4. **Run the Test Again**: The test should now pass. +5. **Refactor the Code**: Improve the `mix_colors()` function while ensuring the test still passes. + +**Video Tutorial**: [Test-Driven Development with pytest](https://www.youtube.com/watch?v=uEFrE6cgVNY) + +### Additional Resources + +- [pytest Documentation](https://docs.pytest.org/en/6.2.x/) +- [Unit Testing in Python](https://realpython.com/python-testing/) +- [Test-Driven Development Explained](https://martinfowler.com/bliki/TestDrivenDevelopment.html) + +## 🚀 Quiz + +::::{tab-set} +:sync-group: category + +:::{tab-item} Sp/Su 2024 +:sync: sp2024 + +[URL] +::: + +:::: + +## 📄 Assignment + +1. **Write Unit Tests**: + - Write unit tests for the light-mixing demo and ensure that the color combinations return the correct results. + +2. **Run Tests**: + - Use pytest to run the tests and verify the output. Interpret any errors and fix the code accordingly. + +3. **Debugging**: + - Use the pytest `--pdb` flag to debug any failing tests and inspect variables during the debugging session. + +4. **Test-Driven Development**: + - Implement a new feature using the TDD approach. Write the tests first, then write the code to make the tests pass. + +::::{tab-set} +:sync-group: category + +:::{tab-item} Sp/Su 2024 +:sync: sp2024 + +[URL] +::: + +:::: diff --git a/docs/courses/software-dev/4.4-automated-docs.md b/docs/courses/software-dev/4.4-automated-docs.md new file mode 100644 index 0000000..6e986bb --- /dev/null +++ b/docs/courses/software-dev/4.4-automated-docs.md @@ -0,0 +1,226 @@ + +(4.4-automated-documentation)= +# 🧩 4.4 Automated Documentation + +```{contents} +:depth: 3 +``` + +## 🔰 Tutorial + +In this module, you will learn how to automate documentation creation for your Python projects using **Sphinx** and **Readthedocs**. You will also explore writing docstrings, generating documentation in **Markdown**, and understanding the concept of **documentation as code**. + +1. Write documentation in Markdown +2. Explain what "documentation as code" means +3. Write a docstring for a Python function +4. Set up a Readthedocs account and publish a Readthedocs page + +### Writing Documentation in Markdown + +Markdown is a lightweight markup language that uses plain text formatting to create formatted documents. It is widely used for writing documentation because of its simplicity and ease of use. + +#### Why Markdown? +- **Simplicity**: Markdown files are easy to read and write without the need for complex syntax. +- **Compatibility**: Markdown is supported by many platforms (e.g., GitHub, Readthedocs). +- **Efficiency**: Markdown allows you to focus on content without worrying about formatting. + +#### Basic Markdown Syntax: +- **Headings**: Use `#` for headings. +- **Lists**: Use `-` for unordered lists or `1.` for ordered lists. +- **Code blocks**: Enclose code in triple backticks. +- **Links**: Create links with `[Link text](URL)`. + +#### Example Markdown Document: +```markdown +# Project Title + +## Description +This is a brief description of the project. + +## Installation +To install the project, run the following command: +```bash +pip install -r requirements.txt +``` + + +## Usage +Run the following command to start the application: +```bash +python main.py +``` + +[More about Markdown](https://www.markdownguide.org) + + +Video Tutorial: [How to Write Markdown](https://www.youtube.com/watch?v=HUBNt18RFbo) + +### What Documentation as Code Means + +Documentation as code is a practice where documentation is written, version-controlled, and maintained in the same way as code. This approach encourages continuous updates, collaboration, and automation of the documentation process. + +#### Key Points: +- Version Control: Documentation can be versioned along with code in Git. +- Automation: Tools like **Sphinx** and **Readthedocs** can automatically generate documentation from the code. +- Consistency: Since the documentation is written close to the code, it is easier to keep both in sync. + +By treating documentation like code, it becomes part of the development workflow, allowing it to evolve as the project grows. + +Video Tutorial: [Documentation as Code Explained](https://www.youtube.com/watch?v=XU5xt1kBuyI&pp=ygUfRG9jdW1lbnRhdGlvbiBhcyBDb2RlIEV4cGxhaW5lZA%3D%3D) + +### Writing Python Docstrings + +Docstrings are comments within Python functions, classes, or modules that describe their behavior. Tools like **Sphinx** can extract these docstrings and generate API documentation from them. + +#### Example of a Function Docstring: +```python +def multiply(a: int, b: int) -> int: + """ + Multiplies two numbers and returns the result. + + Parameters: + a (int): The first number. + b (int): The second number. + + Returns: + int: The result of multiplying a and b. + """ + return a * b +``` + +#### Steps for Writing Good Docstrings: +1. Start with a summary: Begin with a one-line summary of the function. +2. Parameters section: Describe each argument, including its type and purpose. +3. Returns section: Indicate what the function returns, including the type and expected value. + +### More Docstring Examples + +#### Example for a class: +```python +class Calculator: + """ + A simple calculator class that supports addition and subtraction. + """ + + def add(self, a: int, b: int) -> int: + """ + Adds two numbers. + + Parameters: + a (int): The first number. + b (int): The second number. + + Returns: + int: The sum of the two numbers. + """ + return a + b +``` + +Video Tutorial: [Writing Python Docstrings](https://www.youtube.com/watch?v=QZhANCk5OXc&pp=ygUZV3JpdGluZyBQeXRob24gRG9jc3RyaW5ncw%3D%3D) + +### Setting Up Sphinx for Automated Documentation + +Sphinx is a documentation generator that converts reStructuredText or Markdown files into various output formats (HTML, PDF, etc.). It can extract Python docstrings to create clean, organized API documentation. + +#### Steps to Set Up Sphinx: + +1. Install Sphinx: + ```bash + pip install sphinx + ``` +2. Initialize Sphinx Project: + Run `sphinx-quickstart` in your project folder and follow the prompts to set up the basic structure: + ```bash + sphinx-quickstart + ``` + This will generate the necessary configuration files. + +3. Configure Sphinx: + - Modify the `conf.py` file to include the source directory where your Python files are located. + - Example modification: + ```python + import os + import sys + sys.path.insert(0, os.path.abspath('../src')) + ``` + +4. Add Extensions: + To use Markdown files or automate docstring extraction, add extensions in `conf.py`: + ```python + extensions = ['sphinx.ext.autodoc', 'myst_parser'] + ``` + +5. Build the Documentation: + After making changes, run: + ```bash + make html + ``` + This command will generate HTML documentation in the `_build/html/` directory. + + +Video Tutorial: [Sphinx Documentation Setup](https://www.youtube.com/watch?v=BWIrhgCAae0&pp=ygUaU3BoaW54IERvY3VtZW50YXRpb24gU2V0dXA%3D) + +### Publishing Documentation with Readthedocs + +Readthedocs is a popular platform for hosting and automatically building documentation from your repository. It integrates seamlessly with Sphinx and GitHub. + +#### Steps to Set Up and Publish on Readthedocs: +1. Create an Account: Go to [Readthedocs](https://readthedocs.org/) and sign up for an account. +2. Connect Your Repository: After signing in, connect your GitHub repository with Readthedocs. +3. Add a `docs/` folder: + Ensure that your project contains a `docs/` folder with the Sphinx configuration files (`conf.py`, `index.rst` or `index.md`). + +4. Set Up Readthedocs: + - In your Readthedocs dashboard, import the project by selecting your GitHub repository. + - Follow the prompts to configure your build settings (e.g., Python version, Sphinx builder). + +5. Build the Documentation: + - Click "Build" in Readthedocs to generate the documentation. + - Once the build is complete, your documentation will be available at a public URL. + +Video Tutorial: [Host your documentation on ReadTheDocs](https://www.youtube.com/watch?v=PO4Zd-6a6fA&pp=ygULUmVhZHRoZWRvY3M%3D) + +### Additional Resources + +- [Sphinx Documentation](https://www.sphinx-doc.org/en/master/) +- [Readthedocs Documentation](https://docs.readthedocs.io/en/stable/) +- [Markdown Guide](https://www.markdownguide.org/) + +## 🚀 Quiz + +::::{tab-set} +:sync-group: category + +:::{tab-item} Sp/Su 2024 +:sync: sp2024 + +[URL] +::: + +:::: + +## 📄 Assignment + +1. Write Markdown Documentation**: + - Create a `README.md` file for one of your Python projects and include installation, usage, and description sections. + +2. Explain Documentation as Code**: + - Write a short paragraph explaining what "documentation as code" means and why it is important. + +3. Write Docstrings**: + - Write docstrings for all the functions in a Python script of your choice. + +4. Publish on Readthedocs**: + - Set up a Readthedocs account, link it to your GitHub repository, and publish your Sphinx-generated documentation. + +::::{tab-set} +:sync-group: category + +:::{tab-item} Sp/Su 2024 +:sync: sp2024 + +[URL] +::: + +:::: + diff --git a/docs/courses/software-dev/4.5-continuous-integration.md b/docs/courses/software-dev/4.5-continuous-integration.md new file mode 100644 index 0000000..25f4eb6 --- /dev/null +++ b/docs/courses/software-dev/4.5-continuous-integration.md @@ -0,0 +1,221 @@ + +(4.5-continuous-integration)= +# 🧩 4.5 Continuous Integration + +```{contents} +:depth: 3 +``` + +## 🔰 Tutorial + +In this module, you will learn about **Continuous Integration (CI)** and how to use **GitHub Actions** to automate tasks like running unit tests and building documentation. By the end of this module, you'll be able to: + +1. Explain the purpose of continuous integration +2. Set up a GitHub Actions workflow +3. Run unit tests and documentation builds on GitHub Actions + +### What is Continuous Integration? + +Continuous Integration (CI) is a software development practice where code changes are automatically tested and integrated into a shared repository frequently. This practice helps catch issues early, improve code quality, and ensure the integrity of the project. + +#### Purpose of Continuous Integration: +- **Early Detection of Errors**: Running automated tests ensures that new changes don't introduce bugs. +- **Consistent Code Quality**: CI tools run linters and other static analysis tools to enforce code quality standards. +- **Faster Development**: Automating testing and integration allows developers to focus on writing code rather than manually running tests. +- **Team Collaboration**: By frequently integrating code, CI reduces the chances of conflicts when multiple team members are working on the same codebase. + +### Setting Up a GitHub Actions Workflow + +**GitHub Actions** is a powerful CI/CD tool that allows you to automate workflows directly in your GitHub repository. You can use it to run tests, lint code, build documentation, and more every time new code is pushed to the repository. + +#### Steps to Set Up a GitHub Actions Workflow: + +1. **Create a Workflow File**: + In your GitHub repository, create a `.github/workflows/` directory and add a YAML file for your workflow. For example, create a `ci.yml` file. + +2. **Define Workflow**: + In the `ci.yml` file, define the steps to run the CI process. Below is an example of a workflow that runs unit tests and builds documentation. + +```yaml +name: CI Workflow + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.8' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run unit tests + run: | + pytest + + - name: Build documentation + run: | + cd docs + make html +``` + +This workflow will: +- Trigger on `push` or `pull request` events targeting the `main` branch. +- Set up Python 3.8, install dependencies, run unit tests, and build the documentation. + +3. **Push to GitHub**: + Once the workflow file is set up, push the changes to your GitHub repository. GitHub will automatically trigger the workflow. + +### Running Unit Tests and Documentation Builds on GitHub Actions + +The CI process often includes running automated tests and building documentation to ensure that everything works as expected after each code change. + +#### Running Unit Tests on GitHub Actions: +1. **Install Testing Framework**: + Make sure that `pytest` or any other testing framework you are using is included in your `requirements.txt` file. + +2. **Define Test Step**: + In the workflow, include a step to run the tests: + ```yaml + - name: Run unit tests + run: | + pytest + ``` + +#### Building Documentation on GitHub Actions: +1. **Install Sphinx**: + Ensure that `Sphinx` and its dependencies are included in your `requirements.txt` file. + +2. **Add Documentation Build Step**: + In the workflow, add a step to build the documentation: + ```yaml + - name: Build documentation + run: | + cd docs + make html + ``` + +This step will navigate to the `docs` folder and run the `make html` command to generate the HTML documentation. + +### Additional Resources + +- [GitHub Actions Documentation](https://docs.github.com/en/actions) +- [Continuous Integration Overview](https://www.atlassian.com/continuous-delivery/continuous-integration) +- [Pytest Documentation](https://docs.pytest.org/en/stable/) +- [Sphinx Documentation](https://www.sphinx-doc.org/en/master/) + + +## 🚀 Quiz + +::::{tab-set} +:sync-group: category + +:::{tab-item} spring/summer 2024 +:sync: sp2024 + +### 1. Fill in the blanks + +Complete the description of Continuous Integration (CI) by selecting the correct words from the drop-down menu and filling in the blanks. + +Continuous Integration (CI) is a [select 1] practice where developers often integrate code into [select 2]. Each integration is validated through [select 3] to detect [select 4] as early as possible. The main benefits of CI include [select 5] to detect problems, [select 6] to reduce them, [select 7] to improve them, and [select 8] to speed them up. GitHub Actions is a popular [select 9] platform that allows developers to automate [select 10]. Running [select 11] is a critical step in the CI process to ensure code quality. At the same time, integrating [select 12] builds into CI ensures that the documentation stays in sync with the code. + +### Options: + +1. [Software Development, Project Management, Code Review] +2. [Shared Repositories, Local Branches, Production Environments] +3. [Automated Builds, Manual Checking, Code Review] +4. [Integration Bugs, Performance Issues, Security Vulnerabilities] +5. [Early, Delayed, Periodic] +6. [Integration Issues, Development Costs, Team Size] +7. [Code Quality, Development Speed, Team Communication] +8. [Release Cycle, Test Coverage, Code Complexity] +9. [CI/CD, Version Control, Project Management] +10. [Software Development Workflow, Server Configuration, Database Management] +11. [Unit Tests, Test Coverage, Project Management] +12. [Documentation, Databases, User Interfaces] + +### 2. Code Analysis Questions + +Analyze the following GitHub Actions workflow configuration and answer the questions: + +1. What operating system does the workflow use? +2. How can this workflow be improved to include a document deployment step? + +```yaml +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Run tests + run: python -m unittest discover tests + - name: Build documentation + run: | + cd docs + make html + +``` + + +[URL] +::: + +:::: + +## 📄 Assignment + +1. **Explain the Purpose of Continuous Integration**: + - Write a paragraph explaining the purpose of continuous integration and its benefits in software development. + +2. **Set Up GitHub Actions**: + - Create a `ci.yml` file in your GitHub repository and define a workflow that runs unit tests and builds documentation. + +3. **Run Unit Tests**: + - Push changes to your repository and verify that the unit tests are executed correctly via GitHub Actions. + +4. **Build Documentation**: + - Ensure that your documentation is built automatically as part of your CI pipeline using Sphinx. + +::::{tab-set} +:sync-group: category + +:::{tab-item} Sp/Su 2024 +:sync: sp2024 + +[URL] +::: + +:::: diff --git a/docs/courses/software-dev/4.6-project-templates.md b/docs/courses/software-dev/4.6-project-templates.md new file mode 100644 index 0000000..2a1b436 --- /dev/null +++ b/docs/courses/software-dev/4.6-project-templates.md @@ -0,0 +1,219 @@ + +(4.6-project-templates)= +# 🧩 4.6 Project Templates + +```{contents} +:depth: 3 +``` + +## 🔰 Tutorial + +In this module, you will learn how to use **PyScaffold** and **Cookiecutter** to create project templates, manage dependencies, and publish Python packages to **PyPI**. By the end of this module, you'll be able to: + +1. Create a project template using PyScaffold +2. Add project content and initialize a Python project +3. Publish a Python package to PyPI +4. Outline the key benefits of dependency management during software development + +### Project Templates with PyScaffold + +**PyScaffold** is a tool that helps create the scaffolding for Python projects by generating a clean project structure, setting up version control, documentation, and package configuration. This simplifies the process of initializing new Python projects. + +#### Steps to Create a Project Template with PyScaffold: + +1. Install PyScaffold: + ```bash + pip install --upgrade pyscaffold + ``` + +2. Create a New Project: + Run the following command to initialize a new project: + ```bash + putup my_project + ``` + + This will create a project folder called `my_project` template with everything you need for some serious coding with the following structure: + ``` + my_project/ + ├── src/ + ├── tests/ + ├── docs/ + ├── setup.py + └── README.rst + ``` + +3. Add Features: + PyScaffold allows you to add features like testing frameworks (e.g., `pytest`) or documentation tools (e.g., `Sphinx`) directly during initialization: + ```bash + putup --with-pytest --with-sphinx my_project + ``` + + This command adds both `pytest` and `Sphinx` configurations to the project. + +Quick Start: [PyScaffold Demo Project](https://github.com/pyscaffold/pyscaffold-demo) + +### Project Templates with Cookiecutter + +Cookiecutter is another powerful tool for creating project templates, but it is more customizable than PyScaffold. Cookiecutter allows you to define templates that can be reused across different projects. + +#### Steps to Create a Project Template with Cookiecutter: + +1. Install Cookiecutter: + ```bash + pip install cookiecutter + ``` + +2. Use an Existing Template: + You can initialize a new project from an existing template by running: + ```bash + cookiecutter https://github.com/audreyr/cookiecutter-pypackage + ``` + + Follow the prompts to customize the project (e.g., project name, author, license, etc.). + +3. Create Your Own Template: + You can also create your own project template. For example, create a folder structure like: + ``` + my_template/ + ├── {{cookiecutter.project_name}}/ + │ └── __init__.py + └── cookiecutter.json + ``` + + The `cookiecutter.json` file defines the variables for your template, such as: + ```json + { + "project_name": "MyProject", + "author_name": "Your Name" + } + ``` + + You can use this template across different projects by running: + ```bash + cookiecutter path/to/my_template + ``` + +Video Tutorial: [Using Cookiecutter for Python Projects](https://www.youtube.com/watch?v=KpGAEsysxpY) + +### Adding Project Content and Initialization + +After setting up a project template using PyScaffold or Cookiecutter, the next step is to add your own code, documentation, and tests. The structure generated by these tools encourages best practices for organizing code and keeping everything modular and maintainable. + +#### Example of Adding Content: + +1. Source Code**: Add your Python code under the `src/` directory. + ```bash + src/my_project/ + __init__.py + module.py + ``` + +2. Tests**: Place your unit tests under the `tests/` directory. + ```bash + tests/ + test_module.py + ``` + +3. Documentation**: Sphinx setup will generate documentation files in the `docs/` directory. + +4. Version Control: Use Git for version control. The template already includes a `.gitignore` file to exclude unnecessary files from your repository. + +### Publishing a Python Package to PyPI + +PyPI (Python Package Index) is a repository where you can publish your Python packages so they can be easily installed by others using `pip`. Here's how to package and publish your project to PyPI: + +#### Steps to Publish a Package to PyPI: + +1. Install Build Tools: + First, install the required tools for packaging: + ```bash + pip install setuptools wheel twine + ``` + +2. Build Your Package: + Inside your project directory, run the following command to create a distribution package: + ```bash + python setup.py sdist bdist_wheel + ``` + + This will generate a `dist/` directory containing `.tar.gz` and `.whl` files. + +3. Upload to PyPI: + Create an account on PyPI if you don’t already have one. Then, use `twine` to upload the package: + ```bash + twine upload dist/* + ``` + + Your package is now published on PyPI and can be installed using: + ```bash + pip install your-package-name + ``` + +Video Tutorial: [How to Publish a Package on PyPI](https://www.youtube.com/watch?v=GIF3LaRqgXo) + +### Dependency Management in Python + +Dependency management ensures that your project has all the necessary external libraries installed, and that these dependencies are consistent across different environments. Proper dependency management is essential for the smooth development and deployment of software projects. + +#### Key Benefits of Dependency Management: + +1. Consistency: Ensures that everyone working on the project is using the same versions of dependencies. +2. Isolation: Dependencies are isolated in virtual environments (e.g., `venv`, `conda`), preventing conflicts with other projects. +3. Reproducibility: With a `requirements.txt` or `pyproject.toml`, anyone can recreate the exact environment needed to run the project. +4. Security: Dependency management tools can automatically check for outdated or vulnerable libraries, helping keep your project secure. + +#### Tools for Managing Dependencies: +- `requirements.txt`: Lists all the dependencies of the project, which can be installed using: + ```bash + pip install -r requirements.txt + ``` + +- `pyproject.toml`: A modern way to manage dependencies and build system requirements, supported by tools like **Poetry**. + +Video Tutorial: [Dependency Management in Python](https://www.youtube.com/watch?v=fKl2JW_qrso) + +### Additional Resources + +- [PyScaffold Documentation](https://pyscaffold.org/en/stable/) +- [Cookiecutter Documentation](https://cookiecutter.readthedocs.io/en/1.7.2/) +- [Publishing Python Packages to PyPI](https://packaging.python.org/tutorials/packaging-projects/) +- [Dependency Management with Poetry](https://python-poetry.org/) + +## 🚀 Quiz + +::::{tab-set} +:sync-group: category + +:::{tab-item} Sp/Su 2024 +:sync: sp2024 + +[URL] +::: + +:::: + +## 📄 Assignment + +1. **Create a Project Template**: + - Use PyScaffold or Cookiecutter to create a new Python project template. + +2. **Add Project Content**: + - Add source code, documentation, and tests to your initialized project. + +3. **Publish a Python Package to PyPI**: + - Follow the steps to package your project and publish it to PyPI. + +4. **Explain Dependency Management**: + - Write a short paragraph outlining the benefits of dependency management during software development. + +::::{tab-set} +:sync-group: category + +:::{tab-item} Sp/Su 2024 +:sync: sp2024 + +[URL] +::: + +:::: + diff --git a/docs/courses/software-dev/4.7-cloud-servers.md b/docs/courses/software-dev/4.7-cloud-servers.md new file mode 100644 index 0000000..570772d --- /dev/null +++ b/docs/courses/software-dev/4.7-cloud-servers.md @@ -0,0 +1,187 @@ + +(4.7-launching-free-cloud-server)= +# 🧩 4.7 Launching a Free Cloud Server + +```{contents} +:depth: 3 +``` + +## 🔰 Tutorial + +In this module, you will learn how to launch a free cloud server, leverage **serverless computing**, and deploy applications using **PythonAnywhere** and **Hugging Face**. By the end of this module, you'll be able to: + +1. Launch a free cloud server +2. Use a container to deploy applications +3. Create a container for your app +4. Deploy a materials discovery campaign on a cloud server + +### Launching a Free Cloud Server + +A cloud server is a virtual server that you can access over the internet. Many cloud platforms offer free tiers for users to launch servers, allowing you to run and deploy your applications in the cloud without incurring costs. + +#### Free Cloud Server Providers: +1. **PythonAnywhere**: A Python-centric cloud platform that offers a free plan with enough resources for small-scale applications. +2. **Google Cloud Platform (GCP)**: Provides free credits and the option to launch a small virtual machine for free. +3. **AWS Free Tier**: Offers free EC2 instances for the first 12 months. +4. **Hugging Face Spaces**: Provides a free option to deploy machine learning models and web applications using the Gradio or Streamlit framework. + +#### Steps to Launch a Free Cloud Server on PythonAnywhere: + +1. **Sign up for PythonAnywhere**: + Go to [PythonAnywhere](https://www.pythonanywhere.com) and create a free account. + +2. **Start a New Console**: + Once logged in, go to the **Consoles** tab and start a new **Bash** console. + +3. **Set Up Your Application**: + You can set up your Python environment and install necessary packages: + ```bash + pip install -r requirements.txt + ``` + +4. **Deploy Your Application**: + You can deploy web apps or Python scripts directly by using the **Web** tab to set up a web application or schedule your scripts to run. + +**Video Tutorial**: [PythonAnywhere Overview](https://www.youtube.com/watch?v=yhqYFyo7dAM&pp=ygUOUHl0aG9uQW55d2hlcmU%3D) + +### Serverless Computing + +**Serverless computing** allows you to run your code without having to manage the underlying infrastructure. You only pay for the compute resources when your code is executed, making it ideal for small-scale or on-demand applications. + +#### Benefits of Serverless Computing: +1. **Cost Efficiency**: You are only billed for actual compute time, rather than for server uptime. +2. **Scalability**: Serverless platforms can automatically scale your application based on demand. +3. **Ease of Use**: You don't need to manage or configure the server, allowing you to focus on application development. + +#### Popular Serverless Platforms: + +1. **AWS Lambda**: Executes your code in response to events (such as HTTP requests or file uploads) without requiring you to provision or manage servers. AWS Lambda automatically scales your application by running code in response to each trigger, making it highly reliable and cost-effective for event-driven workloads. + +2. **Google Cloud Functions**: A lightweight, event-driven serverless compute platform similar to AWS Lambda. It's great for tasks like executing code in response to HTTP requests, Cloud Storage events, or Pub/Sub messages. It’s well integrated with other Google Cloud services and offers seamless scalability. + +3. **Azure Functions**: Microsoft's serverless platform that also supports event-driven execution, with deep integration into the Azure ecosystem. It supports a wide range of triggers (e.g., HTTP requests, queue messages) and can be used to execute code in response to changes in Azure Storage or Cosmos DB, making it ideal for cloud-native applications running on Azure. + +4. **Hugging Face Spaces**: A serverless platform specifically designed for deploying machine learning models and web applications. Hugging Face Spaces supports frameworks like Gradio and Streamlit, which makes it easy to deploy and share ML-powered applications with others. + +### Using Containers + +**Containers** provide a consistent environment for your applications, making it easier to deploy them across different systems, including cloud servers. A container includes everything your application needs to run, such as libraries, dependencies, and configuration files. + +To better understand what a container does, think of it as a **pizza box**. Just as a pizza box holds and protects a pizza, allowing it to be transported anywhere while keeping the pizza intact, a container holds your application and its environment, ensuring that the app can run anywhere without changes—whether on your local machine, a colleague’s system, or a cloud server. + +#### Steps to Use a Container: +1. **Install Docker**: + Docker is the most widely used container platform. Install Docker on your local machine: + ```bash + sudo apt-get update + sudo apt-get install docker-ce docker-ce-cli containerd.io + ``` + +2. **Create a Dockerfile**: + A Dockerfile is a text file that contains instructions for building a Docker image. Here’s an example Dockerfile for a Python Flask app: + ```dockerfile + # Use an official Python runtime as a parent image + FROM python:3.8-slim + + # Set the working directory + WORKDIR /app + + # Copy the current directory contents into the container at /app + COPY . /app + + # Install any needed packages specified in requirements.txt + RUN pip install --no-cache-dir -r requirements.txt + + # Make port 5000 available to the world outside this container + EXPOSE 5000 + + # Run app.py when the container launches + CMD ["python", "app.py"] + ``` + +3. **Build the Docker Image**: + Run the following command to build your Docker image: + ```bash + docker build -t my_flask_app . + ``` + +4. **Run the Container**: + After building the image, you can run the container: + ```bash + docker run -p 5000:5000 my_flask_app + ``` + +**Video Tutorial**: [Getting Started with Docker](https://www.youtube.com/watch?v=fqMOX6JJhGo) + +### Creating a Container + +Containers are useful for creating reproducible environments that work on any cloud platform or local machine. You can define all dependencies and settings in a container, ensuring that your application will run smoothly, regardless of the environment. + +#### Steps to Create a Container for Your App: + +1. **Create a Dockerfile**: + Create a `Dockerfile` in your project directory that includes the necessary instructions for your application (see the Dockerfile example above). + +2. **Build the Image**: + Use the `docker build` command to build your image from the Dockerfile. + +3. **Test Locally**: + Before deploying your container to the cloud, run it locally to ensure that everything works as expected. + +**Video Tutorial**: [Build Your Own Container](https://www.youtube.com/watch?v=SnSH8Ht3MIc&ab_channel=TechnoTim) + +### Deploying a Materials Discovery Campaign on a Cloud Server + +In this example, we will deploy a simplified **materials discovery campaign** where the goal is to analyze a dataset of material properties (e.g., conductivity, hardness, and thermal resistance) and predict optimal materials for specific applications. We will deploy this application on a cloud server, enabling users to submit data and receive predictions from a trained machine learning model hosted in the cloud. + +#### Steps to Deploy a Materials Discovery Campaign: + +1. **Dataset Preparation**: + The campaign starts by loading a dataset of materials with their respective properties. The dataset could be a CSV file containing columns like `Material Name`, `Conductivity`, `Hardness`, and `Thermal Resistance`. + +2. **Model Training**: + Train a machine learning model (e.g., a Random Forest or Neural Network) that can predict the best material for a given set of conditions (e.g., optimal material for high conductivity and low thermal resistance). Save the trained model as a `.pkl` file. + +3. **Create a Flask Application**: + Develop a Python Flask application that will serve as the front-end for the campaign. Users can submit material properties through a web form, and the model will return a prediction of the best material. + ```python + from flask import Flask, request, jsonify + import pickle + + app = Flask(__name__) + + # Load the trained model + with open('model.pkl', 'rb') as f: + model = pickle.load(f) + + @app.route('/predict', methods=['POST']) + def predict(): + data = request.json + prediction = model.predict([data['properties']]) + return jsonify({'predicted_material': prediction[0]}) + + if __name__ == '__main__': + app.run(debug=True) + ``` + +4. **Containerize the Application**: + Use Docker to containerize the Flask application (refer to the Dockerfile example above). + +5. **Deploy the Application**: + Deploy the containerized application on PythonAnywhere or Hugging Face Spaces. Ensure the web interface is accessible and that users can submit data and receive predictions in real-time. + +**Video Tutorial**: [Flask Deploy to Huggingface Cloud](https://youtu.be/pWnE9FHnGcQ) + +### Additional Resources + +- [PythonAnywhere Documentation](https://help.pythonanywhere.com/pages/) +- [Hugging Face Spaces Documentation](https://huggingface.co/docs) +- [Docker Documentation](https://docs.docker.com/) +- [Serverless Framework Documentation](https://www.serverless.com/framework/docs/) + +## 🚀 Quiz + +::::{tab-set} +:sync-group: category + +:::{tab \ No newline at end of file diff --git a/docs/courses/software-dev/4.8-cloud-computing.md b/docs/courses/software-dev/4.8-cloud-computing.md new file mode 100644 index 0000000..ca18d79 --- /dev/null +++ b/docs/courses/software-dev/4.8-cloud-computing.md @@ -0,0 +1,221 @@ + +(4.8-on-demand-cloud-simulations)= +# 🧩 4.8 On-demand Cloud Simulations + +```{contents} +:depth: 3 +``` + +## 🔰 Tutorial + +In this module, you will learn how to set up an AWS account and use cloud computing services like **AWS Lambda**, **Docker containers**, **Apptainer**, and **Prefect** to run **on-demand cloud simulations**. You will also explore how to integrate these simulations into a materials discovery campaign. + +1. Set up an AWS account +2. Use AWS Lambda for serverless cloud computing +3. Run Docker containers and Apptainer for cloud simulations +4. Automate workflows with Prefect +5. Integrate cloud simulations into a materials discovery campaign + +### Setting Up an AWS Account + +**AWS (Amazon Web Services)** is a popular cloud computing platform that provides a wide range of cloud services, including compute, storage, and databases. To run on-demand simulations, you’ll first need to set up an AWS account. + +#### Steps to Set Up an AWS Account: + +1. **Sign up for AWS**: + - Visit [AWS Signup](https://aws.amazon.com/free) and create an account. You’ll need to provide billing information, but AWS offers a free tier that includes limited usage for services like **AWS Lambda** and **EC2**. + +2. **Create an IAM User**: + - After signing up, create an **IAM User** for secure access to your AWS resources. + - Go to **IAM Management Console** → **Users** → **Add User**, and assign the necessary permissions (e.g., for Lambda, S3, and EC2). + +3. **Set Up AWS CLI**: + - To manage AWS services from your terminal, install and configure the **AWS CLI**: + ```bash + pip install awscli + aws configure + ``` + Enter your **Access Key ID** and **Secret Access Key** from the IAM user you created. + +**Video Tutorial**: [How to Set Up an AWS Free Tier](https://www.youtube.com/watch?v=SFaSB6vgp8k&pp=ygUVYXdzIGZyZWUgdGllciBzaWduIHVw) + +### AWS Lambda: Serverless Cloud Computing + +**AWS Lambda** is a serverless compute service that lets you run code in response to events without provisioning or managing servers. It’s ideal for running simulations on-demand based on user requests or data changes. + +#### Running Cloud Simulations with AWS Lambda: + +1. **Create a Lambda Function**: + - Go to **Lambda Console** → **Create Function**, choose **Author from scratch**, and select **Python** as the runtime. + +2. **Write Simulation Code**: + - Write the code for your simulation in Python. Here's a simple example that simulates material property calculations: + ```python + import json + + def lambda_handler(event, context): + # Simulate material property calculations + material_data = event['material_properties'] + conductivity = material_data['conductivity'] * 0.9 # Example calculation + hardness = material_data['hardness'] * 1.1 + + return { + 'statusCode': 200, + 'body': json.dumps({ + 'optimized_conductivity': conductivity, + 'optimized_hardness': hardness + }) + } + ``` + +3. **Deploy the Function**: + - Once your code is ready, deploy the Lambda function and trigger it using an **API Gateway**, **S3 events**, or **manual invocation**. + +**Video Tutorial**: [AWS Lambda Tutorial for Beginners](https://www.youtube.com/watch?v=eOBq__h4OJ4) + +### Docker Containers for Cloud Simulations + +Docker containers help package your simulations with all necessary dependencies, making it easy to run them on any cloud server. This allows for reproducible and scalable simulations. + +#### Steps to Run Cloud Simulations in Docker: + +1. **Create a Dockerfile**: + Define a Dockerfile for your simulation environment: + ```dockerfile + FROM python:3.8-slim + + WORKDIR /simulation + + COPY . /simulation + + RUN pip install -r requirements.txt + + CMD ["python", "run_simulation.py"] + ``` + +2. **Build the Docker Image**: + ```bash + docker build -t material_simulation . + ``` + +3. **Run the Simulation Locally**: + ```bash + docker run -d material_simulation + ``` + +4. **Deploy the Docker Container on AWS**: + You can deploy your Docker container on **AWS Fargate** or **EC2** for on-demand simulations. Fargate is a serverless compute engine for containers, while EC2 provides virtual machines. + +**Video Tutorial**: [Docker on AWS EC2](https://www.youtube.com/watch?v=qNIniDftAcU&pp=ygURRG9ja2VyIG9uIEFXUyBFQzI%3D) + +### Apptainer for Scientific Simulations + +**Apptainer** (formerly **Singularity**) is a container platform tailored for high-performance computing (HPC) and scientific simulations. It’s commonly used in research environments where Docker cannot be used due to security constraints. + +#### Steps to Run Simulations with Apptainer: + +1. **Install Apptainer**: + Install Apptainer on your system by following the instructions from the [official documentation](https://apptainer.org/docs/admin/main/installation.html). + +2. **Create an Apptainer Container**: + Similar to Docker, Apptainer uses definition files (`.def`) to define container environments. Here’s an example: + ```def + Bootstrap: docker + From: python:3.8-slim + + %post + pip install numpy scipy + + %runscript + exec python run_simulation.py + ``` + +3. **Build and Run the Container**: + ```bash + apptainer build material_simulation.sif material_simulation.def + apptainer run material_simulation.sif + ``` + +**Video Tutorial**: [Apptainer/Singularity Tutorial](https://www.youtube.com/watch?v=g0cCErlveiI&list=PLKZ9c4ONm-VkxWW98Gcn9H6WwykMiqtnF) + +### Workflow Automation with Prefect + +**Prefect** is a modern workflow orchestration tool that helps automate complex workflows, like running multiple cloud simulations or orchestrating data pipelines. You can use Prefect to trigger cloud simulations, handle retries, and manage dependencies. + +#### Steps to Automate Cloud Simulations with Prefect: + +1. **Install Prefect**: + ```bash + pip install -U prefect + ``` + +2. **Define a Prefect Flow**: + A **Prefect flow** defines the sequence of tasks to run. Here’s an example of running a cloud simulation as part of a workflow: + ```python + from prefect import task, Flow + + @task + def run_simulation(): + print("Running cloud simulation...") + # Simulate material discovery task here + return "Simulation Completed" + + with Flow("material_discovery") as flow: + run_simulation() + + flow.run() + ``` + +3. **Run the Flow**: + Run the flow locally or deploy it on **Prefect Cloud** for distributed execution. + +**Video Tutorial**: [Getting Started with Prefect](https://www.youtube.com/watch?v=4yIW34WcmBQ&pp=ygUcR2V0dGluZyBTdGFydGVkIHdpdGggUHJlZmVjdA%3D%3D) + +### Integrating Cloud Simulations into a Materials Discovery Campaign + +In a materials discovery campaign, you might need to perform large-scale simulations to identify the best materials for specific properties. By integrating cloud simulations, you can scale your computational efforts and automate the discovery process. + +#### Example: Integrating a Simulation into a Campaign + +1. **Use Case**: + Imagine you are searching for materials with optimal thermal conductivity and hardness. You have a dataset of potential materials, and you want to run simulations to find the top candidates. + +2. **Simulation Setup**: + - Load the material properties from a database (e.g., AWS S3). + - Run the simulation using AWS Lambda or Docker containers on EC2/Fargate. + - Use the simulation to calculate optimized properties (e.g., using machine learning models trained on historical material data). + +3. **Automate the Process**: + - Use **Prefect** to automate the workflow, including triggering simulations based on incoming data, aggregating the results, and storing them in a database. + - Each simulation run generates predictions for a subset of materials, and the best candidates are selected for further analysis. + + + +### Additional Resources + +- [AWS Lambda Documentation](https://docs.aws.amazon.com/lambda/) +- [Docker Documentation](https://docs.docker.com/) +- [Apptainer Documentation](https://apptainer.org/) +- [Prefect Documentation](https://docs.prefect.io/) +- [EC2 User Guide](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html) + +## 🚀 Quiz + +::::{tab-set} +:sync-group: category + +:::{tab-item} Sp/Su 2024 +:sync: sp2024 + +### 1. Multiple Choice: AWS Lambda + +Which of the following are true about AWS Lambda? (Select all that apply) + +- [x] It automatically scales with incoming requests. +- [x] You only pay for the compute time used. +- [ ] It requires you to manage the underlying server infrastructure. +- [ ] It supports long-running tasks exceeding 15 minutes. + +### 2. Code Fill-in: Docker Container + +Fill in the blanks \ No newline at end of file From 33c6d61de307fe1f63f3716f9d66dd1e3fd396dc Mon Sep 17 00:00:00 2001 From: "Sterling G. Baird" Date: Thu, 19 Sep 2024 12:56:13 -0400 Subject: [PATCH 2/9] tutorial files and orientation module --- docs/course-data.yaml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/course-data.yaml b/docs/course-data.yaml index 45cc6a6..f55b879 100644 --- a/docs/course-data.yaml +++ b/docs/course-data.yaml @@ -558,20 +558,36 @@ software-dev: - "Sterling Baird, PhD Materials Science and Engineering (Acceleration Consortium)" module_note: "Each module is intended to take approximately 3-4 hours, assuming that the recommended prerequisites have been met." modules: + - module_name: "4.0 Orientation" + tutorial_file: 4.0-orientation.md + topics: + - "Git" + - "GitHub" + - "Version control" + - "GitHub Classroom" + - "Codespaces" + learning_outcomes: + - "Describe the purpose of Git and GitHub" + - "Create a GitHub account and a repository" + - "Commit, push, and pull changes" + - "Run a unit test and fix a simple Python function" + - "Define continuous integration" - module_name: "Deep dive into Git and GitHub" + tutorial_file: 4.1-github-deep-dive.md topics: - "GitHub issues" - "Pull requests" - "Collaborative coding" - "Branches" - "Merge conflicts" - - "Project management" + # - "Project management" learning_outcomes: - "Open a GitHub issue on a repository" - "Create a new branch" - "Merge a GitHub pull request" - "Resolve a merge conflict" - module_name: "Setting up VS Code" + tutorial_file: 4.2-vscode-setup.md topics: - "IDEs" - "Miniconda" @@ -587,6 +603,7 @@ software-dev: - "Install Miniconda" - "Install VS Code extensions" - module_name: "Debugging in VS Code" + tutorial_file: 4.3-vscode-debugging.md topics: - "Print statements" - "Setting breakpoints" @@ -602,6 +619,7 @@ software-dev: - "Use the debug console" - "Set up debug configurations" - module_name: "Unit testing" + tutorial_file: 4.4-unit-testing.md topics: - "pytest" - "Test result interpretation" @@ -618,6 +636,7 @@ software-dev: # Linting and code formatting? (e.g., black, flake8, isort, etc., especially VS Code Extensions) # VS Code extensions? (e.g., Python, Jupyter, Git, etc.) - module_name: "Automated documentation" + tutorial_file: 4.5-automated-docs.md topics: - "Markdown" - "Documentation as code" @@ -632,6 +651,7 @@ software-dev: tutorial: - "GitHub-flavored Markdown tutorial" - module_name: "Continuous integration (CI)" + tutorial_file: 4.6-continuous-integration.md topics: - "Continuous integration" - "GitHub actions" @@ -642,6 +662,7 @@ software-dev: - "Set up a GitHub actions workflow" - "Run unit tests and documentation builds on GitHub actions" - module_name: "Project templates" + tutorial_file: 4.7-project-templates.md topics: - "PyScaffold" - "Cookiecutter" @@ -656,6 +677,7 @@ software-dev: - "Publish a Python package to PyPI" - "Outline the key benefits of dependency management during software development" - module_name: "Launching a free cloud server" + tutorial_file: 4.8-cloud-server.md topics: - "Serverless computing" - "PythonAnywhere" @@ -667,6 +689,7 @@ software-dev: - "Create a container" - "Deploy a materials discovery campaign on a cloud server" - module_name: "On-demand cloud simulations" + tutorial_file: 4.9-cloud-simulations.md topics: - "Cloud computing" - "Setting up an AWS account" From a01b497f513cbccbe5d980961069178bb40eeef6 Mon Sep 17 00:00:00 2001 From: "Sterling G. Baird" Date: Thu, 19 Sep 2024 12:56:29 -0400 Subject: [PATCH 3/9] del placeholder ipynb files --- .../software-dev/4.1-vscode-setup.ipynb | 39 ------------------- .../software-dev/4.2-vscode-debugging.ipynb | 39 ------------------- .../software-dev/4.3-unit-testing.ipynb | 39 ------------------- .../software-dev/4.4-automated-docs.ipynb | 39 ------------------- .../4.5-continuous-integration.ipynb | 39 ------------------- .../software-dev/4.6-project-templates.ipynb | 39 ------------------- .../software-dev/4.7-cloud-servers.ipynb | 39 ------------------- .../software-dev/4.8-cloud-computing.ipynb | 39 ------------------- 8 files changed, 312 deletions(-) delete mode 100644 docs/courses/software-dev/4.1-vscode-setup.ipynb delete mode 100644 docs/courses/software-dev/4.2-vscode-debugging.ipynb delete mode 100644 docs/courses/software-dev/4.3-unit-testing.ipynb delete mode 100644 docs/courses/software-dev/4.4-automated-docs.ipynb delete mode 100644 docs/courses/software-dev/4.5-continuous-integration.ipynb delete mode 100644 docs/courses/software-dev/4.6-project-templates.ipynb delete mode 100644 docs/courses/software-dev/4.7-cloud-servers.ipynb delete mode 100644 docs/courses/software-dev/4.8-cloud-computing.ipynb diff --git a/docs/courses/software-dev/4.1-vscode-setup.ipynb b/docs/courses/software-dev/4.1-vscode-setup.ipynb deleted file mode 100644 index d0b691e..0000000 --- a/docs/courses/software-dev/4.1-vscode-setup.ipynb +++ /dev/null @@ -1,39 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 1. VS Code Setup" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "ac-microcourses", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/courses/software-dev/4.2-vscode-debugging.ipynb b/docs/courses/software-dev/4.2-vscode-debugging.ipynb deleted file mode 100644 index f4da235..0000000 --- a/docs/courses/software-dev/4.2-vscode-debugging.ipynb +++ /dev/null @@ -1,39 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 2. VS Code Debugging" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "ac-microcourses", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/courses/software-dev/4.3-unit-testing.ipynb b/docs/courses/software-dev/4.3-unit-testing.ipynb deleted file mode 100644 index 787eccc..0000000 --- a/docs/courses/software-dev/4.3-unit-testing.ipynb +++ /dev/null @@ -1,39 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 3. Unit Testing" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "ac-microcourses", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/courses/software-dev/4.4-automated-docs.ipynb b/docs/courses/software-dev/4.4-automated-docs.ipynb deleted file mode 100644 index d52d3f5..0000000 --- a/docs/courses/software-dev/4.4-automated-docs.ipynb +++ /dev/null @@ -1,39 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 4. Automated Documentation" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "ac-microcourses", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/courses/software-dev/4.5-continuous-integration.ipynb b/docs/courses/software-dev/4.5-continuous-integration.ipynb deleted file mode 100644 index a0e5222..0000000 --- a/docs/courses/software-dev/4.5-continuous-integration.ipynb +++ /dev/null @@ -1,39 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 5. Continuous Integration" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "ac-microcourses", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/courses/software-dev/4.6-project-templates.ipynb b/docs/courses/software-dev/4.6-project-templates.ipynb deleted file mode 100644 index 4b0aa5f..0000000 --- a/docs/courses/software-dev/4.6-project-templates.ipynb +++ /dev/null @@ -1,39 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 6. Project Templates" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "ac-microcourses", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/courses/software-dev/4.7-cloud-servers.ipynb b/docs/courses/software-dev/4.7-cloud-servers.ipynb deleted file mode 100644 index 8e34450..0000000 --- a/docs/courses/software-dev/4.7-cloud-servers.ipynb +++ /dev/null @@ -1,39 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 7. Cloud Servers" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "ac-microcourses", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/courses/software-dev/4.8-cloud-computing.ipynb b/docs/courses/software-dev/4.8-cloud-computing.ipynb deleted file mode 100644 index 97ef371..0000000 --- a/docs/courses/software-dev/4.8-cloud-computing.ipynb +++ /dev/null @@ -1,39 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 8. Cloud Computing" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "ac-microcourses", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} From ce87dd73278547725ee4c82e73d43cb2c504d591 Mon Sep 17 00:00:00 2001 From: "Sterling G. Baird" Date: Thu, 19 Sep 2024 13:27:55 -0400 Subject: [PATCH 4/9] add github deep dive placeholder, formatting changes (mostly spacing/tabbing) --- .../software-dev/4.1-github-deep-dive.md | 0 .../software-dev/4.2-vscode-debugging.md | 46 +++++++++++-------- .../software-dev/4.6-project-templates.md | 15 +++++- .../courses/software-dev/4.7-cloud-servers.md | 23 ++++++---- .../software-dev/4.8-cloud-computing.md | 32 +++++++++---- docs/courses/software-dev/index.md | 19 ++++---- docs/courses/software-dev/overview.md | 13 +++++- 7 files changed, 101 insertions(+), 47 deletions(-) create mode 100644 docs/courses/software-dev/4.1-github-deep-dive.md diff --git a/docs/courses/software-dev/4.1-github-deep-dive.md b/docs/courses/software-dev/4.1-github-deep-dive.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/courses/software-dev/4.2-vscode-debugging.md b/docs/courses/software-dev/4.2-vscode-debugging.md index 9860e5c..3cdc3e3 100644 --- a/docs/courses/software-dev/4.2-vscode-debugging.md +++ b/docs/courses/software-dev/4.2-vscode-debugging.md @@ -28,10 +28,11 @@ The simplest form of debugging is using print statements to display the values o #### Example: ```python def calculate_area(radius): - area = 3.14 * radius ** 2 + area = 3.14 * radius**2 print(f"Calculated area: {area}") # Debugging with a print statement return area + radius = 5 print(f"Radius: {radius}") # Print the value of radius area = calculate_area(radius) @@ -52,9 +53,10 @@ Breakpoints allow you to pause the execution of your code at specific lines so t #### Example: ```python def calculate_area(radius): - area = 3.14 * radius ** 2 + area = 3.14 * radius**2 return area + radius = 5 area = calculate_area(radius) # Set a breakpoint on this line print(f"Area: {area}") @@ -73,9 +75,10 @@ Once a breakpoint is hit, you can inspect the values of variables at that specif #### Example: ```python def calculate_area(radius): - area = 3.14 * radius ** 2 + area = 3.14 * radius**2 return area + radius = 10 # Inspect the value of radius here area = calculate_area(radius) ``` @@ -97,12 +100,14 @@ Stepping allows you to move through your code line by line, giving you control o def multiply(a, b): return a * b + def main(): x = 5 y = 10 result = multiply(x, y) # Step into this function print(f"Result: {result}") + main() ``` @@ -121,9 +126,12 @@ The debug console allows you to interact with your code while it’s paused. You def divide(a, b): return a / b + x = 50 y = 0 # Potential division by zero error -result = divide(x, y) # Set a breakpoint here and use the debug console to check variable values +result = divide( + x, y +) # Set a breakpoint here and use the debug console to check variable values ``` **Video Tutorial**: [Using the Debug Console in VS Code](https://www.youtube.com/watch?v=-QRyPL5qupU) @@ -138,25 +146,27 @@ You can create custom debug configurations in VS Code to define how your program 3. Customize the configuration based on your project needs. #### Example Configuration (`launch.json`): + ```json { - "version": "0.2.0", - "configurations": [ - { - "name": "Python: Current File", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal", - "args": ["--verbose"], # Pass arguments to the program - "env": { # Set environment variables - "DEBUG": "true" - } - } - ] + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "args": ["--verbose"], + "env": {"DEBUG": "true"}, + } + ], } ``` + + + **Video Tutorial**: [Setting Up Debug Configurations in VS Code](https://www.youtube.com/watch?v=gLNIRwX3oM4) ### Additional Resources diff --git a/docs/courses/software-dev/4.6-project-templates.md b/docs/courses/software-dev/4.6-project-templates.md index 2a1b436..e7360ec 100644 --- a/docs/courses/software-dev/4.6-project-templates.md +++ b/docs/courses/software-dev/4.6-project-templates.md @@ -22,17 +22,20 @@ In this module, you will learn how to use **PyScaffold** and **Cookiecutter** to #### Steps to Create a Project Template with PyScaffold: 1. Install PyScaffold: + ```bash pip install --upgrade pyscaffold ``` 2. Create a New Project: Run the following command to initialize a new project: + ```bash putup my_project ``` This will create a project folder called `my_project` template with everything you need for some serious coding with the following structure: + ``` my_project/ ├── src/ @@ -44,6 +47,7 @@ In this module, you will learn how to use **PyScaffold** and **Cookiecutter** to 3. Add Features: PyScaffold allows you to add features like testing frameworks (e.g., `pytest`) or documentation tools (e.g., `Sphinx`) directly during initialization: + ```bash putup --with-pytest --with-sphinx my_project ``` @@ -59,12 +63,14 @@ Cookiecutter is another powerful tool for creating project templates, but it is #### Steps to Create a Project Template with Cookiecutter: 1. Install Cookiecutter: + ```bash pip install cookiecutter ``` 2. Use an Existing Template: You can initialize a new project from an existing template by running: + ```bash cookiecutter https://github.com/audreyr/cookiecutter-pypackage ``` @@ -73,6 +79,7 @@ Cookiecutter is another powerful tool for creating project templates, but it is 3. Create Your Own Template: You can also create your own project template. For example, create a folder structure like: + ``` my_template/ ├── {{cookiecutter.project_name}}/ @@ -81,6 +88,7 @@ Cookiecutter is another powerful tool for creating project templates, but it is ``` The `cookiecutter.json` file defines the variables for your template, such as: + ```json { "project_name": "MyProject", @@ -102,6 +110,7 @@ After setting up a project template using PyScaffold or Cookiecutter, the next s #### Example of Adding Content: 1. Source Code**: Add your Python code under the `src/` directory. + ```bash src/my_project/ __init__.py @@ -109,6 +118,7 @@ After setting up a project template using PyScaffold or Cookiecutter, the next s ``` 2. Tests**: Place your unit tests under the `tests/` directory. + ```bash tests/ test_module.py @@ -126,12 +136,14 @@ PyPI (Python Package Index) is a repository where you can publish your Python pa 1. Install Build Tools: First, install the required tools for packaging: + ```bash pip install setuptools wheel twine ``` 2. Build Your Package: Inside your project directory, run the following command to create a distribution package: + ```bash python setup.py sdist bdist_wheel ``` @@ -140,11 +152,13 @@ PyPI (Python Package Index) is a repository where you can publish your Python pa 3. Upload to PyPI: Create an account on PyPI if you don’t already have one. Then, use `twine` to upload the package: + ```bash twine upload dist/* ``` Your package is now published on PyPI and can be installed using: + ```bash pip install your-package-name ``` @@ -216,4 +230,3 @@ Video Tutorial: [Dependency Management in Python](https://www.youtube.com/watch? ::: :::: - diff --git a/docs/courses/software-dev/4.7-cloud-servers.md b/docs/courses/software-dev/4.7-cloud-servers.md index 570772d..31934f8 100644 --- a/docs/courses/software-dev/4.7-cloud-servers.md +++ b/docs/courses/software-dev/4.7-cloud-servers.md @@ -56,7 +56,7 @@ A cloud server is a virtual server that you can access over the internet. Many c #### Popular Serverless Platforms: 1. **AWS Lambda**: Executes your code in response to events (such as HTTP requests or file uploads) without requiring you to provision or manage servers. AWS Lambda automatically scales your application by running code in response to each trigger, making it highly reliable and cost-effective for event-driven workloads. - + 2. **Google Cloud Functions**: A lightweight, event-driven serverless compute platform similar to AWS Lambda. It's great for tasks like executing code in response to HTTP requests, Cloud Storage events, or Pub/Sub messages. It’s well integrated with other Google Cloud services and offers seamless scalability. 3. **Azure Functions**: Microsoft's serverless platform that also supports event-driven execution, with deep integration into the Azure ecosystem. It supports a wide range of triggers (e.g., HTTP requests, queue messages) and can be used to execute code in response to changes in Azure Storage or Cosmos DB, making it ideal for cloud-native applications running on Azure. @@ -65,13 +65,14 @@ A cloud server is a virtual server that you can access over the internet. Many c ### Using Containers -**Containers** provide a consistent environment for your applications, making it easier to deploy them across different systems, including cloud servers. A container includes everything your application needs to run, such as libraries, dependencies, and configuration files. +**Containers** provide a consistent environment for your applications, making it easier to deploy them across different systems, including cloud servers. A container includes everything your application needs to run, such as libraries, dependencies, and configuration files. To better understand what a container does, think of it as a **pizza box**. Just as a pizza box holds and protects a pizza, allowing it to be transported anywhere while keeping the pizza intact, a container holds your application and its environment, ensuring that the app can run anywhere without changes—whether on your local machine, a colleague’s system, or a cloud server. #### Steps to Use a Container: 1. **Install Docker**: Docker is the most widely used container platform. Install Docker on your local machine: + ```bash sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io @@ -79,6 +80,7 @@ To better understand what a container does, think of it as a **pizza box**. Just 2. **Create a Dockerfile**: A Dockerfile is a text file that contains instructions for building a Docker image. Here’s an example Dockerfile for a Python Flask app: + ```dockerfile # Use an official Python runtime as a parent image FROM python:3.8-slim @@ -101,12 +103,14 @@ To better understand what a container does, think of it as a **pizza box**. Just 3. **Build the Docker Image**: Run the following command to build your Docker image: + ```bash docker build -t my_flask_app . ``` 4. **Run the Container**: After building the image, you can run the container: + ```bash docker run -p 5000:5000 my_flask_app ``` @@ -144,6 +148,7 @@ In this example, we will deploy a simplified **materials discovery campaign** wh 3. **Create a Flask Application**: Develop a Python Flask application that will serve as the front-end for the campaign. Users can submit material properties through a web form, and the model will return a prediction of the best material. + ```python from flask import Flask, request, jsonify import pickle @@ -151,16 +156,18 @@ In this example, we will deploy a simplified **materials discovery campaign** wh app = Flask(__name__) # Load the trained model - with open('model.pkl', 'rb') as f: + with open("model.pkl", "rb") as f: model = pickle.load(f) - @app.route('/predict', methods=['POST']) + + @app.route("/predict", methods=["POST"]) def predict(): data = request.json - prediction = model.predict([data['properties']]) - return jsonify({'predicted_material': prediction[0]}) + prediction = model.predict([data["properties"]]) + return jsonify({"predicted_material": prediction[0]}) + - if __name__ == '__main__': + if __name__ == "__main__": app.run(debug=True) ``` @@ -184,4 +191,4 @@ In this example, we will deploy a simplified **materials discovery campaign** wh ::::{tab-set} :sync-group: category -:::{tab \ No newline at end of file +:::{tab diff --git a/docs/courses/software-dev/4.8-cloud-computing.md b/docs/courses/software-dev/4.8-cloud-computing.md index ca18d79..971c790 100644 --- a/docs/courses/software-dev/4.8-cloud-computing.md +++ b/docs/courses/software-dev/4.8-cloud-computing.md @@ -31,10 +31,12 @@ In this module, you will learn how to set up an AWS account and use cloud comput 3. **Set Up AWS CLI**: - To manage AWS services from your terminal, install and configure the **AWS CLI**: + ```bash pip install awscli aws configure ``` + Enter your **Access Key ID** and **Secret Access Key** from the IAM user you created. **Video Tutorial**: [How to Set Up an AWS Free Tier](https://www.youtube.com/watch?v=SFaSB6vgp8k&pp=ygUVYXdzIGZyZWUgdGllciBzaWduIHVw) @@ -47,24 +49,25 @@ In this module, you will learn how to set up an AWS account and use cloud comput 1. **Create a Lambda Function**: - Go to **Lambda Console** → **Create Function**, choose **Author from scratch**, and select **Python** as the runtime. - + 2. **Write Simulation Code**: - Write the code for your simulation in Python. Here's a simple example that simulates material property calculations: + ```python import json + def lambda_handler(event, context): # Simulate material property calculations - material_data = event['material_properties'] - conductivity = material_data['conductivity'] * 0.9 # Example calculation - hardness = material_data['hardness'] * 1.1 + material_data = event["material_properties"] + conductivity = material_data["conductivity"] * 0.9 # Example calculation + hardness = material_data["hardness"] * 1.1 return { - 'statusCode': 200, - 'body': json.dumps({ - 'optimized_conductivity': conductivity, - 'optimized_hardness': hardness - }) + "statusCode": 200, + "body": json.dumps( + {"optimized_conductivity": conductivity, "optimized_hardness": hardness} + ), } ``` @@ -81,6 +84,7 @@ Docker containers help package your simulations with all necessary dependencies, 1. **Create a Dockerfile**: Define a Dockerfile for your simulation environment: + ```dockerfile FROM python:3.8-slim @@ -94,11 +98,13 @@ Docker containers help package your simulations with all necessary dependencies, ``` 2. **Build the Docker Image**: + ```bash docker build -t material_simulation . ``` 3. **Run the Simulation Locally**: + ```bash docker run -d material_simulation ``` @@ -119,6 +125,7 @@ Docker containers help package your simulations with all necessary dependencies, 2. **Create an Apptainer Container**: Similar to Docker, Apptainer uses definition files (`.def`) to define container environments. Here’s an example: + ```def Bootstrap: docker From: python:3.8-slim @@ -131,6 +138,7 @@ Docker containers help package your simulations with all necessary dependencies, ``` 3. **Build and Run the Container**: + ```bash apptainer build material_simulation.sif material_simulation.def apptainer run material_simulation.sif @@ -145,21 +153,25 @@ Docker containers help package your simulations with all necessary dependencies, #### Steps to Automate Cloud Simulations with Prefect: 1. **Install Prefect**: + ```bash pip install -U prefect ``` 2. **Define a Prefect Flow**: A **Prefect flow** defines the sequence of tasks to run. Here’s an example of running a cloud simulation as part of a workflow: + ```python from prefect import task, Flow + @task def run_simulation(): print("Running cloud simulation...") # Simulate material discovery task here return "Simulation Completed" + with Flow("material_discovery") as flow: run_simulation() @@ -218,4 +230,4 @@ Which of the following are true about AWS Lambda? (Select all that apply) ### 2. Code Fill-in: Docker Container -Fill in the blanks \ No newline at end of file +Fill in the blanks diff --git a/docs/courses/software-dev/index.md b/docs/courses/software-dev/index.md index b366bd7..06686fa 100644 --- a/docs/courses/software-dev/index.md +++ b/docs/courses/software-dev/index.md @@ -54,15 +54,16 @@ Waitlist {octicon}`link-external;1em` 🗺️ Overview 🎓 Waitlist -🧩 Deep dive into Git and GitHub <> -🧩 Setting up VS Code <> -🧩 Debugging in VS Code <> -🧩 Unit testing <> -🧩 Automated documentation <> -🧩 Continuous integration (CI) <> -🧩 Project templates <> -🧩 Launching a free cloud server <> -🧩 On-demand cloud simulations <> +🧩 4.0 Orientation <4.0-orientation.md> +🧩 Deep dive into Git and GitHub <4.1-github-deep-dive.md> +🧩 Setting up VS Code <4.2-vscode-setup.md> +🧩 Debugging in VS Code <4.3-vscode-debugging.md> +🧩 Unit testing <4.4-unit-testing.md> +🧩 Automated documentation <4.5-automated-docs.md> +🧩 Continuous integration (CI) <4.6-continuous-integration.md> +🧩 Project templates <4.7-project-templates.md> +🧩 Launching a free cloud server <4.8-cloud-server.md> +🧩 On-demand cloud simulations <4.9-cloud-simulations.md> ``` diff --git a/docs/courses/software-dev/overview.md b/docs/courses/software-dev/overview.md index 6122f73..80556d5 100644 --- a/docs/courses/software-dev/overview.md +++ b/docs/courses/software-dev/overview.md @@ -71,13 +71,24 @@ Each module is intended to take approximately 3-4 hours, assuming that the recom - Topics - Learning Outcomes +* - 4.0 Orientation + - * Git + * GitHub + * Version control + * GitHub Classroom + * Codespaces + - * Describe the purpose of Git and GitHub + * Create a GitHub account and a repository + * Commit, push, and pull changes + * Run a unit test and fix a simple Python function + * Define continuous integration + * - Deep dive into Git and GitHub - * GitHub issues * Pull requests * Collaborative coding * Branches * Merge conflicts - * Project management - * Open a GitHub issue on a repository * Create a new branch * Merge a GitHub pull request From 454d8b3d5e3dcfd0f20ee0fa53fd423e1901a6e0 Mon Sep 17 00:00:00 2001 From: "Sterling G. Baird" Date: Thu, 26 Sep 2024 09:59:13 -0400 Subject: [PATCH 5/9] add Sissi as developer --- docs/course-data.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/course-data.yaml b/docs/course-data.yaml index f55b879..0962966 100644 --- a/docs/course-data.yaml +++ b/docs/course-data.yaml @@ -556,6 +556,7 @@ software-dev: course_assessments_and_grading_schema: "{{ courses.hello-world.course_assessments_and_grading_schema }}" developers: - "Sterling Baird, PhD Materials Science and Engineering (Acceleration Consortium)" + - "Sissi Feng, PhD Electrical and Computer Engineering (Acceleration Consortium)" module_note: "Each module is intended to take approximately 3-4 hours, assuming that the recommended prerequisites have been met." modules: - module_name: "4.0 Orientation" From 0f66917cf186ff50720a0fdbda9c64c14b56c3fe Mon Sep 17 00:00:00 2001 From: "Sterling G. Baird" Date: Fri, 4 Oct 2024 11:35:12 -0400 Subject: [PATCH 6/9] sissi as coauthor and fix for sphinx 8.0 incompatibility --- docs/courses/software-dev/overview.md | 2 ++ docs/requirements.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/docs/courses/software-dev/overview.md b/docs/courses/software-dev/overview.md index 80556d5..18f22ef 100644 --- a/docs/courses/software-dev/overview.md +++ b/docs/courses/software-dev/overview.md @@ -196,3 +196,5 @@ Each module is intended to take approximately 3-4 hours, assuming that the recom - Sterling Baird, PhD Materials Science and Engineering (Acceleration Consortium) + +- Sissi Feng, PhD Electrical and Computer Engineering (Acceleration Consortium) diff --git a/docs/requirements.txt b/docs/requirements.txt index a43ff78..c97e15b 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -21,3 +21,5 @@ sphinx-gallery # sphinx_rtd_theme sphinx_book_theme sphinx_copybutton +sphinxcontrib-applehelp>=2 +sphinxcontrib-htmlhelp>=2.1 From 0bb92862007085db3942f882273a37a9fbcc2fa7 Mon Sep 17 00:00:00 2001 From: "Sterling G. Baird" Date: Fri, 4 Oct 2024 11:35:58 -0400 Subject: [PATCH 7/9] precommit --- docs/courses/software-dev/4.1-vscode-setup.md | 2 +- docs/courses/software-dev/4.3-unit-testing.md | 1 + .../software-dev/4.4-automated-docs.md | 12 ++++---- .../4.5-continuous-integration.md | 30 +++++++++---------- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/docs/courses/software-dev/4.1-vscode-setup.md b/docs/courses/software-dev/4.1-vscode-setup.md index c199dd3..83dd015 100644 --- a/docs/courses/software-dev/4.1-vscode-setup.md +++ b/docs/courses/software-dev/4.1-vscode-setup.md @@ -8,7 +8,7 @@ ## 🔰 Tutorial -In this module, you will learn how to set up VS Code and optimize it for Python development using tools like Miniconda, various extensions, and advanced features. +In this module, you will learn how to set up VS Code and optimize it for Python development using tools like Miniconda, various extensions, and advanced features. 1. Set up VS Code 2. Install Miniconda for environment management diff --git a/docs/courses/software-dev/4.3-unit-testing.md b/docs/courses/software-dev/4.3-unit-testing.md index 05271ac..5d72c44 100644 --- a/docs/courses/software-dev/4.3-unit-testing.md +++ b/docs/courses/software-dev/4.3-unit-testing.md @@ -64,6 +64,7 @@ def mix_colors(color1, color2): else: return "unknown" + # test_light_mixing.py def test_mix_colors(): assert mix_colors("red", "blue") == "purple" diff --git a/docs/courses/software-dev/4.4-automated-docs.md b/docs/courses/software-dev/4.4-automated-docs.md index 6e986bb..55c65ae 100644 --- a/docs/courses/software-dev/4.4-automated-docs.md +++ b/docs/courses/software-dev/4.4-automated-docs.md @@ -17,7 +17,7 @@ In this module, you will learn how to automate documentation creation for your P ### Writing Documentation in Markdown -Markdown is a lightweight markup language that uses plain text formatting to create formatted documents. It is widely used for writing documentation because of its simplicity and ease of use. +Markdown is a lightweight markup language that uses plain text formatting to create formatted documents. It is widely used for writing documentation because of its simplicity and ease of use. #### Why Markdown? - **Simplicity**: Markdown files are easy to read and write without the need for complex syntax. @@ -141,13 +141,14 @@ Sphinx is a documentation generator that converts reStructuredText or Markdown f ```python import os import sys - sys.path.insert(0, os.path.abspath('../src')) + + sys.path.insert(0, os.path.abspath("../src")) ``` 4. Add Extensions: To use Markdown files or automate docstring extraction, add extensions in `conf.py`: ```python - extensions = ['sphinx.ext.autodoc', 'myst_parser'] + extensions = ["sphinx.ext.autodoc", "myst_parser"] ``` 5. Build the Documentation: @@ -169,11 +170,11 @@ Readthedocs is a popular platform for hosting and automatically building documen 2. Connect Your Repository: After signing in, connect your GitHub repository with Readthedocs. 3. Add a `docs/` folder: Ensure that your project contains a `docs/` folder with the Sphinx configuration files (`conf.py`, `index.rst` or `index.md`). - + 4. Set Up Readthedocs: - In your Readthedocs dashboard, import the project by selecting your GitHub repository. - Follow the prompts to configure your build settings (e.g., Python version, Sphinx builder). - + 5. Build the Documentation: - Click "Build" in Readthedocs to generate the documentation. - Once the build is complete, your documentation will be available at a public URL. @@ -223,4 +224,3 @@ Video Tutorial: [Host your documentation on ReadTheDocs](https://www.youtube.com ::: :::: - diff --git a/docs/courses/software-dev/4.5-continuous-integration.md b/docs/courses/software-dev/4.5-continuous-integration.md index 25f4eb6..7893640 100644 --- a/docs/courses/software-dev/4.5-continuous-integration.md +++ b/docs/courses/software-dev/4.5-continuous-integration.md @@ -89,7 +89,7 @@ The CI process often includes running automated tests and building documentation #### Running Unit Tests on GitHub Actions: 1. **Install Testing Framework**: Make sure that `pytest` or any other testing framework you are using is included in your `requirements.txt` file. - + 2. **Define Test Step**: In the workflow, include a step to run the tests: ```yaml @@ -101,7 +101,7 @@ The CI process often includes running automated tests and building documentation #### Building Documentation on GitHub Actions: 1. **Install Sphinx**: Ensure that `Sphinx` and its dependencies are included in your `requirements.txt` file. - + 2. **Add Documentation Build Step**: In the workflow, add a step to build the documentation: ```yaml @@ -137,24 +137,24 @@ Continuous Integration (CI) is a [select 1] practice where developers often inte ### Options: -1. [Software Development, Project Management, Code Review] -2. [Shared Repositories, Local Branches, Production Environments] -3. [Automated Builds, Manual Checking, Code Review] -4. [Integration Bugs, Performance Issues, Security Vulnerabilities] -5. [Early, Delayed, Periodic] -6. [Integration Issues, Development Costs, Team Size] -7. [Code Quality, Development Speed, Team Communication] -8. [Release Cycle, Test Coverage, Code Complexity] -9. [CI/CD, Version Control, Project Management] -10. [Software Development Workflow, Server Configuration, Database Management] -11. [Unit Tests, Test Coverage, Project Management] +1. [Software Development, Project Management, Code Review] +2. [Shared Repositories, Local Branches, Production Environments] +3. [Automated Builds, Manual Checking, Code Review] +4. [Integration Bugs, Performance Issues, Security Vulnerabilities] +5. [Early, Delayed, Periodic] +6. [Integration Issues, Development Costs, Team Size] +7. [Code Quality, Development Speed, Team Communication] +8. [Release Cycle, Test Coverage, Code Complexity] +9. [CI/CD, Version Control, Project Management] +10. [Software Development Workflow, Server Configuration, Database Management] +11. [Unit Tests, Test Coverage, Project Management] 12. [Documentation, Databases, User Interfaces] ### 2. Code Analysis Questions Analyze the following GitHub Actions workflow configuration and answer the questions: -1. What operating system does the workflow use? +1. What operating system does the workflow use? 2. How can this workflow be improved to include a document deployment step? ```yaml @@ -169,7 +169,7 @@ on: jobs: build: runs-on: ubuntu-latest - + steps: - uses: actions/checkout@v2 - name: Set up Python From ca6115a76a01990fb625b1d775b3538394969eb2 Mon Sep 17 00:00:00 2001 From: "Sterling G. Baird" Date: Fri, 4 Oct 2024 11:56:24 -0400 Subject: [PATCH 8/9] Update 4.1-vscode-setup.md --- docs/courses/software-dev/4.1-vscode-setup.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/courses/software-dev/4.1-vscode-setup.md b/docs/courses/software-dev/4.1-vscode-setup.md index 83dd015..166de8f 100644 --- a/docs/courses/software-dev/4.1-vscode-setup.md +++ b/docs/courses/software-dev/4.1-vscode-setup.md @@ -54,6 +54,7 @@ Extensions can enhance the functionality of VS Code, especially for Python devel - [Black Formatter](https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter): Automatically formats your Python code. - [autoDocstring](https://marketplace.visualstudio.com/items?itemName=njpwerner.autodocstring): Generates docstrings for your Python functions and methods. - [GitHub Copilot](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot): An AI-powered coding assistant. +- [GitHub Copilot Chat](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot-chat): AI chat features powered by Copilot. - [Remote - SSH](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh): For remote development using SSH. To install these extensions: From 7f769e099add835bbc93d9e0eb522306831624c7 Mon Sep 17 00:00:00 2001 From: "Sterling G. Baird" Date: Fri, 4 Oct 2024 12:00:44 -0400 Subject: [PATCH 9/9] Update 4.1-vscode-setup.md add note about mamba --- docs/courses/software-dev/4.1-vscode-setup.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/courses/software-dev/4.1-vscode-setup.md b/docs/courses/software-dev/4.1-vscode-setup.md index 166de8f..0ba458b 100644 --- a/docs/courses/software-dev/4.1-vscode-setup.md +++ b/docs/courses/software-dev/4.1-vscode-setup.md @@ -31,6 +31,10 @@ First, you will download and install Visual Studio Code (VS Code), a lightweight Miniconda is a lightweight distribution of Conda, an environment and package manager for Python. It allows you to manage multiple isolated environments on your machine. +```{note} +Consider using [Mamba](https://github.com/mamba-org/mamba), a widely used, fast (written in C++), drop-in replacement for conda. +``` + #### Steps: 1. Download Miniconda from the [official site](https://docs.conda.io/en/latest/miniconda.html).