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 all 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
75 changes: 62 additions & 13 deletions .github/workflows/test.yml
@@ -1,22 +1,71 @@
name: Test
name: Build

on: [push, pull_request, workflow_dispatch]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
test:
name: Test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Setup Poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v3
with:
cache: poetry
python-version: "3.9"
- name: Install dependencies
run: poetry install
# TODO run tests
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: snok/install-poetry@v1
- name: Install GEOS
uses: lyricwulf/abc@v1
with:
macos: geos
linux: libgeos-dev
- name: Install PROJ
uses: lyricwulf/abc@v1
with:
macos: proj
linux: proj-bin libproj-dev
- run: poetry install
- run: poetry run pytest
black:
girotobial marked this conversation as resolved.
Show resolved Hide resolved
name: Black
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: snok/install-poetry@v1
- name: Install GEOS
uses: lyricwulf/abc@v1
with:
macos: geos
linux: libgeos-dev
- name: Install PROJ
uses: lyricwulf/abc@v1
with:
macos: proj
linux: proj-bin libproj-dev
- run: poetry install
- run: poetry run black --check src
mypy:
name: MyPy
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: snok/install-poetry@v1
- name: Install GEOS
uses: lyricwulf/abc@v1
with:
macos: geos
linux: libgeos-dev
- name: Install PROJ
uses: lyricwulf/abc@v1
with:
macos: proj
linux: proj-bin libproj-dev
- run: poetry install
- run: poetry run mypy
237 changes: 92 additions & 145 deletions poetry.lock

Large diffs are not rendered by default.

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

[tool.poetry.dependencies]
python = "~3.9"
python = "~3.10"
numpy = "1.21.2"
requests = "2.26.0"
Shapely = "1.7.1"
Rtree = "0.9.7"
Rtree = "1.0.0"
Pillow = "8.3.2"
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"
prospector = {extras = ["with_vulture"], version = "1.5.1"}
types-requests = "2.25.11"
types-requests = "2.26.0"
types-Pillow = "8.3.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
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
2 changes: 1 addition & 1 deletion src/geo.py
Expand Up @@ -135,7 +135,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