Git Action.txt
In the context of GitHub Actions for Python projects, a requirements.txt file is used to specify the Python package dependencies that need to be installed for your workflow to run successfully.
Purpose in GitHub Actions:
- Dependency Management:It provides a standardized way to declare all the external Python libraries and their specific versions that your project relies on.
- Consistent Environment:When your GitHub Action runs, it can use this file to install the exact same dependencies, ensuring a consistent environment across different runs and preventing issues caused by varying package versions.
- Reproducibility:It makes your build and test processes reproducible, as anyone working on the project or any automated system can easily set up the required environment.
How it’s used in a GitHub Action workflow:
- Checkout Code: The workflow typically starts by checking out your repository’s code.
- Set up Python Environment: An action like
actions/setup-pythonis used to configure a Python environment. - Install Dependencies: A
pip install -r requirements.txtcommand is executed to install all the packages listed in yourrequirements.txtfile.
Automatic requirement.txt for Python Projects on Github
pipreqs – Generates pip requirements.txt file based on imports of any project.
This action will automatically create the requirements.txt file for a python project using the pipreqs tool.
You can specify the location of your project folder that contains all the python files within your repository. You can specify the path to which your requirement.txt has to be saved.
Usage
Example workflow
name: Integration Test
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Automatic requirements.txt for Python Project
uses: ryan-rozario/pipreqs-action@master
# Put an example of mandatory inputs here
with:
PROJECT_PATH: project_folder #default is the root of the repository
REQUIREMENT_PATH: project_folder/requirements.txt #default is requirement.txt in the root of your repository
Inputs
| Input | Description | Default |
|---|---|---|
PROJECT_PATH | Gives the path to the project folder that contains the python files | . |
REQUIREMENT_PATH | Gives the path to the location where requirements.txt has to be saved, including the requirements.txt file name | requirements.txt |
PROJECT_NAME | Includes the project name in the commit | project_name |
Example of a step in a GitHub Actions workflow:
Code
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
Creating requirements.txt:
You can manually create or update this file, or use tools like pip freeze to generate it automatically:
Code
pip freeze > requirements.txt
- You need to clone the repository
############################################ # command: git clone <repository url> ############################################git clone https://github.com/OmkarNallagoni/EDA.git</code></pre></li>check your brnach name : ################################## Command: git branch -a or git branch ################################### main
dev
remotes/origin/main ==> only main is there/dev branch is not able
to see in UI
remotes/origin/dev ==> both main and dev able to see Let's create a branch name : dev
##########################
# comand: git branch dev #
########################## Spl condition:
In order to see the cretaed branch in github ################################# git push origin <branch_name> git push origin dev ################################## * marks means : currently you are on which branch
*main
what ever I modify the codes ====== > directly impact main branch we will move to dev branch
*dev
#################################################
command: git checkout
git checkout dev
################################################## In order to create remote branch
command: git push origin
git push origin dev I will start my developemnts ########################################### Modify any file ########################################### After we modify/ any developents we need to push that changes
then only we can able to see in github First check the status:
status will privide which files are modified or created etc
#######################
# command: git status #
####################### Now add the changes:
########################
# command: git add . #
######################## Now commit che changes git config --global user.email omkar.nallagoni@gamil.com ################################################ command : git commit -am<msg> git commit -am "workspace updated" ###################################################a: automatically you can track m: modified files before commit</code></pre></li>Optional
*** Please tell me who you are. Run git config --global user.email "you@example.com"
git config --global user.name "Your Name" to set your account's default identity.
Omit --global to set the identity only in this repository. #################################################################### git config --global user.email "omkar.nallagoni@gmail.com" ################################################################ Finally we will push the changes ############################################### command: git push origin <branch name> git push origin dev ################################################# after codes will push in your feature branch
you need merge with main branch Raise a PR: PUll REQUEST =================================================================
clone the main code base
created a branch
we modified the file we push the changes on the feature branch branch need to be deleted locally: ################################################ command: git branch -D <branch_name> git branch --delete <branch_name> ################################################### Note: Branch will not delete if you are on that currently
So first checkout to main, then delete branch
###################################################
git checkout main
##################################################### branch need to be deleted remote ############################################### Command: git push origin -d <branch_name> ################################################
Python Dependency Installation
Install Python dependencies from requirements.txt file
v4.1.0
Latest
By py-actions
Tags
2 (2)
continuous-integrationdependency-management
py-actions/py-dependency-install GitHub Action
This GitHub Action installs Python package dependencies from a user-defined requirements.txt file path with pip, setuptools, and wheel installs/updates during execution. A Python package environment report is displayed at the end of Action execution.
This Action is tested nightly with cPython v3.9.x – v3.12.x in the latest Linux, macOS, and Windows GitHub Actions runner environments.
Quick Start
Insert a dependency installation step under the steps: field in a GitHub workflow job with a configuration like this:
Default
Uses path requirements.txt and updates pip, setuptools, and wheel before the install.
steps:
# this Action should follow steps to set up Python build environment
- name: Install Python dependencies
uses: py-actions/py-dependency-install@v4
Define the requirements.txt path
Define a requirements.txt file on a path relative to the root of your repository.
steps:
# this Action should follow steps to set up Python build environment
- name: Install Python dependencies
uses: py-actions/py-dependency-install@v4
with:
path: "path/to/requirements.txt"
Toggle pip, setuptools, and wheel installs/updates off
The pip, setuptools, and wheel install/updates can be toggled off in your configuration. Use one or more of the update-pip, update-setuptools, and update-wheel settings with a boolean string to customize the default behavior:
steps:
# this Action should follow steps to set up Python build environment
- name: Install Python dependencies
uses: py-actions/py-dependency-install@v4
with:
update-pip: "false"
update-setuptools: "false"
update-wheel: "false"
Inputs
path
Optional The requirements.txt file path relative to the root of your source repository. Default = "requirements.txt".
update-pip
Optional A boolean string indicating that a pip package update should occur before the dependency installation. Options: ["true", "false"]. Default="true"
update-setuptools
Optional A boolean string indicating that a setuptools package update should occur before the dependency installation. Options: ["true", "false"]. Default="true"
update-wheel
Optional A boolean string indicating that a wheel package update should occur before the dependency installation. Options: ["true", "false"]. Default="true"
Outputs
None
I am building a python project — potion. I want to use Github actions to automate some linting & testing before merging a new branch to master.
To do that, I am using a slight modification of a Github recommended python actions starter workflow — Python Application.
During the step of “Install dependencies” within the job, I am getting an error. This is because pip is trying to install my local package potion and failing.
The code that is failing if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
The corresponding error is:
ERROR: git+https@github.com:<github_username>/potion.git@82210990ac6190306ab1183d5e5b9962545f7714#egg=potion is not a valid editable requirement. It should either be a path to a local project or a VCS URL (beginning with bzr+http, bzr+https, bzr+ssh, bzr+sftp, bzr+ftp, bzr+lp, bzr+file, git+http, git+https, git+ssh, git+git, git+file, hg+file, hg+http, hg+https, hg+ssh, hg+static-http, svn+ssh, svn+http, svn+https, svn+svn, svn+file).
Error: Process completed with exit code 1.
Most likely, the job is not able install the package potion because it is not able to find it. I installed it on my own computer using pip install -e . and later used pip freeze > requirements.txt to create the requirements file.
Since I use this package for testing therefore I need to install this package so that pytest can run its tests properly.
How can I install a local package (which is under active development) on Github Actions?
Here is part of the Github workflow file python-app.yml
...
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
...
Note 1: I have already tried changing from git+git@github.com:<github_username>... to git_git@github.com/<github_username>.... Pay attention to / instead of :.
Note 2: I have also tried using other protocols such as git+https, git+ssh, etc.
Note 3: I have also tried to remove the alphanumeric @8221... after git url ...potion.git
- python
- github
- pip
- github-actions
- requirements.txt
- Could you include the
potionentry from your requirements.txt file in your post? – jidicula CommentedJun 11, 2021 at 13:47 -e git+git@github.com:<github_username>/potion.git@a3edd62c15257dc0e3755558ab1faa573bf0cd3d#egg=potion-> that’s what potion looks like in requirements.txt