Skip to content

Commit

Permalink
Merge pull request #124 from dylanljones/refactor
Browse files Browse the repository at this point in the history
refactor: update linter/formatter rules
  • Loading branch information
dylanljones authored Feb 23, 2024
2 parents 4317f6d + 9eb7733 commit a6d0c58
Show file tree
Hide file tree
Showing 23 changed files with 122 additions and 61 deletions.
29 changes: 27 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,45 @@ select = [
"F", # flake8
"E", # pycodestyle Errors
"W", # pycodestyle Warnings
# "I", # isort
"I", # isort
"NPY", # Numpy
"N", # pep8-naming
"D", # pydocstyle
]
ignore = [
"E203", # Whitespace before ':'
"D100", # Missing docstring in public module
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D104", # Missing docstring in public package
"D105", # Missing docstring in magic method
"D106", # Missing docstring in public nested class
"D107", # Missing docstring in __init__
"D401", # First line should be in imperative mood
"D403", # First word of the first line should be capitalized
"D404", # First word of the docstring should not be "This"
#"N802", # Function name should be lowercase
#"N803", # Argument name should be lowercase
"N813", # Camelcase imported as lowercase
#"N815", # Variable in class scope should not be mixedCase
"N818", # Exception name should be named with an Error suffix
]
fixable = ["ALL"] # Allow fix for all enabled rules (when `--fix`) is provided.
unfixable = []

[tool.ruff.lint.per-file-ignores]
"*__init__.py" = ["F401"]
"rbxml.py" = ["N803"]
"tables.py" = ["N802", "N815"]


[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.ruff.lint.isort]
combine-as-imports = true
# length-sort = true
length-sort = false

[tool.ruff.format]
quote-style = "double"
Expand Down
16 changes: 8 additions & 8 deletions pyrekordbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
# Author: Dylan Jones
# Date: 2022-04-10

from .anlz import AnlzFile, get_anlz_paths, read_anlz_files, walk_anlz_paths
from .config import get_config, show_config, update_config
from .db6 import Rekordbox6Database, open_rekordbox_database
from .logger import logger
from .config import show_config, get_config, update_config
from .rbxml import RekordboxXml, XmlDuplicateError, XmlAttributeKeyError
from .anlz import get_anlz_paths, walk_anlz_paths, read_anlz_files, AnlzFile
from .mysettings import (
DevSettingFile,
DjmMySettingFile,
MySetting2File,
MySettingFile,
get_mysetting_paths,
read_mysetting_file,
MySettingFile,
MySetting2File,
DjmMySettingFile,
DevSettingFile,
)
from .db6 import Rekordbox6Database, open_rekordbox_database
from .rbxml import RekordboxXml, XmlAttributeKeyError, XmlDuplicateError

try:
from ._version import version as __version__
Expand Down
5 changes: 3 additions & 2 deletions pyrekordbox/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import os
import re
import sys
import shutil
import sys
import urllib.request
from pathlib import Path
from pyrekordbox.config import write_db6_key_cache, _cache_file

from pyrekordbox.config import _cache_file, write_db6_key_cache

KEY_SOURCES = [
{
Expand Down
5 changes: 3 additions & 2 deletions pyrekordbox/anlz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
from pathlib import Path
from typing import Union

from . import structs
from .file import AnlzFile

Expand Down Expand Up @@ -77,7 +78,7 @@ def walk_anlz_dirs(root_dir: Union[str, Path]):
The path of the root directory.
Yields
-------
------
anlz_dir : str
The path of a directory containing ANLZ files
"""
Expand All @@ -96,7 +97,7 @@ def walk_anlz_paths(root_dir: Union[str, Path]):
The path of the root directory.
Yields
-------
------
anlz_dir : str
The path of a directory containing ANLZ files.
anlz_files : Sequence of str
Expand Down
6 changes: 4 additions & 2 deletions pyrekordbox/anlz/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
from collections import abc
from pathlib import Path
from typing import Union
from .tags import TAGS
from . import structs

from construct import Int16ub

from . import structs
from .tags import TAGS

logger = logging.getLogger(__name__)

XOR_MASK = bytearray.fromhex("CB E1 EE FA E5 EE AD EE E9 D2 E9 EB E1 E9 F3 E8 E9 F4 E1")
Expand Down
4 changes: 3 additions & 1 deletion pyrekordbox/anlz/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import logging
from abc import ABC

import numpy as np

from . import structs

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -439,7 +441,7 @@ class PWV5AnlzTag(AbstractAnlzTag):
LEN_HEADER = 24

def get(self):
"""Parse the Waveform Color Detail Tag (PWV5)
"""Parse the Waveform Color Detail Tag (PWV5).
The format of the entries is:
Expand Down
1 change: 0 additions & 1 deletion pyrekordbox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ def _get_rb5_config(

def _extract_pw(pioneer_install_dir: Path) -> str: # pragma: no cover
"""Extract the password for decrypting the Rekordbox 6 database key."""

asar_data = read_rekordbox6_asar(pioneer_install_dir)
match_result = re.search('pass: ".(.*?)"', asar_data)
if match_result is None:
Expand Down
4 changes: 2 additions & 2 deletions pyrekordbox/db6/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Author: Dylan Jones
# Date: 2022-05-07

from .database import Rekordbox6Database, open_rekordbox_database
from .smartlist import SmartList
from .tables import (
AgentRegistry,
CloudAgentRegistry,
Expand Down Expand Up @@ -41,5 +43,3 @@
SettingFile,
UuidIDMap,
)
from .smartlist import SmartList
from .database import Rekordbox6Database, open_rekordbox_database
5 changes: 3 additions & 2 deletions pyrekordbox/db6/aux_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# Author: Dylan Jones
# Date: 2023-09-10

from pathlib import Path
from datetime import datetime
import xml.etree.cElementTree as xml
from datetime import datetime
from pathlib import Path

from ..config import get_config
from ..utils import pretty_xml

Expand Down
18 changes: 10 additions & 8 deletions pyrekordbox/db6/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@
import datetime
import logging
import secrets
from uuid import uuid4
from pathlib import Path
from typing import Optional
from sqlalchemy import create_engine, or_, event, MetaData, select
from sqlalchemy.orm import Session, Query
from uuid import uuid4

from sqlalchemy import MetaData, create_engine, event, or_, select
from sqlalchemy.exc import NoResultFound
from sqlalchemy.orm import Query, Session
from sqlalchemy.sql.sqltypes import DateTime, String
from ..utils import get_rekordbox_pid, warn_deprecated

from ..anlz import AnlzFile, get_anlz_paths, read_anlz_files
from ..config import get_config
from ..anlz import get_anlz_paths, read_anlz_files, AnlzFile
from .registry import RekordboxAgentRegistry
from ..utils import get_rekordbox_pid, warn_deprecated
from . import tables
from .aux_files import MasterPlaylistXml
from .tables import DjmdContent, FileType, PlaylistType
from .registry import RekordboxAgentRegistry
from .smartlist import SmartList
from . import tables
from .tables import DjmdContent, FileType, PlaylistType

try:
from sqlcipher3 import dbapi2 as sqlite3 # noqa
Expand Down
1 change: 1 addition & 0 deletions pyrekordbox/db6/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
from contextlib import contextmanager

from sqlalchemy.orm.exc import ObjectDeletedError

logger = logging.getLogger(__name__)
Expand Down
8 changes: 4 additions & 4 deletions pyrekordbox/db6/smartlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import logging
import xml.etree.cElementTree as xml
from dataclasses import dataclass
from datetime import datetime
from enum import Enum, IntEnum
from typing import List, Union
from datetime import datetime
from dataclasses import dataclass

from sqlalchemy import or_, and_, not_
from sqlalchemy.sql.elements import BooleanClauseList
from dateutil.relativedelta import relativedelta # noqa
from sqlalchemy import and_, not_, or_
from sqlalchemy.sql.elements import BooleanClauseList

from .tables import DjmdContent

Expand Down
21 changes: 16 additions & 5 deletions pyrekordbox/db6/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,26 @@

import math
import struct
import numpy as np
from enum import IntEnum
from datetime import datetime
from enum import IntEnum
from typing import List
from sqlalchemy import Column, Integer, VARCHAR, BigInteger, SmallInteger, Text, Float
from sqlalchemy import ForeignKey, TypeDecorator
from sqlalchemy.orm import DeclarativeBase, relationship, backref, mapped_column, Mapped

import numpy as np
from sqlalchemy import (
VARCHAR,
BigInteger,
Column,
Float,
ForeignKey,
Integer,
SmallInteger,
Text,
TypeDecorator,
)
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.inspection import inspect
from sqlalchemy.orm import DeclarativeBase, Mapped, backref, mapped_column, relationship

from .registry import RekordboxAgentRegistry

__all__ = [
Expand Down
9 changes: 5 additions & 4 deletions pyrekordbox/mysettings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

import re
from pathlib import Path

from . import structs
from .file import (
FILES,
SettingsFile,
MySettingFile,
MySetting2File,
DjmMySettingFile,
DevSettingFile,
DjmMySettingFile,
MySetting2File,
MySettingFile,
SettingsFile,
)

RE_MYSETTING = re.compile(".*SETTING[0-9]?.DAT$")
Expand Down
4 changes: 3 additions & 1 deletion pyrekordbox/mysettings/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"""Rekordbox My-Setting file handlers."""

import re
from construct import Struct
from collections.abc import MutableMapping

from construct import Struct

from . import structs

# fmt: off
Expand Down
6 changes: 4 additions & 2 deletions pyrekordbox/rbxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import logging
import os.path
import urllib.parse
import xml.etree.cElementTree as xml
from abc import abstractmethod
from collections import abc
import xml.etree.cElementTree as xml

import bidict

from .utils import pretty_xml

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -658,7 +660,7 @@ def entries(self):

@property
def key_type(self):
"""str: The type of key used by the playlist node"""
"""str: The type of key used by the playlist node."""
return NODE_KEYTYPE_MAPPING.get(self._element.attrib.get("KeyType"))

@property
Expand Down
7 changes: 4 additions & 3 deletions pyrekordbox/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

import os
import warnings
import psutil
from xml.dom import minidom
import xml.etree.cElementTree as xml
from xml.dom import minidom

import psutil

warnings.simplefilter("always", DeprecationWarning)

Expand Down Expand Up @@ -122,7 +123,7 @@ def get_rekordbox_agent_pid(raise_exec=False):


def pretty_xml(element, indent=None, encoding="utf-8"):
"""Generates a formatted string of an XML element.
r"""Generates a formatted string of an XML element.
Parameters
----------
Expand Down
2 changes: 1 addition & 1 deletion pyrekordbox/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Author: Dylan Jones
# Date: 2022-04-10

from .utils import warn_deprecated as _warn_deprecated
from .rbxml import * # noqa: F401, F403
from .utils import warn_deprecated as _warn_deprecated

_warn_deprecated("pyrekordbox.xml", "pyrekordbox.rbxml", remove_in="0.4.0")
4 changes: 3 additions & 1 deletion tests/test_anlz.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
# Date: 2023-02-01

import os
import pytest

import numpy as np
import pytest
from numpy.testing import assert_equal

from pyrekordbox import anlz

TEST_ROOT = os.path.join(os.path.dirname(os.path.dirname(__file__)), ".testdata")
Expand Down
6 changes: 4 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# Author: Dylan Jones
# Date: 2023-10-02

import pytest
import json
from pathlib import Path
from pyrekordbox.config import update_config, get_config

import pytest

from pyrekordbox.config import get_config, update_config

RB_SETTING = """<?xml version="1.0" encoding="UTF-8"?>
<PROPERTIES><VALUE name="masterDbDirectory" val="{db_dir}"/></PROPERTIES>
Expand Down
Loading

0 comments on commit a6d0c58

Please sign in to comment.