Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ jobs:
- region: ActivitySim 1-Zone Example (MTC)
region-org: ActivitySim
region-repo: activitysim-prototype-mtc
region-branch: extended
region-branch: pandas2
- region: ActivitySim 2-Zone Example (SANDAG)
region-org: ActivitySim
region-repo: sandag-abm3-example
region-branch: main
region-branch: pandas2
fail-fast: false
defaults:
run:
Expand Down
36 changes: 36 additions & 0 deletions sharrow/filewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,47 @@
import filecmp
import os
import uuid
from pathlib import Path

from filelock import FileLock, Timeout

# by default, blackening is disabled for performance reasons,
# but it can be enabled by setting the environment variable SHARROW_BLACKEN=1
SHARROW_BLACKEN = os.environ.get("SHARROW_BLACKEN", "0") == "1"


def blacken(code):
if not SHARROW_BLACKEN:
return code

# Ruff is much faster than black, so we try to use it first.
import subprocess

which_ruff = subprocess.run(["which", "ruff"], capture_output=True, text=True)
which_ruff.check_returncode()
ruff_bin = which_ruff.stdout.strip()
if ruff_bin:
try:
result = subprocess.run(
[ruff_bin, "format", "-"],
input=code,
text=True,
capture_output=True,
check=True,
cwd=Path.cwd(),
)
result.check_returncode()
return result.stdout
except subprocess.CalledProcessError as err:
import warnings

warnings.warn(f"error in ruffen: {err!r}", stacklevel=2)
return code
else:
import warnings

warnings.warn("ruff not found, trying black instead", stacklevel=2)

try:
import black
except ImportError:
Expand Down
Loading