Skip to content

Commit

Permalink
Merge pull request #155 from sbidoul/pre-commit-autoupdate-sbi
Browse files Browse the repository at this point in the history
Pre commit autoupdate
  • Loading branch information
sbidoul authored Jul 2, 2024
2 parents ad8b410 + 1f9f883 commit 44419fa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ jobs:
python-version: "3.12"
python: python
# macos
- os: "macos-latest"
python-version: "3.6"
python: python
- os: "macos-latest"
python-version: "3.7"
python: python
- os: "macos-latest"
python-version: "3.8"
python: python
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
rev: v1.10.1
hooks:
- id: mypy
args: ["--strict"]
exclude: '^(docs|tasks|tests)|setup\.py'
additional_dependencies: ["httpx", "packaging", "typer>=0.3.2"]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.3.2
rev: v0.5.0
hooks:
- id: ruff
- id: ruff-format
32 changes: 25 additions & 7 deletions src/pip_deepfreeze/fixup-vcs-direct-urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
import sys
from pathlib import Path
from typing import List
from typing import List, Union

try:
import importlib.metadata as importlib_metadata
Expand All @@ -27,6 +27,20 @@ def _canonicalize_name(name: str) -> str:
return _canonicalize_regex.sub("_", name).lower()


def find_direct_url_path(
dist: importlib_metadata.Distribution,
) -> Union[Path, None]:
canonical_name = _canonicalize_name(dist.metadata["Name"])
package_paths = importlib_metadata.files(canonical_name)
if not package_paths:
return None
for package_path in package_paths:
if package_path.name == "direct_url.json":
if package_path.parent.name == f"{canonical_name}-{dist.version}.dist-info":
return Path(package_path.locate())
return None


def fixup_vcs_direct_url(dist: importlib_metadata.Distribution) -> None:
"""Fixup VCS direct_url.json to set a fake commit_id when it is different from
requested_revision.
Expand All @@ -37,13 +51,17 @@ def fixup_vcs_direct_url(dist: importlib_metadata.Distribution) -> None:
cache it.
"""
canonical_name = _canonicalize_name(dist.metadata["Name"])
direct_url_path = Path(
dist.locate_file(f"{canonical_name}-{dist.version}.dist-info/direct_url.json")
)
if not direct_url_path.is_file():
return
try:
direct_url = json.loads(direct_url_path.read_text(encoding="utf-8"))
direct_url_json = dist.locate_file(
f"{canonical_name}-{dist.version}.dist-info/direct_url.json"
).read_text()
except FileNotFoundError:
return # no direct_url.json metadata
direct_url_path = find_direct_url_path(dist)
if not direct_url_path:
return # direct_url.json not an actual filesystem path
try:
direct_url = json.loads(direct_url_json)
except Exception:
return # invalid direct_url.json
vcs_info = direct_url.get("vcs_info")
Expand Down

0 comments on commit 44419fa

Please sign in to comment.