Skip to content

Commit

Permalink
Add ruff for linting, remove flake8, remove isort, remove pylint (#2069)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsheni authored Jun 17, 2024
1 parent a8c45ac commit 407114c
Show file tree
Hide file tree
Showing 111 changed files with 4,495 additions and 6,154 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vscode/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,13 @@ check-dependencies: ## test if there are any broken dependencies
pip check

.PHONY: lint
lint: ## check style with flake8 and isort
lint:
invoke lint

.PHONY: fix-lint
fix-lint: ## fix lint issues using autoflake, autopep8, and isort
find sdv tests -name '*.py' | xargs autoflake --in-place --remove-all-unused-imports --remove-unused-variables
autopep8 --in-place --recursive --aggressive sdv tests
isort --apply --atomic sdv tests
fix-lint:
ruff check --fix .
ruff format


# TEST TARGETS
Expand Down
83 changes: 47 additions & 36 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,32 +86,7 @@ dev = [
'Jinja2>=2,<4',

# style check
'flake8>=3.7.7,<8',
'flake8-absolute-import>=1.0,<2',
'flake8-builtins>=1.5.3,<3',
'flake8-comprehensions>=3.6.1,<4',
'flake8-debugger>=4.0.0,<5',
'flake8-docstrings>=1.5.0,<2',
'flake8-eradicate>=1.1.0,<2',
'flake8-fixme>=1.1.1,<1.2',
'flake8-mock>=0.3,<1',
'flake8-multiline-containers>=0.0.18,<0.1',
'flake8-mutable>=1.2.0,<1.3',
'flake8-expression-complexity>=0.0.9,<0.1',
'flake8-print>=4.0.0,<4.1',
'flake8-pytest-style>=2.0.0,<3',
'flake8-quotes>=3.3.0,<4',
'flake8-sfs>=0.0.3,<2',
'flake8-variables-names>=0.0.4,<0.1',
'dlint>=0.11.0,<1',
'isort>=5.13.2,<6',
'pandas-vet>=0.2.3,<2024',
'pep8-naming>=0.12.1,<1',
'pydocstyle>=6.1.1,<7',

# fix style issues
'autoflake>=1.1,<3',
'autopep8>=1.4.3,<3',
'ruff>=0.4.5,<1',

# distribute on PyPI
'twine>=1.10.0,<6',
Expand Down Expand Up @@ -190,19 +165,55 @@ filename = "sdv/__init__.py"
search = "__version__ = '{current_version}'"
replace = "__version__ = '{new_version}'"

[tool.isort]
line_length = 99
lines_between_types = 0
multi_line_output = 4
use_parentheses = true

[tool.pydocstyle]
convention = 'google'
add-ignore = ['D105', 'D107', 'D407', 'D417']

[tool.pytest.ini_options]
addopts = "--ignore=pyproject.toml"

[build-system]
requires = ['setuptools', 'wheel']
build-backend = 'setuptools.build_meta'

[tool.ruff]
preview = true
line-length = 100
indent-width = 4
src = ["sdv"]
exclude = [
"docs",
".tox",
".git",
"__pycache__",
".ipynb_checkpoints"
]

[tool.ruff.lint]
select = [
# Pyflakes
"F",
# Pycodestyle
"E",
"W",
"D200",
# isort
"I001",
]
ignore = [
"E501",
"D107", # Missing docstring in __init__
"D417", # Missing argument descriptions in the docstring, this is a bug from pydocstyle: https://github.com/PyCQA/pydocstyle/issues/449
]

[tool.ruff.format]
quote-style = "single"
indent-style = "space"
preview = true
docstring-code-format = true
docstring-code-line-length = "dynamic"

[tool.ruff.lint.isort]
known-first-party = ["sdv"]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401", "E402", "F403", "F405", "E501", "I001"]

[tool.ruff.lint.pydocstyle]
convention = "google"
23 changes: 6 additions & 17 deletions scripts/release_notes_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
'maintenance': 'Maintenance',
'customer success': 'Customer Success',
'documentation': 'Documentation',
'misc': 'Miscellaneous'
'misc': 'Miscellaneous',
}
ISSUE_LABELS = [
'documentation',
'maintenance',
'internal',
'bug',
'feature request',
'customer success'
'customer success',
]
NEW_LINE = '\n'
GITHUB_URL = 'https://api.github.com/repos/sdv-dev/sdv'
Expand All @@ -30,14 +30,8 @@

def _get_milestone_number(milestone_title):
url = f'{GITHUB_URL}/milestones'
headers = {
'Authorization': f'Bearer {GITHUB_TOKEN}'
}
query_params = {
'milestone': milestone_title,
'state': 'all',
'per_page': 100
}
headers = {'Authorization': f'Bearer {GITHUB_TOKEN}'}
query_params = {'milestone': milestone_title, 'state': 'all', 'per_page': 100}
response = requests.get(url, headers=headers, params=query_params)
body = response.json()
if response.status_code != 200:
Expand All @@ -52,17 +46,12 @@ def _get_milestone_number(milestone_title):


def _get_issues_by_milestone(milestone):
headers = {
'Authorization': f'Bearer {GITHUB_TOKEN}'
}
headers = {'Authorization': f'Bearer {GITHUB_TOKEN}'}
# get milestone number
milestone_number = _get_milestone_number(milestone)
url = f'{GITHUB_URL}/issues'
page = 1
query_params = {
'milestone': milestone_number,
'state': 'all'
}
query_params = {'milestone': milestone_number, 'state': 'all'}
issues = []
while True:
query_params['page'] = page
Expand Down
19 changes: 16 additions & 3 deletions sdv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,21 @@
from types import ModuleType

from sdv import (
constraints, data_processing, datasets, evaluation, io, lite, logging, metadata, metrics,
multi_table, sampling, sequential, single_table, version)
constraints,
data_processing,
datasets,
evaluation,
io,
lite,
logging,
metadata,
metrics,
multi_table,
sampling,
sequential,
single_table,
version,
)

__all__ = [
'constraints',
Expand All @@ -33,7 +46,7 @@
'sampling',
'sequential',
'single_table',
'version'
'version',
]


Expand Down
20 changes: 6 additions & 14 deletions sdv/_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Miscellaneous utility functions."""

import operator
import uuid
import warnings
Expand Down Expand Up @@ -122,11 +123,7 @@ def _validate_datetime_format(column, datetime_format):
Series of booleans, with True if the value matches the format, False if not.
"""
pandas_datetime_format = datetime_format.replace('%-', '%')
datetime_column = pd.to_datetime(
column,
errors='coerce',
format=pandas_datetime_format
)
datetime_column = pd.to_datetime(column, errors='coerce', format=pandas_datetime_format)
valid = pd.isna(column) | ~pd.isna(datetime_column)

return set(column[~valid])
Expand Down Expand Up @@ -253,7 +250,7 @@ def check_sdv_versions_and_warn(synthesizer):
public_missmatch = current_public_version != fitted_public_version
enterprise_missmatch = current_enterprise_version != fitted_enterprise_version

if (public_missmatch or enterprise_missmatch):
if public_missmatch or enterprise_missmatch:
static_message = (
'The latest bug fixes and features may not be available for this synthesizer. '
'To see these enhancements, create and train a new synthesizer on this version.'
Expand Down Expand Up @@ -346,23 +343,18 @@ def check_synthesizer_version(synthesizer, is_fit_method=False, compare_operator
static_message = 'Downgrading your SDV version is not supported.'
if is_fit_method:
static_message = (
'Fitting this synthesizer again is not supported. '
'Please create a new synthesizer.'
'Fitting this synthesizer again is not supported. ' 'Please create a new synthesizer.'
)

fit_public_version = getattr(synthesizer, '_fitted_sdv_version', None)
fit_enterprise_version = getattr(synthesizer, '_fitted_sdv_enterprise_version', None)

is_public_lower = _compare_versions(
current_public_version,
fit_public_version,
compare_operator
current_public_version, fit_public_version, compare_operator
)

is_enterprise_lower = _compare_versions(
current_enterprise_version,
fit_enterprise_version,
compare_operator
current_enterprise_version, fit_enterprise_version, compare_operator
)

if is_public_lower and is_enterprise_lower:
Expand Down
17 changes: 14 additions & 3 deletions sdv/constraints/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
"""SDV Constraints module."""

from sdv.constraints.base import Constraint
from sdv.constraints.tabular import (
FixedCombinations, FixedIncrements, Inequality, Negative, OneHotEncoding, Positive, Range,
ScalarInequality, ScalarRange, Unique, create_custom_constraint_class)
FixedCombinations,
FixedIncrements,
Inequality,
Negative,
OneHotEncoding,
Positive,
Range,
ScalarInequality,
ScalarRange,
Unique,
create_custom_constraint_class,
)

__all__ = [
'create_custom_constraint_class',
Expand All @@ -16,5 +27,5 @@
'Negative',
'Positive',
'OneHotEncoding',
'Unique'
'Unique',
]
Loading

0 comments on commit 407114c

Please sign in to comment.