Skip to content

Commit

Permalink
chore: get rid of setup.py/setup.cfg
Browse files Browse the repository at this point in the history
And misc maintenace updates:

* Move all of the configs to pyproject.toml instead of 3 config.
* Remove isort/black/flake8 in favor of ruff
* Use local mypy hook instead of mirrors-mypy, as it hides a lot of errors.
* Changes line-length to 88 (default in ruff). Luckily, this did not change any diff.
* Add support for Python 3.12, and run tests in CI for 3.12.
  • Loading branch information
skshetry committed Mar 25, 2024
1 parent d4852de commit 0c64924
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 173 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check-test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: ["3.9", "3.10", "3.11"]
python: ["3.9", "3.10", "3.11", "3.12"]
fail-fast: false
timeout-minutes: 10
steps:
Expand All @@ -52,7 +52,7 @@ jobs:
- name: Install
run: |
pip install --upgrade pip setuptools wheel
pip install pre-commit .[tests]
pip install pre-commit .[dev]
- run: pre-commit run pylint -a -v --show-diff-on-failure
- name: Run tests
run: |
Expand Down
42 changes: 11 additions & 31 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,24 @@ repos:
- id: check-merge-conflict
- id: check-yaml
exclude: examples/layouts
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: sort-simple-yaml
- id: trailing-whitespace
- repo: 'https://github.com/pycqa/flake8'
rev: 6.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.3.3'
hooks:
- id: flake8
args:
- '-j8'
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-debugger
- flake8-string-format
- repo: 'https://github.com/psf/black'
rev: 23.9.1
hooks:
- id: black
- repo: 'https://github.com/PyCQA/isort'
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]
- repo: 'https://github.com/pre-commit/mirrors-mypy'
rev: v1.5.1
hooks:
- id: mypy
additional_dependencies:
- types-requests
- types-six
- types-PyYAML
- pydantic
- types-filelock
- types-tabulate
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: local
hooks:
- id: mypy
name: mypy
entry: mypy
language: system
types: [python]
require_serial: true
- id: pylint
name: pylint
entry: pylint -v
Expand Down
3 changes: 2 additions & 1 deletion gto/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ def get_events(
self, direct=True, indirect=True, ascending=False
) -> Sequence[BaseEvent]: # pylint: disable=unused-argument
return sorted(
self.assignments + self.unassignments if direct else [], key=lambda e: e.created_at # type: ignore
self.assignments + self.unassignments if direct else [], # type: ignore
key=lambda e: e.created_at,
)[:: 1 if ascending else -1]

@property
Expand Down
2 changes: 1 addition & 1 deletion gto/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def inner(ctx, *iargs, **ikwargs):
raise typer.Exit(1) from e
finally:
# TODO: analytics
error # pylint: disable=pointless-statement
error # pylint: disable=pointless-statement # noqa: B018
# send_cli_call(cmd_name, error_msg=error, **res)

return inner
Expand Down
8 changes: 4 additions & 4 deletions gto/git_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from itertools import chain
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Optional, Union
from typing import Iterator, Optional, Union

from scmrepo.exceptions import SCMError
from scmrepo.git import Git, SyncStatus
Expand Down Expand Up @@ -46,7 +46,7 @@ def from_url(
if os.path.exists(url_or_scm):
scm = Git(url_or_scm)
try:
scm.dir
scm.dir # noqa: B018
except SCMError as e:
scm.close()
raise NoRepo(url_or_scm) from e
Expand Down Expand Up @@ -103,12 +103,12 @@ def _call_commit_push(


@contextmanager
def cloned_git_repo(url: str) -> Git:
def cloned_git_repo(url: str) -> Iterator[Git]:
with TemporaryDirectory() as tmp_dir:
logging.debug("create temporary directory %s", tmp_dir)
scm = Git.clone(url, tmp_dir)
try:
scm.dir
scm.dir # noqa: B018
except SCMError as e:
scm.close()
raise NoRepo(url) from e
Expand Down
2 changes: 1 addition & 1 deletion gto/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def check_if_path_exists(
if scm is None:
return Path(path).exists()
try:
fs = scm.get_fs(ref)
fs = scm.get_fs(ref) # type: ignore[arg-type]
return fs.exists(str(path))
except SCMError:
return False
Expand Down
1 change: 1 addition & 0 deletions gto/log.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Loggers used in other parts of GTO
"""

import logging.config

from gto.config import CONFIG
Expand Down
3 changes: 2 additions & 1 deletion gto/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def find_artifact(
all_branches=all_branches,
all_commits=all_commits,
).find_artifact(
name, create_new=create_new # type: ignore
name, # type: ignore
create_new=create_new,
)

def register( # pylint: disable=too-many-locals
Expand Down
2 changes: 1 addition & 1 deletion gto/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def is_valid(cls, version):
return False

@classmethod
def parse(cls, version: str) -> "SemVer":
def parse(cls, version: str) -> "semver.VersionInfo":
"""
Parse version string to a Version instance.
Expand Down
106 changes: 105 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,114 @@
[build-system]
requires = ["setuptools>=48", "setuptools_scm[toml]>=6.3.1", "setuptools_scm_git_archive==1.4.1"]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=61", "setuptools_scm[toml]>=7"]

[project]
name = "gto"
description = "Version and deploy your models following GitOps principles"
readme = "README.md"
license = {text = "Apache License 2.0"}
authors = [{name = "Alexander Guschin", email = "[email protected]"}]
keywords = ["git", "repo", "repository", "artifact", "registry", "developer-tools", "collaboration"]
classifiers = [
"Development Status :: 2 - Pre-Alpha",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
requires-python = ">=3.9"
dynamic = ["version"]
dependencies = [
"entrypoints",
"funcy",
# pydantic.v1.parse_obj is broken in ==2.0.0:
# https://github.com/pydantic/pydantic/issues/6361
"pydantic>=1.9.0,<3,!=2.0.0",
"rich",
"ruamel.yaml",
"scmrepo>=3,<4",
"semver>=2.13.0",
"tabulate>=0.8.10",
"typer>=0.4.1",
]

[project.urls]
Issues = "https://github.com/iterative/gto/issues"
Source = "https://github.com/iterative/gto"

[project.optional-dependencies]
tests = [
"freezegun",
"pytest",
"pytest-cov",
"pytest-mock",
"pytest-test-utils",
]
dev = [
"gto[tests]",
"mypy==1.9.0",
"pylint==3.1.0",
"types-PyYAML",
"types-filelock",
"types-freezegun",
"types-requests",
"types-setuptools",
"types-six",
"types-tabulate",
]

[project.scripts]
gto = "gto.cli:app"

[project.entry-points."gto.enrichment"]
gto = "gto.index:GTOEnrichment"

[tool.setuptools_scm]
write_to = "gto/_gto_version.py"

[tool.pytest.ini_options]
addopts = "-rav --durations=0 --cov=gto --cov-report=term-missing --cov-report=xml"
log_level = "debug"
markers = [
"long: Marks long-running tests",
]
testpaths = ["tests"]

[tool.mypy]
# Error output
show_column_numbers = true
show_error_codes = true
show_error_context = true
show_traceback = true
pretty = true
disable_error_code = ["misc"]
plugins = ["pydantic.mypy"]
# See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports.
ignore_missing_imports = true
check_untyped_defs = false
# Warnings
warn_no_return = true
warn_redundant_casts = true
warn_unreachable = true

[tool.mypy-overrides]
ignore_missing_imports = true
module = ["freezegun.*"]

[tool.ruff]
output-format = "full"
show-fixes = true

[tool.ruff.lint]
extend-select = ["I", "B", "C4", "T10", "Q"]

[tool.ruff.lint.mccabe]
max-complexity = 15

[tool.ruff.lint.isort]
known-first-party = ["gto", "tests"]

[tool.pylint.master]
extension-pkg-whitelist = ["pydantic", "pytest-lazy-fixture", "pytest"]
load-plugins= ["pylint.extensions.no_self_use"]
Expand Down
58 changes: 0 additions & 58 deletions setup.cfg

This file was deleted.

Loading

0 comments on commit 0c64924

Please sign in to comment.