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

Add Ruff and Black CI, apply isort, apply ruff --fix #43

Merged
merged 5 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
48 changes: 48 additions & 0 deletions .github/workflows/build_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: build

on:
push:
branches:
- main
- release**
paths-ignore:
- '**.md'
- '**.rst'
pull_request:
paths-ignore:
- '**.md'
- '**.rst'

# This will cancel previous run if a newer job that obsoletes the said previous
# run, is started.
# Based on https://github.com/zulip/zulip/commit/4a11642cee3c8aec976d305d51a86e60e5d70522
concurrency:
group: "${{ github.workflow }}-${{ github.head_ref || github.run_id }}"
cancel-in-progress: true

jobs:
lint-ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- run: pip install ruff==0.0.275
- name: Lint with ruff
# Include `--format=github` to enable automatic inline annotations.
# Use settings from pyproject.toml.
run: ruff . --format=github

lint-black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- run: pip install black[jupyter]
- name: Lint with black
run: black --check .
1 change: 0 additions & 1 deletion examples/bank_reserves/bank_reserves/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"""

import mesa

from bank_reserves.random_walk import RandomWalker


Expand Down
1 change: 0 additions & 1 deletion examples/bank_reserves/bank_reserves/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import mesa
import numpy as np

from bank_reserves.agents import Bank, Person

"""
Expand Down
1 change: 0 additions & 1 deletion examples/bank_reserves/bank_reserves/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import mesa

from bank_reserves.agents import Person
from bank_reserves.model import BankReserves

Expand Down
1 change: 0 additions & 1 deletion examples/bank_reserves/batch_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import mesa
import numpy as np
import pandas as pd

from bank_reserves.agents import Bank, Person

# Start of datacollector functions
Expand Down
2 changes: 1 addition & 1 deletion examples/boid_flockers/boid_flockers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
self.separation = separation
self.schedule = mesa.time.RandomActivation(self)
self.space = mesa.space.ContinuousSpace(width, height, True)
self.factors = dict(cohere=cohere, separate=separate, match=match)
self.factors = {"cohere": cohere, "separate": separate, "match": match}
self.make_agents()
self.running = True

Expand Down
10 changes: 3 additions & 7 deletions examples/boltzmann_wealth_model/app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from boltzmann_wealth_model.model import BoltzmannWealthModel

import streamlit as st

import time

import pandas as pd

import altair as alt

import pandas as pd
import streamlit as st
from boltzmann_wealth_model.model import BoltzmannWealthModel

model = st.title("Boltzman Wealth Model")
num_agents = st.slider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def network_portrayal(G):
# The model ensures there is 0 or 1 agent per node

portrayal = dict()
portrayal = {}
portrayal["nodes"] = [
{
"id": node_id,
Expand Down
2 changes: 1 addition & 1 deletion examples/caching_and_replay/cacheablemodel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from model import Schelling
from mesa_replay import CacheableModel, CacheState
from model import Schelling


class CacheableSchelling(CacheableModel):
Expand Down
5 changes: 1 addition & 4 deletions examples/caching_and_replay/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily=
x = cell[1]
y = cell[2]
if self.random.random() < self.density:
if self.random.random() < self.minority_pc:
agent_type = 1
else:
agent_type = 0
agent_type = 1 if self.random.random() < self.minority_pc else 0

agent = SchellingAgent((x, y), self, agent_type)
self.grid.place_agent(agent, (x, y))
Expand Down
8 changes: 1 addition & 7 deletions examples/caching_and_replay/run.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
from pathlib import Path

import mesa

from server import (
canvas_element,
get_happy_agents,
happy_chart,
model_params,
)
from cacheablemodel import CacheableSchelling
from server import canvas_element, get_happy_agents, happy_chart, model_params

# As 'replay' is a simulation model parameter in this example, we need to make it available as such
model_params["replay"] = mesa.visualization.Checkbox("Replay cached run?", False)
Expand Down
1 change: 0 additions & 1 deletion examples/caching_and_replay/server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""This file was copied over from the original Schelling mesa example."""

import mesa

from model import Schelling


Expand Down
1 change: 0 additions & 1 deletion examples/charts/charts/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"""

import mesa

from charts.random_walk import RandomWalker


Expand Down
1 change: 0 additions & 1 deletion examples/charts/charts/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import mesa
import numpy as np

from charts.agents import Bank, Person

"""
Expand Down
1 change: 0 additions & 1 deletion examples/charts/charts/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import mesa

from charts.agents import Person
from charts.model import Charts

Expand Down
2 changes: 1 addition & 1 deletion examples/color_patches/color_patches/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def grid(self):
80 cell_objects = model.grid.get_cell_list_contents([(x, y)])

AttributeError: 'ColorPatches' object has no attribute 'grid'
""" # noqa: E501
"""
return self._grid

@property
Expand Down
12 changes: 2 additions & 10 deletions examples/conways_game_of_life/app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import mesa
import streamlit as st

import time

import pandas as pd

import altair as alt


import numpy as np
from conways_game_of_life.model import ConwaysGameOfLife

import pandas as pd

import streamlit as st
from conways_game_of_life.model import ConwaysGameOfLife

model = st.title("Boltzman Wealth Model")
num_ticks = st.slider("Select number of Steps", min_value=1, max_value=100, value=50)
Expand Down
3 changes: 1 addition & 2 deletions examples/conways_game_of_life/conways_game_of_life/server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import mesa

from .portrayal import portrayCell
from .model import ConwaysGameOfLife

from .portrayal import portrayCell

# Make a world that is 50x50, on a 250x250 display.
canvas_element = mesa.visualization.CanvasGrid(portrayCell, 50, 50, 250, 250)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mesa

from .agent import Cop, Citizen
from .agent import Citizen, Cop


class EpsteinCivilViolence(mesa.Model):
Expand Down
23 changes: 11 additions & 12 deletions examples/epstein_civil_violence/epstein_civil_violence/server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import mesa

from .model import EpsteinCivilViolence
from .agent import Citizen, Cop

from .model import EpsteinCivilViolence

COP_COLOR = "#000000"
AGENT_QUIET_COLOR = "#0066CC"
Expand Down Expand Up @@ -37,16 +36,16 @@ def citizen_cop_portrayal(agent):
return portrayal


model_params = dict(
height=40,
width=40,
citizen_density=0.7,
cop_density=0.074,
citizen_vision=7,
cop_vision=7,
legitimacy=0.8,
max_jail_term=1000,
)
model_params = {
"height": 40,
"width": 40,
"citizen_density": 0.7,
"cop_density": 0.074,
"citizen_vision": 7,
"cop_vision": 7,
"legitimacy": 0.8,
"max_jail_term": 1000,
}

canvas_element = mesa.visualization.CanvasGrid(citizen_cop_portrayal, 40, 40, 480, 480)
server = mesa.visualization.ModularServer(
Expand Down
1 change: 0 additions & 1 deletion examples/hex_snowflake/hex_snowflake/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import mesa

from hex_snowflake.cell import Cell


Expand Down
3 changes: 1 addition & 2 deletions examples/hex_snowflake/hex_snowflake/server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import mesa

from hex_snowflake.portrayal import portrayCell
from hex_snowflake.model import HexSnowflake
from hex_snowflake.portrayal import portrayCell

width, height = 50, 50

Expand Down
3 changes: 1 addition & 2 deletions examples/pd_grid/pd_grid/server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import mesa

from .portrayal import portrayPDAgent
from .model import PdGrid

from .portrayal import portrayPDAgent

# Make a world that is 50x50, on a 500x500 display.
canvas_element = mesa.visualization.CanvasGrid(portrayPDAgent, 50, 50, 500, 500)
Expand Down
5 changes: 1 addition & 4 deletions examples/schelling/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily=
x = cell[1]
y = cell[2]
if self.random.random() < self.density:
if self.random.random() < self.minority_pc:
agent_type = 1
else:
agent_type = 0
agent_type = 1 if self.random.random() < self.minority_pc else 0

agent = SchellingAgent((x, y), self, agent_type)
self.grid.place_agent(agent, (x, y))
Expand Down
1 change: 0 additions & 1 deletion examples/schelling/run_ascii.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import mesa

from model import Schelling


Expand Down
1 change: 0 additions & 1 deletion examples/schelling/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import mesa

from model import Schelling


Expand Down
2 changes: 1 addition & 1 deletion examples/shape_example/shape_example/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mesa

from .model import Walker, ShapeExample
from .model import ShapeExample, Walker


def agent_draw(agent):
Expand Down
5 changes: 1 addition & 4 deletions examples/sugarscape_cg/sugarscape_cg/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ def SsAgent_portrayal(agent):
return {"Shape": "sugarscape_cg/resources/ant.png", "scale": 0.9, "Layer": 1}

elif type(agent) is Sugar:
if agent.amount != 0:
color = color_dic[agent.amount]
else:
color = "#D6F5D6"
color = color_dic[agent.amount] if agent.amount != 0 else "#D6F5D6"
return {
"Color": color,
"Shape": "rect",
Expand Down
5 changes: 3 additions & 2 deletions examples/sugarscape_g1mt/run.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import sys
import pandas as pd

import matplotlib.pyplot as plt
import networkx as nx
import mesa
import networkx as nx
import pandas as pd
from sugarscape_g1mt.model import SugarscapeG1mt
from sugarscape_g1mt.server import server

Expand Down
5 changes: 2 additions & 3 deletions examples/sugarscape_g1mt/sugarscape_g1mt/model.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import mesa
import numpy as np


import mesa
from .resource_agents import Spice, Sugar
from .trader_agents import Trader
from .resource_agents import Sugar, Spice


# Helper Functions
Expand Down
Loading