Skip to content

Commit

Permalink
feat:add dev check
Browse files Browse the repository at this point in the history
Signed-off-by: grapebaba <[email protected]>
  • Loading branch information
GrapeBaBa authored and norswap committed Aug 9, 2023
1 parent 0b3d1a1 commit f067044
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build the project

on:
push:
branches: [ "master" ]
pull_request:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
source scripts/install.sh
- name: Check with ruff
run: |
make check
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/optimism
/__pycache__
/.idea
/venv
/.ruff_cache
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

linter: ## Run linter
@ruff check .
.PHONY: linter

check: linter ## Run check
.PHONY: check
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ you can automatically subsidize gas for transactions that match certain criteria

## Prerequisites

- Python 3 (to run the `roll.py` script)
- Python >= 3.10 (to run the `roll.py` script)

The following dependencies will be checked by `roll.py`:

Expand All @@ -34,6 +34,16 @@ always for your permission before installing anything outside the current direct
- Node.js 16.x
- Yarn (`npm install -g yarn` — the old one, not yarn v3 aka yarn berry)

## Contributing

```bash
# Install dependencies
source scripts/install.sh

# Run checks
make check
```

## Plans

- See [here](https://app.charmverse.io/op-grants/proposals?id=a6e6bfb8-75bd-41bd-acb1-618c3c62e667)
Expand Down
Empty file removed makefile
Empty file.
8 changes: 5 additions & 3 deletions roll.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def nvm_install_node():
# We have NVM, try using required version or installing it.
try:
lib.run(f"use node {NODE_VNAME}", f"source ~/.nvm/nvm.sh; nvm use {NODE_VERSION}")
except Exception as err:
except Exception:
if lib.ask_yes_no(f"Node {NODE_VNAME} ({NODE_VERSION}) is required. NVM is installed. "
f"Install with NVM?"):
nvm_install_node()
Expand Down Expand Up @@ -172,9 +172,11 @@ def setup_optimism_repo():

print("Starting to build the optimism repository. This may take a while...\n")
# TODO screen position moves, so this only clears one screen worth of output
if args.use_ansi_esc: lib.term_save_cursor()
if args.use_ansi_esc:
lib.term_save_cursor()
run_with_node("build optimism", "make build", cwd="optimism", forward_output=True)
if args.use_ansi_esc: lib.term_clear_from_saved()
if args.use_ansi_esc:
lib.term_clear_from_saved()
# TODO tee the outputs to a log file
print("Successfully built the optimism repository.")

Expand Down
1 change: 1 addition & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
line-length = 110
53 changes: 53 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

# Description: This script is used to setup the development environment for the project.


check_python_version() {
# Check python version if greater or equal than 3.10, otherwise exit
python_version=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
if python3 -c "import sys; sys.exit(not (sys.version_info >= (3, 10)))"; then
echo "Python version is $python_version"
else
echo "Python version is $python_version, but 3.10 or greater is required"
exit 1
fi
}

activate_venv() {
# Check if venv directory exists, otherwise create it. Then activate venv
if [ -d "venv" ]; then
echo "venv directory exists"
else
echo "venv directory does not exist, creating it now"
python3 -m venv venv
fi
echo "activating venv"
source ./venv/bin/activate
}

install_dev_dependencies() {
# Install development dependencies
echo "installing development dependencies"
# Check if pip3 version is greater or equal than 21.2.4, otherwise upgrade it
pip3_version=$(pip3 --version | awk '{print $2}')
if python3 -c "import sys; sys.exit(not (sys.version_info >= (21, 2, 4)))"; then
echo "pip3 version is $pip3_version"
else
echo "pip3 version is $pip3_version, but 21.2.4 or greater is required"
pip3 install --upgrade pip
fi
# Check if ruff is installed, otherwise install it
if ! command -v ruff &> /dev/null
then
echo "ruff could not be found, installing it now"
pip3 install ruff
else
echo "ruff is installed"
fi
}

check_python_version
activate_venv
install_dev_dependencies

0 comments on commit f067044

Please sign in to comment.