diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f8c4c62..728a0d4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -201,16 +201,23 @@ jobs: uses: mxschmitt/action-tmate@v3 if: env.RUN_TMATE test: - name: test source - py${{ matrix.python-version }} + name: test source - py${{ matrix.python-version }} - ${{ matrix.platform }} needs: - diagnostics permissions: # actions/checkout needs this to fetch code contents: read - runs-on: ubuntu-latest + runs-on: ${{ matrix.platform }} strategy: fail-fast: false matrix: + # We test on all of the latest platforms available to use with GitHub- + # hosted runners for public repositories. + platform: + - macos-latest + - ubuntu-24.04-arm + - ubuntu-latest + - windows-latest python-version: - "3.9" - "3.10" @@ -251,7 +258,8 @@ jobs: python-version: ${{ matrix.python-version }} - uses: actions/cache@v4 env: - BASE_CACHE_KEY: ${{ github.job }}-${{ runner.os }}-\ + BASE_CACHE_KEY: ${{ github.job }}-\ + ${{ runner.os }}-${{ runner.arch }}-\ py${{ steps.setup-python.outputs.python-version }}- with: path: ${{ env.PIP_CACHE_DIR }} @@ -404,17 +412,24 @@ jobs: uses: mxschmitt/action-tmate@v3 if: env.RUN_TMATE test-build: - name: test built wheel - py${{ matrix.python-version }} + name: test built wheel - py${{ matrix.python-version }} - ${{ matrix.platform }} needs: - diagnostics - build permissions: # actions/checkout needs this to fetch code contents: read - runs-on: ubuntu-latest + runs-on: ${{ matrix.platform }} strategy: fail-fast: false matrix: + # We test on all of the latest platforms available to use with GitHub- + # hosted runners for public repositories. + platform: + - macos-latest + - ubuntu-24.04-arm + - ubuntu-latest + - windows-latest python-version: - "3.9" - "3.10" @@ -455,7 +470,8 @@ jobs: python-version: ${{ matrix.python-version }} - uses: actions/cache@v4 env: - BASE_CACHE_KEY: ${{ github.job }}-${{ runner.os }}-\ + BASE_CACHE_KEY: ${{ github.job }}-\ + ${{ runner.os }}-${{ runner.arch }}-\ py${{ steps.setup-python.outputs.python-version }}- with: path: ${{ env.PIP_CACHE_DIR }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e4c9a82..f9506c0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -181,7 +181,7 @@ repos: # Ansible hooks - repo: https://github.com/ansible/ansible-lint - rev: v25.1.3 + rev: v25.4.0 hooks: - id: ansible-lint additional_dependencies: diff --git a/src/example/example.py b/src/example/example.py new file mode 100644 index 0000000..b8edfd3 --- /dev/null +++ b/src/example/example.py @@ -0,0 +1,104 @@ +"""example is an example Python library and tool. + +Divide one integer by another and log the result. Also log some information +from an environment variable and a package resource. + +EXIT STATUS + This utility exits with one of the following values: + 0 Calculation completed successfully. + >0 An error occurred. + +Usage: + example [--log-level=LEVEL] + example (-h | --help) + +Options: + -h --help Show this message. + --log-level=LEVEL If specified, then the log level will be set to + the specified value. Valid values are "debug", "info", + "warning", "error", and "critical". [default: info] +""" + +# Standard Python Libraries +from importlib.resources import files +import logging +import os +import sys +from typing import Any, Dict + +# Third-Party Libraries +import docopt + +# There are no type stubs for the schema library, so mypy requires the type: +# ignore hint. +from schema import And, Schema, SchemaError, Use # type: ignore + +from ._version import __version__ + +DEFAULT_ECHO_MESSAGE: str = "Hello World from the example default!" + + +def example_div(dividend: int, divisor: int) -> float: + """Print some logging messages.""" + logging.debug("This is a debug message") + logging.info("This is an info message") + logging.warning("This is a warning message") + logging.error("This is an error message") + logging.critical("This is a critical message") + return dividend / divisor + + +def main() -> None: + """Set up logging and call the example function.""" + args: Dict[str, str] = docopt.docopt(__doc__, version=__version__) + # Validate and convert arguments as needed + schema: Schema = Schema( + { + "--log-level": And( + str, + Use(str.lower), + lambda n: n in ("debug", "info", "warning", "error", "critical"), + error="Possible values for --log-level are " + + "debug, info, warning, error, and critical.", + ), + "": Use(int, error=" must be an integer."), + "": And( + Use(int), + lambda n: n != 0, + error=" must be an integer that is not 0.", + ), + str: object, # Don't care about other keys, if any + } + ) + + try: + validated_args: Dict[str, Any] = schema.validate(args) + except SchemaError as err: + # Exit because one or more of the arguments were invalid + print(err, file=sys.stderr) + sys.exit(1) + + # Assign validated arguments to variables + dividend: int = validated_args[""] + divisor: int = validated_args[""] + log_level: str = validated_args["--log-level"] + + # Set up logging + logging.basicConfig( + format="%(asctime)-15s %(levelname)s %(message)s", level=log_level.upper() + ) + + logging.info("%d / %d == %f", dividend, divisor, example_div(dividend, divisor)) + + # Access some data from an environment variable + message: str = os.getenv("ECHO_MESSAGE", DEFAULT_ECHO_MESSAGE) + logging.info('ECHO_MESSAGE="%s"', message) + + # Access some data from our package data (see the setup.py) + secret_message: str = ( + files(__package__).joinpath("data", "secret.txt").read_text().strip() + ) + logging.info('Secret="%s"', secret_message) + + # Stop logging and clean up + logging.shutdown() diff --git a/src/lcgit/_version.py b/src/lcgit/_version.py index f9a01d4..be40f23 100644 --- a/src/lcgit/_version.py +++ b/src/lcgit/_version.py @@ -1,3 +1,7 @@ """This file defines the version of this module.""" +<<<<<<< HEAD:src/lcgit/_version.py __version__ = "2.0.0" +======= +__version__ = "0.2.2" +>>>>>>> b122bbddb6b6be656c655a1049d88bbdf12f940a:src/example/_version.py