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

update pre-commit and ga workflows to be consistent with mesa #181

Merged
merged 2 commits into from
Jan 5, 2024
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
8 changes: 8 additions & 0 deletions .codespellignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
hist
hart
mutch
ist
inactivate
ue
fpr
falsy
17 changes: 9 additions & 8 deletions .github/workflows/build_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ jobs:
fail-fast: False
matrix:
os: [windows, ubuntu, macos]
python-version: ["3.11"]
python-version: ["3.12"]
include:
- os: ubuntu
python-version: "3.11"
- os: ubuntu
python-version: "3.10"
- os: ubuntu
Expand Down Expand Up @@ -54,24 +56,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.10"
- run: pip install ruff==0.0.254
python-version: "3.12"
- run: pip install ruff==0.1.5
- name: Lint with ruff
# Include `--format=github` to enable automatic inline annotations.
# Use settings from pyproject.toml.
run: ruff . --format=github
run: ruff .

lint-black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"
- run: pip install black[jupyter]
- name: Lint with black
run: black --check .
18 changes: 18 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: build

on:
push:
branches:
- main
- release**
pull_request:

jobs:
codespell:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: codespell-project/actions-codespell@master
with:
ignore_words_file: .codespellignore
skip: .*bootstrap.*,*.js,.*bootstrap-theme.css.map
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release
on:
push:
branches:
- main
- release**
paths-ignore:
- '**.md'
- '**.rst'
pull_request:
paths-ignore:
- '**.md'
- '**.rst'
workflow_dispatch:

permissions:
id-token: write

jobs:
release:
name: Deploy release to PyPI
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Checkout source
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install dependencies
run: pip install -U pip build wheel setuptools
- name: Build distributions
run: python -m build
- name: Upload package as artifact to GitHub
if: github.repository == 'projectmesa/mesa-geo' && startsWith(github.ref, 'refs/tags')
uses: actions/upload-artifact@v3
with:
name: package
path: dist/
- name: Publish package to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
16 changes: 11 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ ci:
autofix_prs: false

repos:
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black-jupyter
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.5
hooks:
# Run the linter.
- id: ruff
types_or: [ python, pyi, jupyter ]
# Run the formatter.
- id: ruff-format
types_or: [ python, pyi, jupyter ]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
Expand All @@ -17,4 +23,4 @@ repos:
hooks:
- id: trailing-whitespace
- id: check-toml
- id: check-yaml
- id: check-yaml
11 changes: 8 additions & 3 deletions mesa_geo/geoagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@

if agent_kwargs and "unique_id" in agent_kwargs:
agent_kwargs.remove("unique_id")
warnings.warn("Unique_id should not be in the agent_kwargs")
warnings.warn(

Check warning on line 113 in mesa_geo/geoagent.py

View check run for this annotation

Codecov / codecov/patch

mesa_geo/geoagent.py#L113

Added line #L113 was not covered by tests
"Unique_id should not be in the agent_kwargs", UserWarning, stacklevel=2
)

self.agent_class = agent_class
self.model = model
Expand Down Expand Up @@ -219,7 +221,10 @@
return agents

def from_GeoJSON(
self, GeoJSON, unique_id="index", set_attributes=True # noqa: N803
self,
GeoJSON, # noqa: N803
unique_id="index",
set_attributes=True,
):
"""
Create agents from a GeoJSON object or string. CRS is set to epsg:4326.
Expand All @@ -230,7 +235,7 @@
:param set_attributes: Set agent attributes from GeoDataFrame columns. Default True.
"""

gj = json.loads(GeoJSON) if type(GeoJSON) is str else GeoJSON
gj = json.loads(GeoJSON) if isinstance(GeoJSON, str) else GeoJSON

gdf = gpd.GeoDataFrame.from_features(gj)
# epsg:4326 is the CRS for all GeoJSON: https://datatracker.ietf.org/doc/html/rfc7946#section-4
Expand Down
8 changes: 6 additions & 2 deletions mesa_geo/geospace.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def add_layer(self, layer: ImageLayer | RasterLayer | gpd.GeoDataFrame) -> None:
f"Converting {layer.__class__.__name__} from crs {layer.crs.to_string()} "
f"to the crs of {self.__class__.__name__} - {self.crs.to_string()}. "
"Please check your crs settings if this is unintended, or set `GeoSpace.warn_crs_conversion` "
"to `False` to suppress this warning message."
"to `False` to suppress this warning message.",
UserWarning,
stacklevel=2,
)
layer.to_crs(self.crs, inplace=True)
self._total_bounds = None
Expand All @@ -145,7 +147,9 @@ def _check_agent(self, agent):
f"Converting {agent.__class__.__name__} from crs {agent.crs.to_string()} "
f"to the crs of {self.__class__.__name__} - {self.crs.to_string()}. "
"Please check your crs settings if this is unintended, or set `GeoSpace.warn_crs_conversion` "
"to `False` to suppress this warning message."
"to `False` to suppress this warning message.",
UserWarning,
stacklevel=2,
)
agent.to_crs(self.crs, inplace=True)
else:
Expand Down
2 changes: 1 addition & 1 deletion mesa_geo/raster_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,4 +694,4 @@
return obj

def __repr__(self) -> str:
return f"{self.__class__.__name__}(crs={self.crs}, total_bounds={self.total_bounds}, values={repr(self.values)})"
return f"{self.__class__.__name__}(crs={self.crs}, total_bounds={self.total_bounds}, values={self.values!r})"

Check warning on line 697 in mesa_geo/raster_layers.py

View check run for this annotation

Codecov / codecov/patch

mesa_geo/raster_layers.py#L697

Added line #L697 was not covered by tests
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ extend-ignore = [
"PGH004", # Use specific rule codes when using `noqa` TODO
"B905", # `zip()` without an explicit `strict=` parameter
"N802", # Function name should be lowercase
"N999", # Invalid module name
"N999", # Invalid module name. We should revisit this in the future, TODO
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar` TODO
"S310", # Audit URL open for permitted schemes. Allowing use of `file:` or custom schemes is often unexpected.
"S603", # `subprocess` call: check for execution of untrusted input
"ISC001", # ruff format asks to disable this feature
]
extend-exclude = ["docs", "build"]
# Hardcode to Python 3.8.
Expand Down
14 changes: 7 additions & 7 deletions tests/test_GeoSpace.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_add_agents_with_different_crs(self):

def test_remove_agent(self):
self.geo_space.add_agents(self.agents)
agent_to_remove = random.choice(self.agents)
agent_to_remove = random.choice(self.agents) # noqa: S311
self.geo_space.remove_agent(agent_to_remove)
remaining_agent_idx = {agent.unique_id for agent in self.geo_space.agents}

Expand Down Expand Up @@ -121,7 +121,7 @@ def test_add_vector_layer(self):

def test_get_neighbors_within_distance(self):
self.geo_space.add_agents(self.agents)
agent_to_check = random.choice(self.agents)
agent_to_check = random.choice(self.agents) # noqa: S311

neighbors = list(
self.geo_space.get_neighbors_within_distance(
Expand Down Expand Up @@ -175,9 +175,9 @@ def test_get_relation_within(self):
list(self.geo_space.get_relation(self.agents[0], relation="within")), []
)
self.geo_space.add_agents(self.polygon_agent)
within_agent = list(
within_agent = next(
self.geo_space.get_relation(self.agents[0], relation="within")
)[0]
)
self.assertEqual(within_agent.unique_id, self.polygon_agent.unique_id)

def test_get_relation_touches(self):
Expand All @@ -196,9 +196,9 @@ def test_get_relation_touches(self):
1,
)
self.assertEqual(
list(self.geo_space.get_relation(self.polygon_agent, relation="touches"))[
0
].unique_id,
next(
self.geo_space.get_relation(self.polygon_agent, relation="touches")
).unique_id,
self.touching_agent.unique_id,
)

Expand Down