Skip to content
Draft

wip #543

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
31 changes: 31 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Base debian build (latest).
FROM mcr.microsoft.com/vscode/devcontainers/base:debian

# Update packages.
RUN apt-get update && apt-get install -y tar

# Set the default shell to zsh
ENV SHELL=/usr/bin/zsh

# Running everything under zsh
SHELL ["/usr/bin/zsh", "-c"]

# Dropping privileges
USER vscode

# Install rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && source $HOME/.cargo/env

# Install uv and add to PATH
# See https://docs.astral.sh/uv/guides/integration/docker/
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
ENV PATH="/home/vscode/.local/bin:$PATH"

# Add cargo and uv to shell configuration
RUN echo 'export PATH="/home/vscode/.cargo/bin:$PATH"' >> ~/.zshrc

# Install just via uv
RUN uv tool install rust-just

# Clean up
RUN sudo apt-get autoremove -y && sudo apt-get clean -y
28 changes: 28 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "Safe-CLI DevContainer",
"build": {
"dockerfile": "Dockerfile"
},
"features": {},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"charliermarsh.ruff"
],
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
}
},
"python.terminal.activateEnvironment": true,
"python.defaultInterpreterPath": ".venv/bin/python"
}
}
},
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached",
"workspaceFolder": "/workspace",
"postCreateCommand": "zsh -c 'uv venv && source .venv/bin/activate && uv sync --all-extras'"
}
27 changes: 27 additions & 0 deletions .github/workflows/pypi-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: pypi-release

on:
release:
types: [released]
workflow_dispatch:

jobs:
build-and-publish:
runs-on: ubuntu-latest
environment: production
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: "pyproject.toml"
- name: Install uv
uses: astral-sh/setup-uv@v6
- name: Install dependencies
run: uv sync
- name: Build package
run: uv build
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Instead of using `python` in the CLI, use `uv python` and let `uv` manage the Python version and dependencies. This ensures that the correct Python version and dependencies are used, as specified in the `pyproject.toml` file.
59 changes: 59 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Contributing

# Setup

## Manual Setup Requirements

You must have the following installed to proceed with contributing to this project.

- [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- You'll know you did it right if you can run `git --version` and you see a response like `git version x.x.x`
- [python](https://www.python.org/downloads/)
- You'll know you did it right if you can run `python --version` and you see a response like `Python x.x.x`
- [uv](https://docs.astral.sh/uv/getting-started/installation/)
- You'll know you did it right if you can run `uv --version` and you see a response like `uv 0.4.7 (a178051e8 2024-09-07)`
- Linux and/or MacOS
- This project is not tested on Windows, so it is recommended to use a Linux or MacOS machine, or use a tool like [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) for windows users.
- [anvil](https://book.getfoundry.sh/reference/anvil/)
- You'll know you did it right if you can run `anvil --version` and you see a response like `anvil 0.2.0 (b1f4684 2024-05-24T00:20:06.635557000Z)`
- [just](https://github.com/casey/just)
- You'll know you did it right if you can run `just --version` and you see a response like `just 1.35.0`

## Dev Container Setup Requirements

- [Docker](https://www.docker.com/)
- You'll know you did it right if you can run `docker --version` and you see a response like `Docker version x.x.x, build xxxxxxx`
- [VSCode](https://code.visualstudio.com/)

# Local Development

Follow the steps to clone the repo for you to make changes to this project.

1. Clone the repo

```bash
git clone https://github.com/safe-global/safe-cli
cd safe-cli
```

2. Sync dependencies

*This repo uses uv to manage python dependencies and version. So you don't have to deal with virtual environments (much)*

```bash
uv sync --all-extras
```

3. Create a new branch

```bash
git checkout -b <branch_name>
```

And start making your changes! Once you're done, you can commit your changes and push them to your forked repo.

```bash
git add .
git commit -m 'your commit message'
git push <your_forked_github>
```
12 changes: 12 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
list:
@just --list

format:
uv run ruff check --select I --fix
uv run ruff check . --fix

build-requirements:
uv pip compile pyproject.toml -o requirements.txt

test:
uv run pytest -x
80 changes: 63 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "safe-cli"
dynamic = ["version"]
dynamic = [
"version",
]
description = "Command Line Interface for Safe"
readme = "README.md"
license = "MIT"
requires-python = ">=3.8"
authors = [{ name = "Uxío Fuentefría", email = "uxio@safe.global" }]
requires-python = ">=3.10" # Cannot use 3.8 & 3.9 due to dependency issues
authors = [
{ name = "Uxío Fuentefría", email = "uxio@safe.global" },
]
classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
Expand All @@ -31,9 +31,37 @@ dependencies = [
"typer>=0.14.0",
]

[build-system]
requires = [
"hatchling",
]
build-backend = "hatchling.build"

[tool.uv]
managed = true
package = true
dev-dependencies = [
"coverage==7.8.0",
"flake8==7.2.0",
"pytest==8.3.5",
"pytest-sugar==1.0.0",
"hatch",
"ipdb",
"ipython",
"isort",
"pre-commit",
"ledgereth==0.10.0",
"trezor==0.13.10",

]

[project.optional-dependencies]
ledger = ["ledgereth==0.10.0"]
trezor = ["trezor==0.13.10"]
ledger = [
"ledgereth==0.10.0",
]
trezor = [
"trezor==0.13.10",
]

[project.scripts]
safe-cli = "safe_cli.main:main"
Expand All @@ -47,30 +75,45 @@ Homepage = "https://github.com/gnosis/safe-cli"
path = "src/safe_cli/__init__.py"

[tool.hatch.envs.types]
extra-dependencies = ["mypy>=1.0.0"]
extra-dependencies = [
"mypy>=1.0.0",
]

[tool.hatch.envs.types.scripts]
check = "mypy --install-types --non-interactive {args:src/safe_cli tests}"

[tool.hatch.build.targets.sdist]
include = ["/src/safe_cli"]
include = [
"/src/safe_cli",
]

[tool.hatch.build.targets.wheel]
packages = ["/src/safe_cli"]
packages = [
"/src/safe_cli",
]

[tool.coverage.run]
source_pkgs = ["safe_cli", "tests"]
source_pkgs = [
"safe_cli",
"tests",
]
branch = true
parallel = true
omit = [
"*__init__.py*",
"*tests*",
"*/migrations/*"
"*/migrations/*",
]

[tool.coverage.paths]
safe_cli = ["src/safe_cli", "*/safe-cli/src/safe_cli"]
tests = ["tests", "*/safe-cli/tests"]
safe_cli = [
"src/safe_cli",
"*/safe-cli/src/safe_cli",
]
tests = [
"tests",
"*/safe-cli/tests",
]

[tool.coverage.report]
exclude_lines = [
Expand All @@ -86,7 +129,10 @@ exclude_lines = [
profile = "black"
default_section = "THIRDPARTY"
known_first_party = "safe_cli"
known_safe_foundation = ["py_eth_sig_utils", "gnosis"]
known_safe_foundation = [
"py_eth_sig_utils",
"gnosis",
]
known_django = "django"
sections = [
"FUTURE",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_safe_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ def test_update_to_l2_v111(self):
"safe_cli.operators.safe_operator.safe_deployments",
{
"1.3.0": {
"GnosisSafeL2": {"1337": [self.safe_contract_V1_3_0.address]},
"GnosisSafeL2": {"31337": [self.safe_contract_V1_3_0.address]},
"CompatibilityFallbackHandler": {
"1337": [self.compatibility_fallback_handler.address]
"31337": [self.compatibility_fallback_handler.address]
},
}
},
Expand Down Expand Up @@ -409,7 +409,7 @@ def test_update_to_l2_v130(self):
"safe_cli.operators.safe_operator.safe_deployments",
{
"1.3.0": {
"GnosisSafeL2": {"1337": [safe_contract_l2_130_address]},
"GnosisSafeL2": {"31337": [safe_contract_l2_130_address]},
}
},
):
Expand Down
Loading
Loading