Skip to content

Commit

Permalink
Enable basic pre-commit (#121)
Browse files Browse the repository at this point in the history
* Enable basic pre-commit
* Add readme paragraph
  • Loading branch information
inverse authored Sep 9, 2021
1 parent 6018498 commit 77555bc
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.gitattributes export-ignore
.gitignore export-ignore
snapcraft.yaml export-ignore
snapcraft.yaml export-ignore
22 changes: 5 additions & 17 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,11 @@ on:
- "*.txt"

jobs:
lint:
pre-commit:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: ricardochaves/python-lint@master
with:
python-root-list: "src phockup.py"
use-pylint: false
use-pycodestyle: false
use-flake8: true
use-black: false
use-mypy: false
use-isort: true
extra-pylint-options: ""
extra-pycodestyle-options: ""
extra-flake8-options: "--max-line-length=88 --select=C,E,F,W,B,B950 --ignore=E203,E501,W503"
extra-black-options: ""
extra-mypy-options: ""
extra-isort-options: ""
- name: Install dependencies
run: pip install -r requirements-dev.txt
- name: Run pre-commit
run: pre-commit run -a
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ jobs:
run: |
sudo apt-get install -y libimage-exiftool-perl
python -m pip install --upgrade pip
pip install pytest
pip install -r requirements-dev.txt
- name: Run tests
Expand Down
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/PyCQA/isort
rev: 5.9.3
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
10 changes: 5 additions & 5 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@
* Merged [#78](https://github.com/ivandokov/phockup/issues/78)
* Merged [#81](https://github.com/ivandokov/phockup/issues/81)
##### `1.5.9`
* Fixed [#70](https://github.com/ivandokov/phockup/issues/70) related to Windows issues
##### `1.5.8`
* Fixed [#70](https://github.com/ivandokov/phockup/issues/70) related to Windows issues
##### `1.5.8`
* Add `--date-field` option to set date extraction fields [#54](https://github.com/ivandokov/phockup/issues/54)
* Handle regex with optional hour information [#62](https://github.com/ivandokov/phockup/issues/62)
* Fix regex support for incomplete time on filename [#55](https://github.com/ivandokov/phockup/issues/55)
* Fix to handle files with illegal characters [#53](https://github.com/ivandokov/phockup/issues/53)
##### `1.5.7`
##### `1.5.7`
* Resolved [#44](https://github.com/ivandokov/phockup/issues/44)
##### `1.5.6`
##### `1.5.6`
* Add `-o | --original-names` option to allow keeping the original filenames
##### `1.5.5`
##### `1.5.5`
* Add `-t` option to allow using file modification time as a last resort
* Workaround EXIF DateTaken time of all-zeros
##### `1.5.4`
Expand Down
26 changes: 21 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Requires [snapd](https://snapcraft.io/docs/core/install)
```
sudo snap install phockup
```
*Note: snap applications can access files only in your **home and `/media` directories** for security reasons. If your media files are not located in these directories you should use the installation method below.
*Note: snap applications can access files only in your **home and `/media` directories** for security reasons. If your media files are not located in these directories you should use the installation method below.
If your files are in `/media` you should run the following command to allow access:*
```
sudo snap connect phockup:removable-media
Expand Down Expand Up @@ -102,7 +102,7 @@ If any of the photos does not have date information you can use the `-r | --rege
--regex="(?P<day>\d{2})\.(?P<month>\d{2})\.(?P<year>\d{4})[_-]?(?P<hour>\d{2})\.(?P<minute>\d{2})\.(?P<second>\d{2})"
```

As a last resort, specify the `-t | --timestamp` option to use the file modification timestamp. This may not be accurate in all cases but can provide some kind of date if you'd rather it not go into the `unknown` folder.
As a last resort, specify the `-t | --timestamp` option to use the file modification timestamp. This may not be accurate in all cases but can provide some kind of date if you'd rather it not go into the `unknown` folder.

### Move files
Instead of copying the process will move all files from the INPUTDIR to the OUTPUTDIR by using the flag `-m | --move`. This is useful when working with a big collection of files and the remaining free space is not enough to make a copy of the INPUTDIR.
Expand All @@ -114,7 +114,7 @@ Instead of copying the process will create hard link all files from the INPUTDIR
Organize the files in selected format or using the default year/month/day format but keep original filenames by using the flag `-o | --original-names`.

### File Type
By default, Phockup addresses both image and video files. If you want to restrict your command to either images or videos only, use `--file-type=[image|video]`.
By default, Phockup addresses both image and video files. If you want to restrict your command to either images or videos only, use `--file-type=[image|video]`.

### Fix incorrect dates
If date extracted from photos is incorrect, you can use the `-f | --date-field` option to set the correct exif field to get date information from. Use this command to list which fields are available for a file:
Expand Down Expand Up @@ -149,7 +149,7 @@ If you want phockup to run with a progressbar (displaying only the progress and

### Limit directory traversal depth
If you would like to limit how deep the directories are traversed, you can use the `--maxdepth` option to specify the maximum number of levels below the input directory to process. In order to process only the input directory, you can disable sub-directory processing with:
`--maxdepth=0` The current implementation is limited to a maximum depth of 255.
`--maxdepth=0` The current implementation is limited to a maximum depth of 255.

## Development

Expand All @@ -173,6 +173,22 @@ pytest --cov-report term-missing:skip-covered --cov=src tests/

Please add the necessary tests when committing a feature or improvement.


### Pre-commit checks
We leverage the [pre-commit](https://pre-commit.com/) framework to automate some general linting/quality checks.

To install the hooks, from within the activated virtualenv run:

```bash
pre-commit install
```

To manually execute the hooks, run:

``bash
pre-commit run -a
```
### Style Guide Ruleset
Please make sure that the code is compliant as described below when committing a feature or improvement.
Expand All @@ -185,7 +201,7 @@ In a nutshell, this comes down to to 88 characters per line. This number was fou
#### isort
We also use [isort](https://github.com/PyCQA/isort) to check if import are sorted alphabetically, separated into sections and by type.
##### single-quotes and double-quotes
##### single-quotes and double-quotes
We try to adhere to the following as much as possible:
Use single-quotes for string literals, e.g. 'my-identifier', but use double-quotes for strings that are likely to contain single-quote characters as part of the string itself (such as error messages, or any strings containing natural language), e.g. "You've got an error!".
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pytest
pytest-mock
pytest-cov
tqdm
pre-commit
1 change: 1 addition & 0 deletions tests/test_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import re
from datetime import datetime

from src.date import Date

os.chdir(os.path.dirname(__file__))
Expand Down
1 change: 1 addition & 0 deletions tests/test_exif.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
import os
from subprocess import CalledProcessError

from src.exif import Exif

os.chdir(os.path.dirname(__file__))
Expand Down
13 changes: 8 additions & 5 deletions tests/test_phockup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/usr/bin/env python3
import pytest
import logging
import os
import shutil
import sys
import os
import logging
from datetime import datetime

import pytest

from src.dependency import check_dependencies
from src.exif import Exif
from src.phockup import Phockup


os.chdir(os.path.dirname(__file__))


Expand Down Expand Up @@ -93,6 +94,7 @@ def test_dry_run():
assert not os.path.isdir(dir3)
assert not os.path.isdir(dir4)


def test_progress():
shutil.rmtree('output', ignore_errors=True)
Phockup('input', 'output', progress=True)
Expand All @@ -106,6 +108,7 @@ def test_progress():
assert not os.path.isdir(dir3)
assert not os.path.isdir(dir4)


def test_get_file_type(mocker):
mocker.patch.object(Phockup, 'check_directories')
assert Phockup('in', '.').get_file_type("image/jpeg")
Expand Down Expand Up @@ -405,4 +408,4 @@ def test_progress():
os.path.isfile(os.path.join(dir2, name))]) == 1
assert len([name for name in os.listdir(dir3) if
os.path.isfile(os.path.join(dir3, name))]) == 1
shutil.rmtree('output', ignore_errors=True)
shutil.rmtree('output', ignore_errors=True)
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 88
ignore = E203 E501 W503 E126 F811

0 comments on commit 77555bc

Please sign in to comment.