Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup Python virtual environment with an action #2

Merged
merged 2 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/yaml-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Lint YAML code

on:
push:
branches:
- '**'
tags-ignore:
- '**'
jobs:
yamllint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: YAML Lint and Annotate
uses: Staffbase/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
target-path: .
3 changes: 3 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
rules:
truthy: disable
1 change: 1 addition & 0 deletions cleanup/action.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: 'Clean workspace'
description: 'Clean workspace directory after previous workflow run'
runs:
Expand Down
31 changes: 31 additions & 0 deletions setup-venv/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: 'Setup Python virtual environment'
description: 'Install virtualenv and Python modules from requirements file'
inputs:
venv-dir:
description: 'Virtualenv directory name'
required: true
default: 'venv'
requirements:
description: 'Path to requirements file'
required: true
default: requirements.txt
runs:
using: "composite"
steps:
# Install virtualenv for current user
- shell: bash
run: |
if [ -z ~/.local/bin/virtualenv ]; then \
pip install --no-input --disable-pip-version-check --user virtualenv; \
fi

# Setup Python environment
- shell: bash
run: |
~/.local/bin/virtualenv ${{ inputs.venv-dir }} && \
source ./${{ inputs.venv-dir }}/bin/activate && \
which python && \
python --version && \
pip install --no-input --disable-pip-version-check \
-r ${{ inputs.requirements }}
33 changes: 33 additions & 0 deletions setup-venv/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Setup Python virtual environment

Simple usage, given that the requirements file is called `requirements.txt`

```yaml
- uses: tarantool/actions/setup-venv@master
```

Providing the names of virtualenv directory and requirements file:

```yaml
- uses: tarantool/actions/setup-venv@master
with:
venv: '.venv'
requirements: 'requirements-test.txt'
```

Activate the virtual environment with:

```bash
source venv/bin/activate
```

This action is made as a (partial) replacement for
https://github.com/actions/setup-python,
particularly for using on ARM64 machines, where setup-python doesn't work.

Sometimes we don't need to set up the exact version of Python, but rather
need to set up a virtual environment and install a few packages in it.

If `virtualenv` is not found in the system, this action will install it
with `pip install --user`. This way it will not interfere with
system Python packages.