Skip to content

Commit 6df75f2

Browse files
committed
Fix lint errors
1 parent 6bb5617 commit 6df75f2

File tree

7 files changed

+54
-30
lines changed

7 files changed

+54
-30
lines changed

.github/workflows/python-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Install dependencies
1818
run: |
1919
python -m pip install --upgrade pip
20-
pip install pylint
20+
pip install pylint pathtraits
2121
- name: Analysing the code with pylint
2222
run: |
2323
pylint $(git ls-files '*.py')

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,5 @@ dmypy.json
142142
.DS_Store
143143

144144
# etc
145-
run.sh
145+
/run.*
146146
*.db

analyze-db.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# pylint: disable-all
2+
13
import sqlite3
24
import pandas as pd
35

pathtraits/db.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self, db_path):
3838
self.execute(init_path_index_query)
3939
self.update_traits()
4040

41+
# pylint: disable=R1710
4142
def execute(self, query):
4243
"""
4344
Execute a SQLite query
@@ -74,7 +75,7 @@ def get(self, table, cols="*", condition=None, **kwargs):
7475
return None
7576

7677
keys = map(lambda x: x[0], response.description)
77-
res = {k: v for k, v in zip(keys, values)}
78+
res = dict(zip(keys, values))
7879
return res
7980

8081
def get_dict(self, path):

pathtraits/pathpair.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ def find(path):
4141
else:
4242
object_path = path
4343
return PathPair(object_path, meta_path)
44-
else:
45-
object_path = path
46-
for p in [
47-
"meta.yml",
48-
"meta.yaml",
49-
".meta.yml",
50-
".meta.yaml",
51-
".yml",
52-
".yaml",
53-
]:
54-
meta_path = os.path.join(object_path, p)
55-
56-
if os.path.exists(meta_path):
57-
return PathPair(object_path, meta_path)
44+
45+
object_path = path
46+
for p in [
47+
"meta.yml",
48+
"meta.yaml",
49+
".meta.yml",
50+
".meta.yaml",
51+
".yml",
52+
".yaml",
53+
]:
54+
meta_path = os.path.join(object_path, p)
55+
56+
if os.path.exists(meta_path):
57+
return PathPair(object_path, meta_path)
5858
return None

pathtraits/scan.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1-
import inotify.adapters
2-
import os
1+
"""
2+
Module for scanning directories
3+
"""
4+
35
import logging
4-
from pathtraits.pathpair import *
5-
from pathtraits.db import *
6+
import os
67
import re
78

9+
import inotify.adapters
10+
from pathtraits.pathpair import PathPair
11+
from pathtraits.db import TraitsDB
12+
813
logger = logging.getLogger(__name__)
914

1015
yaml_re = re.compile(r"(\.)?(meta)?\.(yaml|yml)$")
1116

1217

18+
# pylint: disable=W0102
1319
def scan_meta_yml(path, pathpairs=[]):
20+
"""
21+
Scan a directory recursively for meta yml files and return PathPairs.
22+
23+
:param path: Root path to scan
24+
:param pathpairs: list of pathpairs found so far (used for recursion)
25+
"""
1426
try:
1527
# faster than os.walk
1628
with os.scandir(path) as ents:
@@ -26,12 +38,19 @@ def scan_meta_yml(path, pathpairs=[]):
2638
pair = PathPair(object_path, e.path)
2739
pathpairs.append(pair)
2840
return pathpairs
29-
except Exception as ex:
30-
logger.error(f"skip {path}: {ex}")
41+
except (FileNotFoundError, PermissionError, OSError) as ex:
42+
logger.error("skip %s: %s", path, ex)
3143
return pathpairs
3244

3345

3446
def batch(path, db_path, verbose):
47+
"""
48+
Update database once, searches for all directories recursively.
49+
50+
:param path: path to scan in batch mode recursively
51+
:param db_path: path to the database
52+
:param verbose: enable verbose logging
53+
"""
3554
if verbose:
3655
logging.basicConfig(level=logging.DEBUG)
3756

@@ -44,6 +63,13 @@ def batch(path, db_path, verbose):
4463

4564

4665
def watch(path, db_path, verbose):
66+
"""
67+
Update database continiously, watches for new or changed files.
68+
69+
:param path: path to watch recursively
70+
:param db_path: path to the database
71+
:param verbose: enable verbose logging
72+
"""
4773
if verbose:
4874
logging.basicConfig(level=logging.DEBUG)
4975

@@ -57,13 +83,13 @@ def watch(path, db_path, verbose):
5783
for event in i.event_gen(yield_nones=False):
5884
(_, type_names, dir_path, filename) = event
5985

60-
if not type_names.__contains__("IN_CLOSE_WRITE"):
86+
if not type_names.contains("IN_CLOSE_WRITE"):
6187
continue
6288

6389
# watch afor both yml and object files
6490
# yml file might be created first and will be ignored
6591
path = os.path.join(dir_path, filename)
6692
pair = PathPair.find(path)
6793
if pair:
68-
logger.debug(f"add pathpair: {pair}")
94+
logger.debug("add pathpair: %s", pair)
6995
db.add_pathpair(pair)

run.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)