Skip to content

Commit

Permalink
Mark abstract base classes and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Jul 21, 2024
1 parent 08bd311 commit 57022f7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from __future__ import annotations

from abc import ABC
import sys

if sys.version_info < (3, 8): # noqa: UP036 # Check for unsupported versions
Expand Down Expand Up @@ -311,7 +312,7 @@ def get_supported_platform():
]


class ResolutionError(Exception):
class ResolutionError(Exception, ABC):
"""Abstract base for dependency resolution errors"""

def __repr__(self):
Expand Down
30 changes: 29 additions & 1 deletion setuptools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Extensions to the 'distutils' for large or complex distributions"""

from abc import ABC, abstractmethod
import functools
import os
import re
Expand Down Expand Up @@ -117,7 +118,7 @@ def setup(**attrs):
_Command = monkey.get_unpatched(distutils.core.Command)


class Command(_Command):
class Command(_Command, ABC):
"""
Setuptools internal actions are organized using a *command design pattern*.
This means that each action (or group of closely related actions) executed during
Expand Down Expand Up @@ -226,6 +227,33 @@ def reinitialize_command(self, command, reinit_subcommands=False, **kw):
vars(cmd).update(kw)
return cmd

@abstractmethod
def initialize_options(self) -> None:
"""
Set or (reset) all options/attributes/caches used by the command
to their default values. Note that these values may be overwritten during
the build.
"""
raise NotImplementedError

@abstractmethod
def finalize_options(self) -> None:
"""
Set final values for all options/attributes used by the command.
Most of the time, each option/attribute/cache should only be set if it does not
have any value yet (e.g. ``if self.attr is None: self.attr = val``).
"""
raise NotImplementedError

@abstractmethod
def run(self) -> None:
"""
Execute the actions intended by the command.
(Side effects **SHOULD** only take place when ``run`` is executed,
for example, creating new files or writing to the terminal output).
"""
raise NotImplementedError


def _find_all_simple(path):
"""
Expand Down
7 changes: 6 additions & 1 deletion setuptools/command/setopt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from abc import ABC, abstractmethod
from distutils.util import convert_path
from distutils import log
from distutils.errors import DistutilsOptionError
Expand Down Expand Up @@ -68,7 +69,7 @@ def edit_config(filename, settings, dry_run=False):
opts.write(f)


class option_base(Command):
class option_base(Command, ABC):
"""Abstract base class for commands that mess with config files"""

user_options = [
Expand Down Expand Up @@ -103,6 +104,10 @@ def finalize_options(self):
)
(self.filename,) = filenames

@abstractmethod
def run(self) -> None:
raise NotImplementedError


class setopt(option_base):
"""Save command-line options to a file"""
Expand Down
3 changes: 2 additions & 1 deletion setuptools/sandbox.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from abc import ABC
import os
import sys
import tempfile
Expand Down Expand Up @@ -265,7 +266,7 @@ def run_setup(setup_script, args):
# Normal exit, just return


class AbstractSandbox:
class AbstractSandbox(ABC):
"""Wrap 'os' module and 'open()' builtin for virtualizing setup scripts"""

_active = False
Expand Down

0 comments on commit 57022f7

Please sign in to comment.