Skip to content

Commit

Permalink
Merge pull request #2 from frangiz/github-actions
Browse files Browse the repository at this point in the history
Migrated from travis to github actions. Added pre-commit and added support for python 3.8 and 3.9
  • Loading branch information
frangiz committed Feb 7, 2021
2 parents ecd4bac + feba612 commit 0e97e3b
Show file tree
Hide file tree
Showing 21 changed files with 116 additions and 90 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
32 changes: 32 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: pre-commit

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
pre-commit:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade pre-commit
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run pre-commit
run: pre-commit run --verbose --all-files --show-diff-on-failure
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,5 @@ dmypy.json

# End of https://www.gitignore.io/api/python

tests/working_dir
tests/working_dir
.venv3.9/
41 changes: 41 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-executables-have-shebangs
- id: check-yaml
- id: end-of-file-fixer
types: [python]
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.5.3
hooks:
- id: isort
args:
- --profile=black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
args:
- --ignore=E203,W503
- --max-complexity=25
- --max-line-length=88
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.782
hooks:
- id: mypy
args:
- --ignore-missing-imports
- repo: local
hooks:
- id: pytest-cov
name: pytest
language: system
entry: pytest --cov=. --cov-report html .
types: [python]
pass_filenames: false
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

19 changes: 5 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ picorg -a duplicates
A settings file is created in <USER_HOME>/.picorg that stores the users settings.

## Developing
Install dependencies from the requirements-dev.txt file
Install dependencies from the requirements.txt file
```python
pip install -r requirements-dev.txt
pip install -r requirements.txt
```

Create a package and install with
Expand All @@ -37,22 +37,13 @@ python setup.py bdist_wheel sdist
pip install -e .
```

Run tests with
```python
pytest --cov=src --cov-report html .
```
or using tox
```
tox
```

### Before commit
Run the script `pre-commit.sh` before any commits on order to be consistent with formatting and having sorted imports.
Run the command `pre-commit run --verbose --all-files --show-diff-on-failure` before any commits on order to be consistent with formatting and having sorted imports.

## Creating a new version.
* Create a new version by bumping the version in setup.py.
* Commit and push.
* Wait for Travis CI to build.
* Wait for Github to build.
* Create a tag in git and push.
* Wait for Travis CI to build the tag.
* Wait for Github to build the tag.
* Push the new package to pypi using `twine upload dist/*`
File renamed without changes.
14 changes: 0 additions & 14 deletions pre-commit.sh

This file was deleted.

10 changes: 0 additions & 10 deletions requirements-dev.txt

This file was deleted.

9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pillow==8.1.0
exifread==2.3.2

# test
pytest==6.2.2
pytest-cov==2.11.1

# formatting
pre-commit==2.10.1
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
Expand Down
3 changes: 1 addition & 2 deletions src/duplicates.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import filecmp

from itertools import combinations
from pathlib import Path
from typing import List

import settings
from src import settings


def handle_duplicates() -> List[Path]:
Expand Down
4 changes: 2 additions & 2 deletions src/picorg.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse

from duplicates import handle_duplicates
from rename import rename_files
from src.duplicates import handle_duplicates
from src.rename import rename_files


def main():
Expand Down
6 changes: 3 additions & 3 deletions src/rename.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os

from pathlib import Path
from typing import List

import timestamp_finder
from src import timestamp_finder


def rename_files(root: str = ".") -> None:
Expand All @@ -23,7 +22,7 @@ def rename_file(file) -> None:
os.rename(file, new_filename)


def _list_files(root: str) -> List[str]:
def _list_files(root: str) -> List[Path]:
types = [".jpg"]
result = []
for filename in Path(root).glob("**/*"):
Expand All @@ -45,6 +44,7 @@ def _find_new_filename(file: str, exif_name: str) -> str:
)
if not suggested_path.is_file():
return str(suggested_path)
raise RuntimeError("This should never happen...")


def _handle_no_exif_found(file: str) -> None:
Expand Down
2 changes: 0 additions & 2 deletions src/settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import json

from pathlib import Path


SETTINGS_DIR = Path(Path.home(), ".picorg")


Expand Down
8 changes: 3 additions & 5 deletions src/timestamp_finder.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from datetime import datetime

import exifread
from PIL import Image
from PIL.ExifTags import TAGS

import exifread


def get_timestamp(filename):
ts = PILWrapper.get_timestamp(filename)
Expand Down Expand Up @@ -39,7 +38,7 @@ def get_timestamp(filename):
field = PILWrapper.__get_field(exif_data, "DateTimeDigitized")
if field is not None and date_text_to_filename(field[0]) is not None:
return field[0]
except Exception as e:
except Exception:
# print(e.__repr__())
return None

Expand All @@ -56,15 +55,14 @@ class ExifReadWrapper:
@staticmethod
def get_timestamp(filename):
try:
exif_data = None
with open(filename, "rb") as f:
tags = exifread.process_file(f) # Return Exif tags
field = ExifReadWrapper.__get_field(tags, "EXIF DateTimeDigitized")
if field is None:
return None

return str(field)
except Exception as e:
except Exception:
# print(e.__repr__())
return None

Expand Down
6 changes: 3 additions & 3 deletions tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import shutil
import inspect
import pathlib

import shutil
from os import path


BASE_PATH = "tests/working_dir"


Expand All @@ -16,6 +14,8 @@ def setup_module(module):
def get_test_folder(test_method: str) -> pathlib.Path:
stack_frame = inspect.stack()[1]
calling_module = inspect.getmodule(stack_frame[0])
if calling_module is None:
raise RuntimeError("Failed to get calling_module")
print(calling_module.__name__)

return pathlib.Path(BASE_PATH, calling_module.__name__, test_method)
9 changes: 3 additions & 6 deletions tests/test_duplicates.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import pathlib
import os
import pathlib

import duplicates
import settings

import test_base

from src import duplicates, settings
from tests import test_base

TEST_DIR = ""
PREV_WORKING_DIR = ""
Expand Down
7 changes: 3 additions & 4 deletions tests/test_rename.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import rename
import shutil
import pathlib
import shutil

import test_base

from src import rename
from tests import test_base

TEST_DIR = ""

Expand Down
2 changes: 1 addition & 1 deletion tests/test_timestamp_finder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import timestamp_finder
from src import timestamp_finder


def test_valid_date_text():
Expand Down
6 changes: 0 additions & 6 deletions tox.ini

This file was deleted.

0 comments on commit 0e97e3b

Please sign in to comment.