Skip to content

Commit

Permalink
add actions updater (#59)
Browse files Browse the repository at this point in the history
* add actions updater

* revert back to py3.8 typing

* convert to ruff

* poetry lock
  • Loading branch information
grizz authored Sep 29, 2024
1 parent 21160de commit b2af280
Show file tree
Hide file tree
Showing 33 changed files with 529 additions and 628 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/actions-updater.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: GitHub Actions Version Updater

# Controls when the action will run.
on:
schedule:
# Automatically run on every Sunday
- cron: '0 0 * * 0'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
# [Required] Access token with `workflow` scope.
token: ${{ secrets.WORKFLOW_SECRET }}

- name: Run GitHub Actions Version Updater
uses: saadmk11/github-actions-version-updater@v0.8.1
with:
# [Required] Access token with `workflow` scope.
token: ${{ secrets.WORKFLOW_SECRET }}
36 changes: 9 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,16 @@ exclude: |
)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: check-yaml
- id: trailing-whitespace
# - repo: https://github.com/astral-sh/ruff-pre-commit
# # Ruff version.
# rev: v0.0.275
# hooks:
# - id: ruff
- repo: local
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.8
hooks:
- id: system
name: isort
entry: poetry run isort .
language: system
pass_filenames: false
- repo: local
hooks:
- id: pyupgrade
name: pyupgrade
entry: poetry run pyupgrade --py37-plus
language: python
types: [python]
pass_filenames: true
- repo: local
hooks:
- id: system
name: Black
entry: poetry run black .
language: system
pass_filenames: false
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
228 changes: 119 additions & 109 deletions poetry.lock

Large diffs are not rendered by default.

30 changes: 24 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Internet",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries",
Expand All @@ -29,12 +30,12 @@ rdap = "rdap.cli:main"
[tool.poetry.dependencies]
python = "^3.8"
requests = ">=2.25.1"
munge = {version = ">=1.3", extras = ["yaml"]}
munge = { version = ">=1.3", extras = ["yaml"] }
pydantic = ">=2.8.2"
googlemaps = ">=4.10"
phonenumbers = ">=8.13.0"

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
# testing
coverage = ">=5"
pytest = ">=6"
Expand All @@ -45,12 +46,10 @@ tox = ">=3.20"
tox-gh-actions = ">2.9.1"

# linting
black = ">=20"
isort = ">=5.7"
flake8 = ">=3.8"
bandit = ">=1.6.2"
mypy = ">=0.950"
pre-commit = ">=2.13"
pyupgrade = ">=2.19"
ruff = ">=0.1"

# docs
markdown = "*"
Expand All @@ -60,6 +59,25 @@ mkdocs = ">=1.2.3"
[tool.poetry.plugins."markdown.extensions"]
pymdgen = "pymdgen.md:Extension"


[tool.ruff]

select = [
"I", # isort
"UP",
]

[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = [
# at least this three should be fine in tests:
"S101", # asserts allowed in tests...
"ARG", # Unused function args -> fixtures nevertheless are functionally relevant...
"FBT", # Don't care about booleans as positional arguments in tests, e.g. via @pytest.mark.parametrize()
# The below are debateable
"PLR2004", # Magic value used in comparison, ...
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
7 changes: 7 additions & 0 deletions rdap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@

# objects to base namespace
from rdap.objects import RdapAsn

__all__ = [
"RdapClient",
"RdapException",
"RdapNotFoundError",
"RdapAsn",
]
32 changes: 12 additions & 20 deletions rdap/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@


class RIRAssignmentLookup:
"""
Fetch RIR assignement status lists from ripe and lookup
"""Fetch RIR assignement status lists from ripe and lookup
assignment per asn
Files will be downloaded from https://ftp.ripe.net/pub/stats/{rir}/delegated-{rir}-extended-latest
Expand All @@ -15,43 +14,40 @@ class RIRAssignmentLookup:
rir_lists = ["afrinic", "apnic", "arin", "lacnic", "ripencc"]

def parse_data(self, line):
"""
Parses a line from a data file and attempts to return the ASN
"""Parses a line from a data file and attempts to return the ASN
and assignment status
A line can parse multiple asns depending of the value in 5th
column.
Returns:
- `None` if no asn and status could be parsed
- `list<`dict`>` containing asns and status
"""
"""
parts = line.split("|")

try:
if parts[2] != "asn":
return
return None
except IndexError:
return
return None

try:
asn = parts[3]
count = int(parts[4])
status = parts[6].strip()
asns = None

asns = [{"asn": int(asn) + i, "status": status} for i in range(0, count)]
asns = [{"asn": int(asn) + i, "status": status} for i in range(count)]

return asns

except IndexError:
return
return None

def load_data(self, data_path=".", cache_days=1):
"""
Reads RIR assignment data into memory
"""Reads RIR assignment data into memory
This is called autoamtically by `get_status`
Expand All @@ -68,13 +64,13 @@ def load_data(self, data_path=".", cache_days=1):
- cache_days (`int`): maximum age of downloaded files before they will be
downloaded again
"""

if not hasattr(self, "_data_files"):
self._data_files = []

for rir in self.rir_lists:
rir_file_path = os.path.join(
data_path, f"delegated-{rir}-extended-latest"
data_path,
f"delegated-{rir}-extended-latest",
)
self.download_data(rir, rir_file_path, cache_days)
self._data_files.append(rir_file_path)
Expand All @@ -100,8 +96,7 @@ def load_data(self, data_path=".", cache_days=1):
return self._data

def download_data(self, rir, file_path, cache_days=1):
"""
Download RIR network assignment status data from RIPE
"""Download RIR network assignment status data from RIPE
https://ftp.ripe.net/pub/stats/{rir}/delegated-{rir}-extended-latesy
"""
# Only download/re-download the file if it doesn't exist or the file is older than a day django_settings.RIR_ALLOCATION_DATA_CACHE_DAYS
Expand All @@ -122,10 +117,7 @@ def download_data(self, rir, file_path, cache_days=1):
file.write(response.text)

def get_status(self, asn):
"""
Get RIR assignment status for an ASN
"""

"""Get RIR assignment status for an ASN"""
if not hasattr(self, "_data"):
self.load_data()

Expand Down
4 changes: 2 additions & 2 deletions rdap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def load_data(self, data):
self.insert(url, asn_range)

def insert(self, url, asn_range):
"Insert a service locator record."
"""Insert a service locator record."""
top = None
try:
bottom, top = map(int, asn_range.split("-"))
Expand All @@ -53,7 +53,7 @@ def insert(self, url, asn_range):
return service

def get_service(self, asn):
"Return service for asn. Raise LookupError if not found."
"""Return service for asn. Raise LookupError if not found."""
i = bisect_right(self._keys, asn)
# correct record will be the previous one
service = self._items[i - 1]
Expand Down
16 changes: 10 additions & 6 deletions rdap/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def add_options(parser, options):


class Context(munge.click.Context):
"""
command line interface context
"""
"""command line interface context"""

app_name = "rdap"
config_class = Config
Expand All @@ -45,13 +43,19 @@ def main(argv=None):
)
parser.add_argument("--output-format", help="output format (yaml, json, text)")
parser.add_argument(
"--show-requests", action="store_true", help="show all requests"
"--show-requests",
action="store_true",
help="show all requests",
)
parser.add_argument(
"--parse", action="store_true", help="parse data into object before display"
"--parse",
action="store_true",
help="parse data into object before display",
)
parser.add_argument(
"--normalize", action="store_true", help="normalize data before display"
"--normalize",
action="store_true",
help="normalize data before display",
)
parser.add_argument("--rir", action="store_true", help="display rir", default=False)
parser.add_argument(
Expand Down
Loading

0 comments on commit b2af280

Please sign in to comment.