Skip to content
Merged
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: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.py[cod]
__pycache__/
venv/
.venv/
.tox/
.vscode/
/build/
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ exclude: >

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.0.276'
rev: 'v0.9.7'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --show-fixes]

- repo: https://github.com/ambv/black
rev: 23.3.0
rev: 24.8.0
hooks:
- id: black

Expand Down
55 changes: 55 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
checkfiles = src/ tests/

help:
@echo "FindPython development makefile"
@echo
@echo "Usage: make <target>"
@echo "Targets:"
@echo " up Updates dev/test dependencies"
@echo " deps Ensure dev/test dependencies are installed"
@echo " check Checks that build is sane"
@echo " test Runs all tests"
@echo " style Auto-formats the code"
@echo " lint Auto-formats the code and check type hints"

up:
pdm update --verbose

deps:
ifeq ($(wildcard .venv),)
pdm install --verbose
else
pdm install
endif

_check:
pdm run ruff format --check $(checkfiles)
pdm run ruff check $(checkfiles)
pdm run mypy $(checkfiles)
check: deps _build _check

_style:
pdm run ruff format $(checkfiles)
pdm run ruff check --fix $(checkfiles)
style: deps _style

_lint:
pdm run ruff format $(checkfiles)
pdm run ruff check --fix $(checkfiles)
pdm run mypy $(checkfiles)
lint: deps _build _lint

_test:
pdm run pytest -s tests
test: deps _test

_build:
rm -fR dist/
pdm build
build: deps _build

# Usage::
# make venv version=3.12
venv:
pdm venv create $(version)
pdm run pip install --upgrade pip
105 changes: 60 additions & 45 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]

[project.urls]
Expand Down Expand Up @@ -61,6 +62,11 @@ exclude = '''

[tool.ruff]
line-length = 90
src = ["src"]
exclude = ["tests/fixtures"]
target-version = "py38"

[tool.ruff.lint]
select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
Expand All @@ -72,14 +78,13 @@ select = [
"YTT", # flake8-2020
]
extend-ignore = ["B018", "B019"]
src = ["src"]
exclude = ["tests/fixtures"]
target-version = "py37"

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

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


[[tool.mypy.overrides]]
module = "_winreg"
ignore_missing_imports = true
9 changes: 5 additions & 4 deletions src/findpython/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""
FindPython
~~~~~~~~~~
A utility to find python versions on your system
FindPython
~~~~~~~~~~
A utility to find python versions on your system
"""

from __future__ import annotations

from typing import TYPE_CHECKING, TypeVar
Expand Down Expand Up @@ -59,4 +60,4 @@ def register_provider(provider: P) -> P:
return provider


__all__ = ["Finder", "find", "find_all", "PythonVersion", "register_provider"]
__all__ = ["Finder", "PythonVersion", "find", "find_all", "register_provider"]
2 changes: 1 addition & 1 deletion src/findpython/pep514tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

from findpython.pep514tools.environment import find, findall, findone

__all__ = ["findall", "find", "findone"]
__all__ = ["find", "findall", "findone"]
7 changes: 4 additions & 3 deletions src/findpython/pep514tools/_registry.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# mypy: disable-error-code="attr-defined"
# -------------------------------------------------------------------------
# Copyright (c) Steve Dower
# All rights reserved.
Expand All @@ -6,10 +7,10 @@
# -------------------------------------------------------------------------

__all__ = [
"open_source",
"REGISTRY_SOURCE_CU",
"REGISTRY_SOURCE_LM",
"REGISTRY_SOURCE_LM_WOW6432",
"REGISTRY_SOURCE_CU",
"open_source",
]

import re
Expand All @@ -18,7 +19,7 @@
try:
import winreg
except ImportError:
import _winreg as winreg
import _winreg as winreg # type:ignore[no-redef]

REGISTRY_SOURCE_LM = 1
REGISTRY_SOURCE_LM_WOW6432 = 2
Expand Down
2 changes: 1 addition & 1 deletion src/findpython/pep514tools/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Distributed under the terms of the MIT License
# -------------------------------------------------------------------------

__all__ = ["Environment", "findall", "find", "findone"]
__all__ = ["Environment", "find", "findall", "findone"]

import sys

Expand Down
1 change: 1 addition & 0 deletions src/findpython/providers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This package contains all the providers for the pythonfinder module.
"""

from __future__ import annotations

from findpython.providers.asdf import AsdfProvider
Expand Down
15 changes: 12 additions & 3 deletions src/findpython/providers/asdf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
from __future__ import annotations

import os
import typing as t
from pathlib import Path
from typing import TYPE_CHECKING

from findpython.providers.base import BaseProvider
from findpython.python import PythonVersion

if TYPE_CHECKING:
import sys
from typing import Iterable

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self


class AsdfProvider(BaseProvider):
"""A provider that finds python installed with asdf"""
Expand All @@ -15,15 +24,15 @@ def __init__(self, root: Path) -> None:
self.root = root

@classmethod
def create(cls) -> t.Self | None:
def create(cls) -> Self | None:
asdf_root = os.path.expanduser(
os.path.expandvars(os.getenv("ASDF_DATA_DIR", "~/.asdf"))
)
if not os.path.exists(asdf_root):
return None
return cls(Path(asdf_root))

def find_pythons(self) -> t.Iterable[PythonVersion]:
def find_pythons(self) -> Iterable[PythonVersion]:
python_dir = self.root / "installs/python"
if not python_dir.exists():
return
Expand Down
Loading
Loading