Skip to content

4. Contribution Example

Maike Rodrigo edited this page Feb 15, 2022 · 3 revisions

Example

If you already forked, cloned, and installed the requirements you can try the example below. The objective here is to create your Branch and Pull Request with a simple script as you will do when you start contributing to this project.

Before starting your new contributions don't forget to get the latest version of this repository.

First, you need to add this repository as a remote:

    git remote add upstream https://github.com/Schots/mlops_project.git

Type git remote -V on the terminal, you will see the URLs from the origin (which is your fork), and the upstream (which is this).

Now you can get the latest version of this repo by typing:

    git pull upstream <branch>

Now, let's go!

  1. Create a branch called new_branch

If you want to help create new functionalities or change anything inside this project, you will do the changes on your branch and at the end of the process request your changes to be merged into main.

    git checkout -b new_branch          # switch to the new_branch
  1. Create a Python script.py

This script simulates how to start the process, first, you will create some code, like a script to clean data, or perform transformations.

    sudo nano script.py                 # to save type 'CRTL+X -> Yes or y -> Enter'
  1. Write the following program.

Ignore the subject of this script, is just for teaching purposes.

script.py :

    from passlib.context import CryptContext

    pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")

    hashed_password = pwd_context.hash("my_password")

    print(hashed_password)
  1. Make the script readable, writable, and executable by giving permissions.

This step is just in case you're following this tutorial in the terminal, and to avoid problems. (Git hooks will try to read and edit this file, you don't grand the permissions, may your get some errors).

    sudo chmod +777 script.py           # add permission to the file
  1. Put dependencies on the right files.

As the script needs on passlib library, edit the requirements. in file and include this dependency.

requirements.in :

    passlib
  1. Reinstall all dependencies of the project, which will also install the new dependencies that you have included in the requirements files.
    make requirements
  1. Test your script
    python3 script.py

If everything works fine you will see something like this output, a hashed password

    $2b$12$B.Xs4nChoe87oXAFM.QHNe7UkSWBWHh0ZuShzs/weKzKPoMKB.cbi
  1. Now commit your changes.

This project uses pre-commit which is a tool of Git hooks scripting. If necessary the pre-commit will perform formatting in your code and you will need to add o these modifications before trying to commit again.

To learn more about the flow of committing to this project, go to the [x. How to commit to this project] and 4.Writing Meaningful Commit Messages pages

    git add script.py                   # add the file created
    git add requirements.in             # add the requirements changes
    git commit -m "First commit"        # commit the changes

You can also run pre-commit manually using:

pre-commit run --all-files

⚠️ Before committing and pushing, don't forget of add the new dependencies to the right files.

🚫 In this project the requirements.txt and requirements-dev.txt will be generated, please don´t edit them.

The project dependencies should be put into requirements.in and requirements-dev.in files (not the same dependency in both).

  • requirements.in - you should put scripts and modules dependencies here.
  • requirements-dev.in - you should put development dependencies like black, pylint and pytest here.
  1. Finally you can push your changes.

Your modifications will be synced on your forked repo.

    git push

after these few steps, the following message will be displayed on your repository.

now you can create your own Pull Request

See also the Project Template, Writing Good Commit Messages

Clone this wiki locally