Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix The 'importlib-resources; python_version < "3.9"' distribution was not found and is required by keyring #108

Merged
merged 22 commits into from
Jan 27, 2024
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
27 changes: 27 additions & 0 deletions .changelog/_unreleased.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[[entries]]
id = "69eb006e-0206-4aea-87fa-69bf2000a3f3"
type = "improvement"
description = "Get rid of deprecated `nr.util` dependency by placing all the required bits of code into Slap itself"
author = "@NiklasRosenstein"
pr = "https://github.com/NiklasRosenstein/slap/pull/108"

[[entries]]
id = "a685b161-8d42-435d-8edd-bdb9be130454"
type = "improvement"
description = "Add `Once.flush()` to use that instead of `.get(resupply=True)`"
author = "@NiklasRosenstein"
pr = "https://github.com/NiklasRosenstein/slap/pull/108"

[[entries]]
id = "712b2efd-32e6-4ed6-b131-4669d36fc951"
type = "improvement"
description = "Use `importlib-metadata` package over `pkg_resources`"
author = "@NiklasRosenstein"
pr = "https://github.com/NiklasRosenstein/slap/pull/108"

[[entries]]
id = "2b4061fd-0028-4520-8e76-f7926c1c6ff7"
type = "improvement"
description = "Python 3.12 support"
author = "@NiklasRosenstein"
pr = "https://github.com/NiklasRosenstein/slap/pull/108"
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ ignore=
W504,
# whitespace before ':'
E203,
# multiple statements on one line (def)
E704,
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
Expand Down
14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ Homepage = "https://github.com/NiklasRosenstein/slap"
Repository = "https://github.com/NiklasRosenstein/slap.git"

[tool.poetry.dependencies]
python = ">=3.10,<3.12"
python = ">=3.10,<3.13"
beautifulsoup4 = "^4.10.0"
cleo = ">=1.0.0a4"
"databind" = "^4.4.0"
flit = "^3.6.0"
"nr.util" = ">=0.8.12,<1.0.0"
poetry-core = ">=1.7,<1.8"
ptyprocess = "^0.7.0"
pygments = "^2.11.2"
Expand All @@ -40,13 +39,14 @@ tqdm = "^4.64.0"
build = "^0.10.0"
"nr.python.environment" = "^0.1.4"
gitpython = "^3.1.31"
"nr.stream" = "^1.1.5"

[tool.poetry.dev-dependencies]
black = "^22.3.0"
flake8 = "^4.0.1"
isort = "^5.10.1"
mypy = "^0.931"
pytest = "^7.1.1"
black = "^24.1.0"
flake8 = "^7.0.0"
isort = "^5.13.1"
mypy = "^1.8.0"
pytest = "^7.4.4"
types-beautifulsoup4 = "^4.10.0"
types-pygments = "^2.9.16"
types-PyYAML = "^6.0.3"
Expand Down
12 changes: 5 additions & 7 deletions src/slap/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
from slap.util.strings import split_by_commata

if t.TYPE_CHECKING:
from nr.util.functional import Once

from slap.configuration import Configuration
from slap.project import Project
from slap.repository import Repository
from slap.util.once import Once

__all__ = ["Command", "argument", "option", "IO", "Application"]
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -116,7 +115,7 @@ def render_error(self, error: Exception, io: IO) -> None:
def _configure_io(self, io: IO) -> None:
import logging

from nr.util.logging.formatters.terminal_colors import TerminalColorFormatter
from slap.util.logging import TerminalColorFormatter

fmt = "<fg=bright black>%(message)s</fg>"
if io.input.has_parameter_option("-vvv"):
Expand Down Expand Up @@ -172,7 +171,7 @@ class Application:
cleo: CleoApplication

def __init__(self, directory: Path | None = None, name: str = "slap", version: str = __version__) -> None:
from nr.util.functional import Once
from slap.util.once import Once

self._directory = directory or Path.cwd()
self._repository: t.Optional[Repository] = None
Expand Down Expand Up @@ -230,9 +229,8 @@ def load_plugins(self) -> None:
plugins delivered immediately with Slap are enabled by default unless disabled explicitly with the `disable`
option."""

from nr.util.plugins import iter_entrypoints

from slap.plugins import ApplicationPlugin
from slap.util.plugins import iter_entrypoints

assert not self._plugins_loaded
self._plugins_loaded = True
Expand All @@ -242,7 +240,7 @@ def load_plugins(self) -> None:

logger.debug("Loading application plugins")

for plugin_name, loader in iter_entrypoints(ApplicationPlugin): # type: ignore[misc]
for plugin_name, loader in iter_entrypoints(ApplicationPlugin): # type: ignore[type-abstract]
if plugin_name in disable:
continue
try:
Expand Down
12 changes: 5 additions & 7 deletions src/slap/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from pathlib import Path

from databind.core.settings import Alias
from nr.util.weak import weak_property

from slap.util.weak_property import weak_property

if t.TYPE_CHECKING:
from poetry.core.constraints.version import Version # type: ignore[import]
Expand Down Expand Up @@ -55,19 +56,16 @@ def find_entry(self, entry_id: str) -> ChangelogEntry | None:

class ChangelogDeser(abc.ABC):
@abc.abstractmethod
def load(self, fp: t.TextIO, filename: str) -> Changelog:
...
def load(self, fp: t.TextIO, filename: str) -> Changelog: ...

def save(self, changelog: Changelog, fp: t.TextIO, filename: str) -> None:
fp.write(self.dump(changelog))

@abc.abstractmethod
def dump(self, changelog: Changelog) -> str:
...
def dump(self, changelog: Changelog) -> str: ...

@abc.abstractmethod
def dump_entry(self, entry: ChangelogEntry) -> str:
...
def dump_entry(self, entry: ChangelogEntry) -> str: ...


class TomlChangelogDeser(ChangelogDeser):
Expand Down
4 changes: 2 additions & 2 deletions src/slap/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from slap.util.toml_file import TomlFile

if t.TYPE_CHECKING:
from nr.util.functional import Once
from slap.util.once import Once

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -35,7 +35,7 @@ class Configuration:
raw_config: Once[dict[str, t.Any]]

def __init__(self, directory: Path) -> None:
from nr.util.functional import Once
from slap.util.once import Once

self.directory = directory
self.pyproject_toml = TomlFile(directory / "pyproject.toml")
Expand Down
2 changes: 1 addition & 1 deletion src/slap/ext/application/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def activate(self, app: Application, config: None) -> None:
app.cleo.add(self)

def handle(self) -> int:
from nr.util.stream import Stream
from nr.stream import Stream

from slap.install.installer import InstallOptions, PipInstaller, get_indexes_for_projects
from slap.python.environment import PythonEnvironment
Expand Down
2 changes: 1 addition & 1 deletion src/slap/ext/application/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ def handle(self) -> int:
except Exception as exc:
has_failures = True
self.line_error(f'warn: could not convert "{filename}": {exc}', "warning")
if self.io.is_very_verbose:
if self.io.is_very_verbose():
import traceback

self.line_error(traceback.format_exc())
Expand Down
3 changes: 1 addition & 2 deletions src/slap/ext/application/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import logging
import typing as t

from nr.util.plugins import load_entrypoint

from slap.application import Application, Command, option
from slap.check import Check, CheckResult
from slap.plugins import ApplicationPlugin, CheckPlugin
from slap.project import Project
from slap.util.plugins import load_entrypoint

logger = logging.getLogger(__name__)
DEFAULT_PLUGINS = ["changelog", "general", "poetry", "release"]
Expand Down
10 changes: 6 additions & 4 deletions src/slap/ext/application/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ def handle(self) -> int:
packages = (
"<i>none</i>"
if packages_list is None
else "[]"
if len(packages_list or []) == 0
else ", ".join(
f"<opt>{p.name} ({os.path.relpath(p.root, project.directory)})</opt>" for p in packages_list
else (
"[]"
if len(packages_list or []) == 0
else ", ".join(
f"<opt>{p.name} ({os.path.relpath(p.root, project.directory)})</opt>" for p in packages_list
)
)
)
self.line(
Expand Down
2 changes: 1 addition & 1 deletion src/slap/ext/application/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def activate(self, app: Application, config: None) -> None:
app.cleo.add(self)

def handle(self) -> int:
from nr.util.optional import Optional
from nr.stream import Optional

template = self.option("template")
if template not in TEMPLATES:
Expand Down
8 changes: 3 additions & 5 deletions src/slap/ext/application/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@


@t.overload
def get_active_python_bin(cmd: Command) -> str:
...
def get_active_python_bin(cmd: Command) -> str: ...


@t.overload
def get_active_python_bin(cmd: Command, fallback: te.Literal[False]) -> str | None:
...
def get_active_python_bin(cmd: Command, fallback: te.Literal[False]) -> str | None: ...


def get_active_python_bin(cmd: Command, fallback: bool = True) -> str | None:
Expand Down Expand Up @@ -166,7 +164,7 @@ def handle(self) -> int:
Installs the requirements of the package using Pip.
"""

from nr.util.stream import Stream
from nr.stream import Stream

from slap.install.installer import InstallOptions, PipInstaller, get_indexes_for_projects
from slap.python.dependency import PathDependency, PypiDependency, parse_dependencies
Expand Down
2 changes: 1 addition & 1 deletion src/slap/ext/application/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def handle(self) -> int:

def link_repository(io: IO, projects: list[Project], dump_pyproject: bool = False, python: str | None = None) -> None:
from flit.install import Installer # type: ignore[import]
from nr.util.fs import atomic_swap

from slap.util.fs import atomic_swap
from slap.util.pygments import toml_highlight

# We need to pass an absolute path to Python to make sure the scripts have an absolute shebang.
Expand Down
16 changes: 9 additions & 7 deletions src/slap/ext/application/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def _validate_options(self) -> int:
def _load_plugins(self, configuration: Configuration) -> list[ReleasePlugin]:
"""Internal. Loads the plugins for the given configuration."""

from nr.util.plugins import load_entrypoint
from slap.util.plugins import load_entrypoint

plugins = []
for plugin_name in self.config[configuration].plugins:
Expand Down Expand Up @@ -252,7 +252,7 @@ def _validate_version_refs(self, version_refs: list[VersionRef], version: str |
def _check_on_release_branch(self) -> bool:
"""Internal. Checks if the current Git branch matches the configured release branch."""

from nr.util.git import NoCurrentBranchError
from slap.util.git import NoCurrentBranchError

if not self.is_git_repository or self.option("no-branch-check"):
return True
Expand Down Expand Up @@ -320,14 +320,15 @@ def _get_new_version(self, version_refs: list[VersionRef], rule: str) -> "Versio
"""Return the new version, based on *rule*. If *rule* is a version string, it is used as the new version.
Otherwise, it is considered a rule and the applicable rule plugin is invoked to construct the new version."""

from nr.util.plugins import NoSuchEntrypointError, load_entrypoint
from poetry.core.constraints.version import Version

from slap.util.plugins import NoSuchEntrypointError, load_entrypoint

try:
return Version.parse(rule)
except ValueError:
try:
plugin = load_entrypoint(VersionIncrementingRulePlugin, rule)
plugin = load_entrypoint(VersionIncrementingRulePlugin, rule) # type: ignore[type-abstract]
except NoSuchEntrypointError:
self.line(f'error: "<b>{rule}</b>" is not a valid version incrementing rule', "error")
sys.exit(1)
Expand All @@ -336,8 +337,9 @@ def _get_new_version(self, version_refs: list[VersionRef], rule: str) -> "Versio
def _bump_version(self, version_refs: list[VersionRef], target_version: Version, dry: bool) -> list[Path]:
"""Internal. Replaces the version reference in all files with the specified *version*."""

from nr.util import Stream
from nr.util.text import substitute_ranges
from nr.stream import Stream

from slap.util.text import substitute_ranges

self.line(
f'bumping <b>{len(version_refs)}</b> version reference{"" if len(version_refs) == 1 else "s"} to '
Expand Down Expand Up @@ -456,7 +458,7 @@ def _get_version_refs(self) -> list[VersionRef]:
def handle(self) -> int:
"""Entrypoint for the command."""

from nr.util.git import Git
from slap.util.git import Git

self.git = Git()
self.is_git_repository = self.git.get_toplevel() is not None
Expand Down
3 changes: 2 additions & 1 deletion src/slap/ext/application/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import json
import logging
import typing as t
from importlib.metadata import Distribution

from importlib_metadata import Distribution

from slap.application import Application, option
from slap.ext.application.venv import VenvAwareCommand
Expand Down
3 changes: 1 addition & 2 deletions src/slap/ext/application/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import typing as t
from pathlib import Path

from nr.util.singleton import NotSet

from slap.application import IO, Application, argument, option
from slap.ext.application.venv import VenvAwareCommand
from slap.plugins import ApplicationPlugin
from slap.project import Project
from slap.util.notset import NotSet

logger = logging.getLogger(__name__)

Expand Down
14 changes: 8 additions & 6 deletions src/slap/ext/checks/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ def _validate_changelogs(self, project: Project) -> tuple[CheckResult, str | Non
(
"\n".join(f"<i>{fn}</i>: {err}" for fn, err in bad_files)
if bad_files
else ""
+ "\n"
+ "\n".join(
f'<i>{fn}</i>: id=<fg=yellow>"{entry_id}"</fg>: {err}' for fn, err, entry_id in bad_changelogs
else (
""
+ "\n"
+ "\n".join(
f'<i>{fn}</i>: id=<fg=yellow>"{entry_id}"</fg>: {err}' for fn, err, entry_id in bad_changelogs
)
if bad_changelogs
else ""
)
if bad_changelogs
else ""
).strip()
or None,
)
4 changes: 2 additions & 2 deletions src/slap/ext/checks/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from pathlib import Path

import requests
from nr.util import Optional
from nr.util.fs import get_file_in_directory
from nr.stream import Optional

from slap.check import Check, CheckResult, check, get_checks
from slap.ext.project_handlers.poetry import PoetryProjectHandler
from slap.plugins import CheckPlugin
from slap.project import Project
from slap.util.external.pypi_classifiers import get_classifiers
from slap.util.fs import get_file_in_directory


def get_readme_path(project: Project) -> Path | None:
Expand Down
Loading