Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ site/
venv/
.DS_Store
.venv

17 changes: 13 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ exclude: |
)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v4.6.0
hooks:
- id: check-yaml
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
rev: v0.6.9
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
- id: mypy
files: ^src/
additional_dependencies: [types-requests, types-PyYAML]
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@


## Unreleased
### Added
- python 3.13 support
### Fixed Issues
- fixed peeringdb-py/#108: Dependency updates and modernization
### Removed
- python 3.8 support (end of life)


## 2.3.0
Expand Down Expand Up @@ -138,4 +144,4 @@
- lookup net by asn, ixnets to client
### Fixed
- get/whois commands honor --config
- fix #2, pass through settings to db
- fix #2, pass through settings to db
9 changes: 6 additions & 3 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Unreleased:
added: []
fixed: []
added:
- python 3.13 support
fixed:
- "Dependency updates and modernization (#108)"
changed: []
deprecated: []
removed: []
removed:
- python 3.8 support (end of life)
security: []
2.3.0:
added:
Expand Down
2 changes: 1 addition & 1 deletion Ctl/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0
2.3.0
2 changes: 0 additions & 2 deletions docs/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,5 +389,3 @@ Should return whether the database is fully migrated
Returns:

- bool


2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ This document describes the environment variables used to configure the PeeringD
### Logging Configuration

- **ALLOW_OTHER_LOGGERS**: To allow other loggers to be used (1 for true, 0 for false). Default is `0`.
- **LOG_LEVEL**: The python logging level to use. Default is `INFO`
- **LOG_LEVEL**: The python logging level to use. Default is `INFO`
4 changes: 0 additions & 4 deletions docs/local_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,3 @@ server {
}
}
```




1 change: 0 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ nav:
- API: 'api.md'

markdown_extensions: [abbr,def_list,footnotes,tables,admonition,nl2br,toc]

112 changes: 100 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@ description = "PeeringDB Django models"
readme = "README.md"
authors = [{ name = "PeeringDB", email = "[email protected]" }]
license = { text = "BSD-2-Clause" }
requires-python = ">=3.8"
requires-python = ">=3.9"

classifiers = [
"Development Status :: 5 - Production/Stable",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Framework :: Django :: 5.1",
"Framework :: Django :: 5.2",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"Intended Audience :: Telecommunications Industry",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Internet",
]
Expand All @@ -33,14 +34,8 @@ dependencies = [
"httpx>=0.24.1",
]

[project.scripts]
peeringdb = "peeringdb.cli:main"

[project.urls]
repository = "https://github.com/peeringdb/peeringdb-py"

[tool.uv]
dev-dependencies = [
[project.optional-dependencies]
dev = [
"django_peeringdb>=3.1.0",
"django>=4.2",
"pytest>=8",
Expand All @@ -49,6 +44,8 @@ dev-dependencies = [
"tox-gh-actions>=3",
"tox-uv>=1.13.0",
"mypy>=0.950",
"types-requests",
"types-PyYAML",
"pre-commit>=2.13",
"ruff>=0.1",
"markdown>=3",
Expand All @@ -60,12 +57,103 @@ dev-dependencies = [
"twine>=3",
]

[project.scripts]
peeringdb = "peeringdb.cli:main"

[project.urls]
repository = "https://github.com/peeringdb/peeringdb-py"


[tool.ruff]
line-length = 88
target-version = "py39"

[tool.ruff.lint]
extend-select = [
"I", # isort
"UP", # pyupgrade
"UP", # pyupgrade
"I", # isort
"F", # Pyflakes
"E", # pycodestyle errors
"W", # pycodestyle warnings
"C90", # mccabe complexity
"N", # pep8-naming
]
exclude = [
".git",
".venv",
"__pycache__",
"build",
"dist",
"*.egg-info",
]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"

[tool.ruff.lint.isort]
known-first-party = ["peeringdb"]
force-single-line = false
split-on-trailing-comma = true

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

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"] # Allow unused imports in __init__.py
"tests/**/*" = ["S101"] # Allow assert statements in tests

[tool.mypy]
python_version = "3.9"
warn_return_any = false
warn_unused_configs = true
disallow_untyped_defs = false
disallow_incomplete_defs = false
check_untyped_defs = true
disallow_untyped_decorators = false
no_implicit_optional = true
warn_redundant_casts = true
warn_unused_ignores = false
warn_no_return = true
warn_unreachable = true
strict_equality = true
show_error_codes = true
# Start with basic type checking, can be made stricter later
strict = false

[[tool.mypy.overrides]]
module = [
"django.*",
"django_peeringdb.*",
"confu.*",
"munge.*",
"twentyc.*",
"yaml.*",
"httpx.*"
]
ignore_missing_imports = true

# Allow some dynamic attribute access for these modules that use metaclasses
[[tool.mypy.overrides]]
module = [
"peeringdb.backend",
"peeringdb.private",
"peeringdb._update"
]
disable_error_code = ["attr-defined"]

# Ignore issues in __init__ (global checks and dynamic imports)
[[tool.mypy.overrides]]
module = "peeringdb.__init__"
disable_error_code = ["unreachable", "import-untyped"]

# Allow complex issues in commands module
[[tool.mypy.overrides]]
module = "peeringdb.commands"
disable_error_code = ["attr-defined", "index", "arg-type"]


[build-system]
requires = ["hatchling"]
Expand Down
37 changes: 23 additions & 14 deletions src/peeringdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@
import sys
from importlib import import_module
from importlib import metadata as importlib_metadata
from typing import TYPE_CHECKING, Optional, Union

if TYPE_CHECKING:
from peeringdb.backend import Interface

from peeringdb.util import get_log_level, str_to_bool

__version__ = importlib_metadata.version("peeringdb")
_log_level = logging.INFO
__version__: str = importlib_metadata.version("peeringdb")
_log_level: int = logging.INFO


def _config_logs(level=None, name=None, allow_other_loggers=False):
def _config_logs(
level: Optional[Union[str, int]] = None,
name: Optional[str] = None,
allow_other_loggers: Union[bool, str] = False,
) -> None:
"""
Set up or change logging configuration.

Expand Down Expand Up @@ -57,34 +65,34 @@ class BackendError(Exception):


# Map external module names to adaptor modules
SUPPORTED_BACKENDS = {
SUPPORTED_BACKENDS: dict[str, str] = {
"django_peeringdb": "django_peeringdb.client_adaptor",
}

__backend = None
__backend: Optional[tuple["Interface", tuple[str, str]]] = None


def backend_initialized():
def backend_initialized() -> bool:
return __backend is not None


def _get():
def _get() -> tuple["Interface", tuple[str, str]]:
global __backend
if __backend:
return __backend
else:
raise BackendError("Backend not initialized")
return __backend # type: ignore[unreachable]
# mypy has trouble with global analysis here
raise BackendError("Backend not initialized")


def get_backend():
def get_backend() -> "Interface":
return _get()[0]


def get_backend_info():
def get_backend_info() -> tuple[str, str]:
return _get()[1]


def initialize_backend(name, **kwargs):
def initialize_backend(name: str, **kwargs: Union[str, int, bool, dict]) -> None:
global __backend
if __backend:
raise BackendError("Backend already initialized")
Expand All @@ -105,4 +113,5 @@ def initialize_backend(name, **kwargs):
# TODO
# def is_valid_backend(backend): ...

# namespace imports
# namespace imports - import client at the end to avoid circular imports
from peeringdb import client # noqa: E402
6 changes: 3 additions & 3 deletions src/peeringdb/_debug/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# import pdb


def log_validation_errors(B, e, obj, k):
def log_validation_errors(backend, e, obj, k):
log = logging.getLogger("peeringdb.sync")
log.debug(f"{e} : errors: {e.message_dict}")
for k, v in e.message_dict.items():
field = B.get_field(obj, k)
field = backend.get_field(obj, k)
try:
log.debug(f"{k}: {getattr(obj, k)}, dict: {field.__dict__}")
except B.object_missing_error():
except backend.object_missing_error():
log.debug(f"{k}: Missing Object, dict: {field.__dict__}")


Expand Down
Loading
Loading