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

Run linter and tests in CI build #48

Merged
merged 26 commits into from Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fbc32eb
Run linter and tests in CI build
chriskilding Jun 18, 2022
37449ea
Fix linter invocation and upgrade its dependency
chriskilding Jun 18, 2022
7c8a221
Parallelize MyPy and Black checks
chriskilding Jun 18, 2022
25f8855
Try Python 3.10 to see if generics error disappears
chriskilding Jun 18, 2022
ad18c9c
Bump actions/setup-python to v4
chriskilding Jun 18, 2022
8c3a3af
Remove poetry cache
chriskilding Jun 18, 2022
f78c3f4
Move poetry install to after setup-python
chriskilding Jun 18, 2022
96db55c
Tweak
chriskilding Jun 18, 2022
f591272
Try a poetry env use fix
chriskilding Jun 18, 2022
81340b4
Try poetry env use one-liner
chriskilding Jun 18, 2022
be18e00
Tweak
chriskilding Jun 18, 2022
108a3bd
Apply Black formatter
chriskilding Jun 18, 2022
9f7ccfb
Try without cache: poetry
chriskilding Jun 19, 2022
8d454b9
Set up poetry after python
chriskilding Jun 19, 2022
9f86236
Try poetry 1.2.0b2
chriskilding Jun 19, 2022
6edc366
Reordering
chriskilding Jun 19, 2022
0efe8b7
try python 3.9
chriskilding Jun 19, 2022
39134f8
alternate poetry install method
chriskilding Jun 19, 2022
9ff82c3
Use install-poetry action
chriskilding Jun 19, 2022
eab3bf4
Tweak
chriskilding Jun 19, 2022
166cc1d
Just install libgeos-dev
chriskilding Jun 19, 2022
96042bc
Add libproj-dev
chriskilding Jun 19, 2022
08feace
Replicate
chriskilding Jun 19, 2022
985968c
Try generics again
chriskilding Jun 19, 2022
0f33933
Reformat
chriskilding Jun 19, 2022
4e7ce32
Add types-requests and types-pillow stubs to satisfy mypy
chriskilding Jun 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 39 additions & 5 deletions .github/workflows/test.yml
@@ -1,22 +1,56 @@
name: Test
name: Build

on: [push, pull_request, workflow_dispatch]

permissions:
contents: read

jobs:
build:
test:
name: "Test"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
cache: poetry

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe try without cache to see if it runs?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alas turning off the cache did not work. Still see this:

============================= test session starts ==============================
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
...

python-version: "3.9"
python-version: "3.10"
- name: Install dependencies
run: poetry install
# TODO run tests
- name: Test
run: poetry run pytest
black:
girotobial marked this conversation as resolved.
Show resolved Hide resolved
name: "Black"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v4
with:
cache: poetry
python-version: "3.10"
- name: Install dependencies
run: poetry install
- name: Black
run: poetry run black --check src
mypy:
name: "MyPy"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v4
with:
cache: poetry
python-version: "3.10"
- name: Install dependencies
run: poetry install
- name: MyPy
run: poetry run mypy
158 changes: 45 additions & 113 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Expand Up @@ -9,7 +9,7 @@ packages = [
]

[tool.poetry.dependencies]
python = "~3.9"
python = "~3.10"
numpy = "1.21.2"
requests = "2.26.0"
Shapely = "1.7.1"
Expand All @@ -20,7 +20,7 @@ pyproj = "3.2.0"

[tool.poetry.dev-dependencies]
pytest-cov = "^3.0.0"
black = "21.9b0"
black = "22.3.0"
girotobial marked this conversation as resolved.
Show resolved Hide resolved
isort = "5.9.3"
mypy = "0.910"
pytest = "6.2.5"
Expand Down
14 changes: 7 additions & 7 deletions src/airport_data.py
Expand Up @@ -367,7 +367,7 @@ def __hash__(self):
def __repr__(self):
return "<GTile ({}, {})@ZL{}>".format(self.x, self.y, self.zl)

@functools.lru_cache(maxsize=2 ** 14)
@functools.lru_cache(maxsize=2**14)
def lower_zl_tile(self, target_zl=None):
if target_zl and target_zl >= self.zl:
return self
Expand All @@ -383,7 +383,7 @@ def lower_zl_tile(self, target_zl=None):
else:
return lower

@functools.lru_cache(maxsize=2 ** 13)
@functools.lru_cache(maxsize=2**13)
def higher_zl_subtiles(self, target_zl=None):
if target_zl and target_zl <= self.zl:
return [self]
Expand All @@ -393,14 +393,14 @@ def higher_zl_subtiles(self, target_zl=None):
return [
GTile(x, y, zl)
for x in range(
self.x * 2 ** zl_diff, (self.x + 16) * 2 ** zl_diff, 16
self.x * 2**zl_diff, (self.x + 16) * 2**zl_diff, 16
)
for y in range(
self.y * 2 ** zl_diff, (self.y + 16) * 2 ** zl_diff, 16
self.y * 2**zl_diff, (self.y + 16) * 2**zl_diff, 16
)
]

@functools.lru_cache(maxsize=2 ** 13)
@functools.lru_cache(maxsize=2**13)
def zl_siblings(self):
return self.lower_zl_tile().higher_zl_subtiles()

Expand All @@ -414,7 +414,7 @@ def surrounding_tiles(self, include_self=False):
]

@staticmethod
@functools.lru_cache(maxsize=2 ** 15)
@functools.lru_cache(maxsize=2**15)
def _cached_polygon(x, y, zl):
lat_max, lon_min = geo.gtile_to_wgs84(x, y, zl)
lat_min, lon_max = geo.gtile_to_wgs84(x + 16, y + 16, zl)
Expand Down Expand Up @@ -855,7 +855,7 @@ def _compacted_tile_set(tiles: set):
# Airport Interface
#

@functools.lru_cache(maxsize=2 ** 3)
@functools.lru_cache(maxsize=2**3)
def gtiles(
self,
zl,
Expand Down
3 changes: 1 addition & 2 deletions src/config.py
Expand Up @@ -1479,8 +1479,7 @@ def apply_changes(self):
if errors:
error_text = (
"The following variables had wrong type\nand were reset to"
" their default value!\n\n* "
+ "\n* ".join(errors)
" their default value!\n\n* " + "\n* ".join(errors)
)
self.popup("ERROR", error_text)

Expand Down
6 changes: 3 additions & 3 deletions src/dem.py
Expand Up @@ -200,7 +200,7 @@ def create_normal_map(self, pixx, pixy):
dy[0, :] = (self.alt_dem[0, :] - self.alt_dem[1, :]) / (pixy)
dy[-1, :] = (self.alt_dem[-2, :] - self.alt_dem[-1, :]) / (pixy)
del self.alt_dem
norm = numpy.sqrt(1 + dx ** 2 + dy ** 2)
norm = numpy.sqrt(1 + dx**2 + dy**2)
dx = dx / norm
dy = dy / norm
del norm
Expand Down Expand Up @@ -947,10 +947,10 @@ def http_request(url, source, verbose=False):
" ",
source,
"server may be down or busy, new tentative in",
2 ** tentative,
2**tentative,
"sec...",
)
time.sleep(2 ** tentative)
time.sleep(2**tentative)


##############################################################################
Expand Down
4 changes: 2 additions & 2 deletions src/dsf.py
Expand Up @@ -48,8 +48,8 @@ def __init__(self, level, bucket_size):
if level == 0:
self[("", "")] = self.Bucket()
else:
for i in range(2 ** level):
for j in range(2 ** level):
for i in range(2**level):
for j in range(2**level):
key = (
numpy.binary_repr(i).zfill(level),
numpy.binary_repr(j).zfill(level),
Expand Down
4 changes: 2 additions & 2 deletions src/filenames.py
Expand Up @@ -358,7 +358,7 @@ def jpeg_file_name_from_attributes(
+ "_"
+ str(til_x_left)
+ "_"
+ str(2 ** zoomlevel - 16 - til_y_top)
+ str(2**zoomlevel - 16 - til_y_top)
+ g2xpl_16_suffix
+ ".jpg"
)
Expand Down Expand Up @@ -421,7 +421,7 @@ def dds_file_name_from_attributes(
+ "_"
+ str(til_x_left)
+ "_"
+ str(2 ** zoomlevel - 16 - til_y_top)
+ str(2**zoomlevel - 16 - til_y_top)
+ g2xpl_16_suffix
+ "."
+ file_ext
Expand Down
6 changes: 2 additions & 4 deletions src/geo.py
Expand Up @@ -75,9 +75,7 @@ def ahaversin(__haversin: float) -> float:
return acos(1 - 2 * __haversin)


def greatcircle_distance(
start: tuple[float, float], end: tuple[float, float]
) -> float:
def greatcircle_distance(start: tuple, end: tuple) -> float:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better fix, would be

`from typing import Tuple

def greatcircle_distance(start: Tuple[float, float], end: Tuple[float, float]) -> float:
...
`

We should avoid removing typing information as it will prevent mypy from picking up typing bugs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I'd forgotten about the typing module

"""[summary]

Parameters
Expand Down Expand Up @@ -135,7 +133,7 @@ def transform(s_epsg, t_epsg, s_x, s_y):
##############################################################################

##############################################################################
@functools.lru_cache(maxsize=2 ** 16)
@functools.lru_cache(maxsize=2**16)
def gtile_to_wgs84(til_x, til_y, zoomlevel):
"""
Returns the latitude and longitude of the top left corner of the tile
Expand Down
24 changes: 12 additions & 12 deletions src/gui.py
Expand Up @@ -1499,7 +1499,7 @@ def compute_size(self):
greediness=config.cover_greediness,
greediness_threshold=config.cover_greediness_threshold,
)
/ 2 ** 30
/ 2**30
)

self.gb.set("{:0.1f}".format(total_size) + " GiB")
Expand Down Expand Up @@ -1620,7 +1620,7 @@ def save_zone_list(self):
class Ortho4XP_Earth_Preview(tk.Toplevel):

earthzl = 6
resolution = 2 ** earthzl * 256
resolution = 2**earthzl * 256

list_del_ckbtn = [
"OSM data",
Expand Down Expand Up @@ -1774,8 +1774,8 @@ def __init__(self, parent, lat, lon):
scrollregion=(
1,
1,
2 ** self.earthzl * 256 - 1,
2 ** self.earthzl * 256 - 1,
2**self.earthzl * 256 - 1,
2**self.earthzl * 256 - 1,
)
) # self.canvas.bbox(ALL))
(x0, y0) = geo.wgs84_to_pix(lat + 0.5, lon + 0.5, self.earthzl)
Expand Down Expand Up @@ -2324,8 +2324,8 @@ def draw_canvas(self, nx0, ny0):
self.imageNW = Image.open(filepreviewNW)
self.photoNW = ImageTk.PhotoImage(self.imageNW)
self.canv_imgNW = self.canvas.create_image(
nx0 * 2 ** self.earthzl * 256 / 8,
ny0 * 2 ** self.earthzl * 256 / 8,
nx0 * 2**self.earthzl * 256 / 8,
ny0 * 2**self.earthzl * 256 / 8,
anchor=NW,
image=self.photoNW,
)
Expand All @@ -2343,8 +2343,8 @@ def draw_canvas(self, nx0, ny0):
self.imageNE = Image.open(filepreviewNE)
self.photoNE = ImageTk.PhotoImage(self.imageNE)
self.canv_imgNE = self.canvas.create_image(
(nx0 + 1) * 2 ** self.earthzl * 256 / 8,
ny0 * 2 ** self.earthzl * 256 / 8,
(nx0 + 1) * 2**self.earthzl * 256 / 8,
ny0 * 2**self.earthzl * 256 / 8,
anchor=NW,
image=self.photoNE,
)
Expand All @@ -2354,8 +2354,8 @@ def draw_canvas(self, nx0, ny0):
self.imageSW = Image.open(filepreviewSW)
self.photoSW = ImageTk.PhotoImage(self.imageSW)
self.canv_imgSW = self.canvas.create_image(
nx0 * 2 ** self.earthzl * 256 / 8,
(ny0 + 1) * 2 ** self.earthzl * 256 / 8,
nx0 * 2**self.earthzl * 256 / 8,
(ny0 + 1) * 2**self.earthzl * 256 / 8,
anchor=NW,
image=self.photoSW,
)
Expand All @@ -2370,8 +2370,8 @@ def draw_canvas(self, nx0, ny0):
self.imageSE = Image.open(filepreviewSE)
self.photoSE = ImageTk.PhotoImage(self.imageSE)
self.canv_imgSE = self.canvas.create_image(
(nx0 + 1) * 2 ** self.earthzl * 256 / 8,
(ny0 + 1) * 2 ** self.earthzl * 256 / 8,
(nx0 + 1) * 2**self.earthzl * 256 / 8,
(ny0 + 1) * 2**self.earthzl * 256 / 8,
anchor=NW,
image=self.photoSE,
)
Expand Down
22 changes: 11 additions & 11 deletions src/imagery.py
Expand Up @@ -579,7 +579,7 @@ def initialize_providers_dict() -> None:
]
provider["resolutions"] = numpy.array(
[
20037508.34 / (128 * 2 ** i)
20037508.34 / (128 * 2**i)
for i in range(21)
]
)
Expand Down Expand Up @@ -861,7 +861,7 @@ def initialize_local_combined_providers_dict(tile):
)
kernel = numpy.array(range(1, 2 * mask_width))
kernel[mask_width:] = range(mask_width - 1, 0, -1)
kernel = kernel / mask_width ** 2
kernel = kernel / mask_width**2
for i in range(0, len(img_array)):
img_array[i] = numpy.convolve(
img_array[i], kernel, "same"
Expand Down Expand Up @@ -1257,7 +1257,7 @@ def get_wmts_image(tilematrix, til_x, til_y, provider, http_session):
url = url.replace("{x}", str(til_x))
url = url.replace("{y}", str(til_y))
url = url.replace("{|y|}", str(abs(til_y) - 1))
url = url.replace("{-y}", str(2 ** tilematrix - 1 - til_y))
url = url.replace("{-y}", str(2**tilematrix - 1 - til_y))
url = url.replace(
"{quadkey}", geo.gtile_to_quadkey(til_x, til_y, tilematrix)
)
Expand Down Expand Up @@ -1348,17 +1348,17 @@ def get_wmts_image(tilematrix, til_x, til_y, provider, http_session):
return (success, data)
elif success and down_sample:
x0 = (
(til_x_orig - 2 ** down_sample * til_x)
(til_x_orig - 2**down_sample * til_x)
* width
// (2 ** down_sample)
// (2**down_sample)
)
y0 = (
(til_y_orig - 2 ** down_sample * til_y)
(til_y_orig - 2**down_sample * til_y)
* height
// (2 ** down_sample)
// (2**down_sample)
)
x1 = x0 + width // (2 ** down_sample)
y1 = y0 + height // (2 ** down_sample)
x1 = x0 + width // (2**down_sample)
y1 = y0 + height // (2**down_sample)
return (
success,
data.crop((x0, y0, x1, y1)).resize(
Expand Down Expand Up @@ -1541,8 +1541,8 @@ def build_texture_from_bbox_and_size(t_bbox, t_epsg, t_size, provider):
- 1
)
if downscale >= 1:
width /= 2 ** downscale
height /= 2 ** downscale
width /= 2**downscale
height /= 2**downscale
subt_size = (width, height)
else:
subt_size = None
Expand Down
8 changes: 4 additions & 4 deletions src/mask.py
Expand Up @@ -58,11 +58,11 @@ def build_masks(tile, for_imagery=False):
##########################################
def transition_profile(ratio, ttype):
if ttype == "spline":
return 3 * ratio ** 2 - 2 * ratio ** 3
return 3 * ratio**2 - 2 * ratio**3
elif ttype == "linear":
return ratio
elif ttype == "parabolic":
return 2 * ratio - ratio ** 2
return 2 * ratio - ratio**2

##########################################
ui.red_flag = False
Expand Down Expand Up @@ -512,7 +512,7 @@ def build_mask(til_x, til_y):
b_img_array = numpy.array(img_array)
kernel = numpy.array(range(1, 2 * blur_width))
kernel[blur_width:] = range(blur_width - 1, 0, -1)
kernel = kernel / blur_width ** 2
kernel = kernel / blur_width**2
for i in range(0, len(b_img_array)):
b_img_array[i] = numpy.convolve(b_img_array[i], kernel, "same")
b_img_array = b_img_array.transpose()
Expand Down Expand Up @@ -906,7 +906,7 @@ def triangulation_to_image(name, pixel_size, grid_size_or_bbox):
kernel = numpy.ones(int(mask_width)) / int(mask_width)
kernel = numpy.array(range(1, 2 * mask_width))
kernel[mask_width:] = range(mask_width - 1, 0, -1)
kernel = kernel / mask_width ** 2
kernel = kernel / mask_width**2
for i in range(0, len(img_array)):
img_array[i] = numpy.convolve(img_array[i], kernel, "same")
img_array = img_array.transpose()
Expand Down