Skip to content

Commit

Permalink
Add black, isort, and mypy to github tests
Browse files Browse the repository at this point in the history
scientific_metadata.py is excluded from mypy temporarily.
  • Loading branch information
sbliven committed Nov 28, 2023
1 parent 3406f6e commit 0906579
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ jobs:
run: |
set -vxeuo pipefail
python -m flake8
- name: Lint with black
shell: bash -l {0}
run: black --check .

- name: Lint with isort
shell: bash -l {0}
run: isort --check .

- name: Lint with mypy
shell: bash -l {0}
run: mypy --check pyscicat

- name: Test with pytest
shell: bash -l {0}
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@ profile = "black"

[tool.hatch]
version.source = "vcs"
build.hooks.vcs.version-file = "pyscicat/_version.py"
build.hooks.vcs.version-file = "pyscicat/_version.py"

[tool.mypy]
# TODO Add type annotations and include this file
exclude = "pyscicat/hdf5/scientific_metadata.py"
9 changes: 5 additions & 4 deletions pyscicat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
from datetime import datetime
from typing import Optional
from pathlib import Path
from urllib.parse import quote_plus, urljoin

import requests
Expand Down Expand Up @@ -777,13 +778,13 @@ def datasets_delete(self, pid: str) -> Optional[dict]:
delete_dataset = datasets_delete


def get_file_size(pathobj):
def get_file_size(pathobj: Path):
filesize = pathobj.lstat().st_size
return filesize


def get_checksum(pathobj):
with open(pathobj) as file_to_check:
def get_checksum(pathobj: Path):
with open(pathobj,'rb') as file_to_check:
# pipe contents of the file through
return hashlib.md5(file_to_check.read()).hexdigest()

Expand All @@ -798,7 +799,7 @@ def encode_thumbnail(filename, imType="jpg"):
return header + dataStr


def get_file_mod_time(pathobj):
def get_file_mod_time(pathobj: Path):
# may only work on WindowsPath objects...
# timestamp = pathobj.lstat().st_mtime
return str(datetime.fromtimestamp(pathobj.lstat().st_mtime))
Expand Down

0 comments on commit 0906579

Please sign in to comment.