Skip to content

Commit

Permalink
Add mypy and ruff configuration and github actions
Browse files Browse the repository at this point in the history
Resolve missing type annotations.
Resolve ruff reported errors.
Make it easier to call generate_script.
  • Loading branch information
153957 committed Jul 4, 2023
1 parent bec4f1c commit 1e10e2b
Show file tree
Hide file tree
Showing 74 changed files with 264 additions and 131 deletions.
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "thursday"

- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
day: "thursday"
31 changes: 31 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run tests

on:
push:

jobs:
rufftest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: 'requirements-ruff.txt'
- run: make ruffinstall
- run: make rufftest
env:
RUFF_FORMAT: github

typingtest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: 'pyproject.toml'
- run: make devinstall
- run: make typingtest
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.PHONY: mypyinstall
mypyinstall:
pip install --upgrade pip
pip install --upgrade --upgrade-strategy eager -r requirements-mypy.txt

.PHONY: ruffinstall
ruffinstall:
pip install --upgrade pip
pip install --upgrade --upgrade-strategy eager -r requirements-ruff.txt

.PHONY: install
install:
pip install --upgrade pip
pip install --upgrade --upgrade-strategy eager -r requirements.txt

.PHONY: test
test: rufftest typingtest

.PHONY: rufftest
rufftest:
ruff .

.PHONY: typingtest
typingtest:
mypy .
21 changes: 11 additions & 10 deletions generate_script.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
import argparse

from os.path import commonprefix
Expand All @@ -14,8 +15,8 @@ def save_script(name: str, script: str) -> None:

def single(path: str) -> None:
"""Simple single shot movie"""
path = Path(path).resolve()
sorted_images = sorted(image_path.stem for image_path in path.iterdir() if image_path.is_file())
resolved_path = Path(path).resolve()
sorted_images = sorted(image_path.stem for image_path in resolved_path.iterdir() if image_path.is_file())
first = sorted_images[0]
last = sorted_images[-1]
poster = choice(sorted_images)
Expand All @@ -30,22 +31,22 @@ def single(path: str) -> None:
NAME = Path(__file__).stem
PATTERN = '{path}/*.tif' # {first} - {last}
# poster: {poster}
POSTER = '{poster}.tif'
if __name__ == '__main__':
make_movie(NAME, PATTERN, {fps}, {deflicker}, watermark=True, verbose=False, dryrun=False)
""").lstrip()
save_script(path.name, script)
save_script(resolved_path.name, script)


def multiple(*paths: str) -> None:
"""Simple multiple shots stitched together"""
paths = [Path(path).resolve() for path in paths]
resolved_paths = [Path(path).resolve() for path in paths]
firsts = []
lasts = []

for path in paths:
for path in resolved_paths:
sorted_images = sorted(image_path.stem for image_path in path.iterdir() if image_path.is_file())
firsts.append(sorted_images[0])
lasts.append(sorted_images[-1])
Expand All @@ -57,7 +58,7 @@ def multiple(*paths: str) -> None:

patterns = '\n '.join(
f" '{path}/*.tif', # {first} - {last}"
for path, first, last in zip(paths, firsts, lasts, strict=True)
for path, first, last in zip(resolved_paths, firsts, lasts, strict=True)
)

script = dedent(f"""
Expand All @@ -69,15 +70,15 @@ def multiple(*paths: str) -> None:
PATTERNS = [
{patterns}
]
# poster: {poster}
POSTER = '{poster}.tif'
if __name__ == '__main__':
make_movie(NAME, PATTERNS, {fps}, {deflicker}, watermark=True, verbose=False, dryrun=False)
""").lstrip()

prefix = commonprefix([path.name for path in paths])
name = '_'.join(path.name.removeprefix(prefix) for path in paths)
prefix = commonprefix([path.name for path in resolved_paths])
name = '_'.join(path.name.removeprefix(prefix) for path in resolved_paths)
if prefix:
name = f'{prefix}{name}'
save_script(name, script)
Expand Down
57 changes: 57 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[tool.mypy]
ignore_missing_imports = true
show_column_numbers = true
show_error_codes = true
strict = true
warn_return_any = true
warn_unused_configs = true

[tool.ruff]
target-version = 'py311'
line-length = 120
select = [
# https://github.com/charliermarsh/ruff#supported-rules
'ALL',
'E111', 'E112', 'E113', 'E114', 'E115', 'E116', 'E117',
'E201', 'E202', 'E203',
'E211',
'E221', 'E222', 'E223', 'E224', 'E225', 'E226', 'E227', 'E228',
'E231',
'E251', 'E252',
'E261', 'E262', 'E265', 'E266',
'E271', 'E272', 'E273', 'E274', 'E275',
]
ignore = [
'ANN101', # No need to add type to self
'D', # Ignore docstring checks
'DTZ007', # Ignore missing timezone
'E501', # Some paths are very long
'EM', # Allow messages directly in exceptions
'FBT001', # Allow positional for boolean arguments
'FBT002', # Allow default value for boolean arguments
'N999', # Allow invalid module names for scripts
'PD', # Not using pandas
'PLR0913', # Allow functions with many arguments
'PT', # Not using pytest
'Q000', # Use single quotes
'RET504', # Allow variable assignment before return
'S311', # Allow pseudo-random generators for non-cryptographic purpose
'SIM108', # Allow if-else block instead of ternary
'SLF001', # Allo private member access
'T201', # Allow using print
'TRY003', # Specific messages for common exception classes
]

[tool.ruff.isort]
lines-between-types = 1
section-order = [
'future',
'standard-library',
'third-party',
'time_lapse',
'first-party',
'local-folder',
]

[tool.ruff.isort.sections]
time_lapse = ['time_lapse']
2 changes: 2 additions & 0 deletions requirements-mypy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-r requirements.txt
mypy==1.4.1
1 change: 1 addition & 0 deletions requirements-ruff.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruff==0.0.275
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
time-lapse==4.0
4 changes: 2 additions & 2 deletions scripts/080614_S60_Hibiscus.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from time_lapse import make_movie

NAME = Path(__file__).stem
PATTERN = '/Volumes/Crimson/Cache/080614_S60_Hibiscus/*.tif', # S60_080614_015644 - S60_080614_120341
# poster: S60_080614_075141
PATTERN = '/Volumes/Crimson/Cache/080614_S60_Hibiscus/*.tif' # S60_080614_015644 - S60_080614_120341
POSTER = 'S60_080614_075141.tif'


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion scripts/090712_DSC_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

NAME = Path(__file__).stem
PATTERN = '/Volumes/Crimson/Cache/090712_DSC_1/*.tif' # D80_090712_114208 - D80_090712_115058
# poster: D80_090712_115006
POSTER = 'D80_090712_115006.tif'


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion scripts/090712_DSC_Tokyo_Tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

NAME = Path(__file__).stem
PATTERN = '/Volumes/Crimson/Cache/090712_DSC_Tokyo_Tower/*.tif' # D80_090712_183805 - D80_090712_195932
# poster: D80_090712_190253
POSTER = 'D80_090712_190253.tif'


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion scripts/090721_DSC_Shanghai_Jiao_Tong_University.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

NAME = Path(__file__).stem
PATTERN = '/Volumes/Crimson/Cache/090721_DSC_Shanghai_Jiao_Tong_University/*.tif' # D80_090721_173414c - D80_090721_174041
# poster: D80_090721_174021
POSTER = 'D80_090721_174021.tif'


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion scripts/090727_DSC_Narita_International_Airport.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

NAME = Path(__file__).stem
PATTERN = '/Volumes/Crimson/Cache/090727_DSC_Narita_International_Airport/*.tif' # D80_090727_153936 - D80_090727_160037
# poster: D80_090727_155831
POSTER = 'D80_090727_155831.tif'


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion scripts/090727_DSC_Shanghai_Pudong_Airport.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

NAME = Path(__file__).stem
PATTERN = '/Volumes/Crimson/Cache/090727_DSC_Shanghai_Pudong_Airport/*.tif' # D80_090727_090438 - D80_090727_101136
# poster: D80_090727_092703
POSTER = 'D80_090727_092703.tif'


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions scripts/100914_DSC_Utrecht_Centraal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

NAME = Path(__file__).stem
PATTERN = '/Volumes/Crimson/Cache/100914_DSC_Utrecht_Centraal/*.tif' # D80_100914_094520 - D80_100914_095806
# poster: D80_100914_094743
POSTER = 'D80_100914_094743.tif'


if __name__ == '__main__':
Expand All @@ -16,5 +16,5 @@
watermark=True,
verbose=False,
dryrun=False,
filters=[('tblend', {'all_mode': 'darken', 'all_opacity': 0.33})]
filters=[('tblend', {'all_mode': 'darken', 'all_opacity': '0.33'})],
)
8 changes: 4 additions & 4 deletions scripts/100924_DSC_1_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
PATTERN2 = '/Volumes/Falcon/tl_temp/100924_2/*.tiff'


def make_movie():
def create_movie() -> None:
input1 = (
ffmpeg
.input(PATTERN1, pattern_type='glob', framerate=24)
Expand All @@ -20,10 +20,10 @@ def make_movie():
.input(PATTERN2, pattern_type='glob', framerate=48)
.filter_('deflicker', mode='pm', size=10)
)
input = ffmpeg.concat(input1, input2)
combined_inputs = ffmpeg.concat(input1, input2)

output.create_outputs(input, NAME, verbose=True, r=48)
output.create_outputs(combined_inputs, NAME, framerate=48, verbose=True)


if __name__ == '__main__':
make_movie()
create_movie()
2 changes: 1 addition & 1 deletion scripts/101203_DSC_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

NAME = Path(__file__).stem
PATTERN = '/Volumes/Sith/Store_elsewhere/Falcon/Time-Lapse/101203_DSC_2/*.tif' # D80_101203_130438 - D80_101203_131442
# poster: D80_101203_130516
POSTER = 'D80_101203_130516.tif'


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion scripts/101231_DSC_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

NAME = Path(__file__).stem
PATTERN = '/Volumes/Falcon/tl_temp/101231_1/*.tiff' # D80_101231_235618 - D80_110101_002307
# poster: D80_110101_000431
POSTER = 'D80_110101_000431.tif'


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions scripts/110209_ADL_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from time_lapse import make_movie

NAME = Path(__file__).stem
PATTERNS = '/Volumes/Falcon/tl_temp/110209_1/*.tiff', # D700_110209_081219 - D700_110209_081737
# poster: D700_110209_081233
PATTERNS = '/Volumes/Falcon/tl_temp/110209_1/*.tiff' # D700_110209_081219 - D700_110209_081737
POSTER = 'D700_110209_081233.tif'


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions scripts/110311_DSC_Holland_Casino.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

NAME = Path(__file__).stem
PATTERN = '/Volumes/Crimson/Cache/110311_DSC_Holland_Casino/*.tif' # D80_110311_200019 - D80_110311_225056
# poster: D80_110311_213343
POSTER = 'D80_110311_213343.tif'


if __name__ == '__main__':
Expand All @@ -16,5 +16,5 @@
watermark=True,
verbose=False,
dryrun=False,
filters=[('tblend', {'all_mode': 'lighten', 'all_opacity': 0.5})]
filters=[('tblend', {'all_mode': 'lighten', 'all_opacity': '0.5'})],
)
Loading

0 comments on commit 1e10e2b

Please sign in to comment.