Skip to content

Commit b8c48f7

Browse files
author
mcdonnnj
committed
# Conflicts: # .github/workflows/build.yml # src/example/example.py # src/mongo_db_from_config/_version.py
2 parents e9ce979 + b122bbd commit b8c48f7

File tree

4 files changed

+143
-5
lines changed

4 files changed

+143
-5
lines changed

.github/workflows/build.yml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,13 @@ jobs:
201201
uses: mxschmitt/action-tmate@v3
202202
if: env.RUN_TMATE
203203
test:
204-
name: test source - py${{ matrix.python-version }}
204+
name: test source - py${{ matrix.python-version }} - ${{ matrix.platform }}
205205
needs:
206206
- diagnostics
207207
permissions:
208208
# actions/checkout needs this to fetch code
209209
contents: read
210+
<<<<<<< HEAD
210211
runs-on: ${{ matrix.os }}
211212
strategy:
212213
fail-fast: false
@@ -216,6 +217,19 @@ jobs:
216217
python-version: "3.7"
217218
os:
218219
- ubuntu-latest
220+
=======
221+
runs-on: ${{ matrix.platform }}
222+
strategy:
223+
fail-fast: false
224+
matrix:
225+
# We test on all of the latest platforms available to use with GitHub-
226+
# hosted runners for public repositories.
227+
platform:
228+
- macos-latest
229+
- ubuntu-24.04-arm
230+
- ubuntu-latest
231+
- windows-latest
232+
>>>>>>> b122bbddb6b6be656c655a1049d88bbdf12f940a
219233
python-version:
220234
- "3.8"
221235
- "3.9"
@@ -257,7 +271,8 @@ jobs:
257271
python-version: ${{ matrix.python-version }}
258272
- uses: actions/cache@v4
259273
env:
260-
BASE_CACHE_KEY: ${{ github.job }}-${{ runner.os }}-\
274+
BASE_CACHE_KEY: ${{ github.job }}-\
275+
${{ runner.os }}-${{ runner.arch }}-\
261276
py${{ steps.setup-python.outputs.python-version }}-
262277
with:
263278
path: ${{ env.PIP_CACHE_DIR }}
@@ -416,13 +431,14 @@ jobs:
416431
uses: mxschmitt/action-tmate@v3
417432
if: env.RUN_TMATE
418433
test-build:
419-
name: test built wheel - py${{ matrix.python-version }}
434+
name: test built wheel - py${{ matrix.python-version }} - ${{ matrix.platform }}
420435
needs:
421436
- diagnostics
422437
- build
423438
permissions:
424439
# actions/checkout needs this to fetch code
425440
contents: read
441+
<<<<<<< HEAD
426442
runs-on: ${{ matrix.os }}
427443
strategy:
428444
fail-fast: false
@@ -432,6 +448,19 @@ jobs:
432448
python-version: "3.7"
433449
os:
434450
- ubuntu-latest
451+
=======
452+
runs-on: ${{ matrix.platform }}
453+
strategy:
454+
fail-fast: false
455+
matrix:
456+
# We test on all of the latest platforms available to use with GitHub-
457+
# hosted runners for public repositories.
458+
platform:
459+
- macos-latest
460+
- ubuntu-24.04-arm
461+
- ubuntu-latest
462+
- windows-latest
463+
>>>>>>> b122bbddb6b6be656c655a1049d88bbdf12f940a
435464
python-version:
436465
- "3.8"
437466
- "3.9"
@@ -473,7 +502,8 @@ jobs:
473502
python-version: ${{ matrix.python-version }}
474503
- uses: actions/cache@v4
475504
env:
476-
BASE_CACHE_KEY: ${{ github.job }}-${{ runner.os }}-\
505+
BASE_CACHE_KEY: ${{ github.job }}-\
506+
${{ runner.os }}-${{ runner.arch }}-\
477507
py${{ steps.setup-python.outputs.python-version }}-
478508
with:
479509
path: ${{ env.PIP_CACHE_DIR }}

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ repos:
182182

183183
# Ansible hooks
184184
- repo: https://github.com/ansible/ansible-lint
185-
rev: v25.1.3
185+
rev: v25.4.0
186186
hooks:
187187
- id: ansible-lint
188188
additional_dependencies:

src/example/example.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
"""example is an example Python library and tool.
2+
3+
Divide one integer by another and log the result. Also log some information
4+
from an environment variable and a package resource.
5+
6+
EXIT STATUS
7+
This utility exits with one of the following values:
8+
0 Calculation completed successfully.
9+
>0 An error occurred.
10+
11+
Usage:
12+
example [--log-level=LEVEL] <dividend> <divisor>
13+
example (-h | --help)
14+
15+
Options:
16+
-h --help Show this message.
17+
--log-level=LEVEL If specified, then the log level will be set to
18+
the specified value. Valid values are "debug", "info",
19+
"warning", "error", and "critical". [default: info]
20+
"""
21+
22+
# Standard Python Libraries
23+
from importlib.resources import files
24+
import logging
25+
import os
26+
import sys
27+
from typing import Any, Dict
28+
29+
# Third-Party Libraries
30+
import docopt
31+
32+
# There are no type stubs for the schema library, so mypy requires the type:
33+
# ignore hint.
34+
from schema import And, Schema, SchemaError, Use # type: ignore
35+
36+
from ._version import __version__
37+
38+
DEFAULT_ECHO_MESSAGE: str = "Hello World from the example default!"
39+
40+
41+
def example_div(dividend: int, divisor: int) -> float:
42+
"""Print some logging messages."""
43+
logging.debug("This is a debug message")
44+
logging.info("This is an info message")
45+
logging.warning("This is a warning message")
46+
logging.error("This is an error message")
47+
logging.critical("This is a critical message")
48+
return dividend / divisor
49+
50+
51+
def main() -> None:
52+
"""Set up logging and call the example function."""
53+
args: Dict[str, str] = docopt.docopt(__doc__, version=__version__)
54+
# Validate and convert arguments as needed
55+
schema: Schema = Schema(
56+
{
57+
"--log-level": And(
58+
str,
59+
Use(str.lower),
60+
lambda n: n in ("debug", "info", "warning", "error", "critical"),
61+
error="Possible values for --log-level are "
62+
+ "debug, info, warning, error, and critical.",
63+
),
64+
"<dividend>": Use(int, error="<dividend> must be an integer."),
65+
"<divisor>": And(
66+
Use(int),
67+
lambda n: n != 0,
68+
error="<divisor> must be an integer that is not 0.",
69+
),
70+
str: object, # Don't care about other keys, if any
71+
}
72+
)
73+
74+
try:
75+
validated_args: Dict[str, Any] = schema.validate(args)
76+
except SchemaError as err:
77+
# Exit because one or more of the arguments were invalid
78+
print(err, file=sys.stderr)
79+
sys.exit(1)
80+
81+
# Assign validated arguments to variables
82+
dividend: int = validated_args["<dividend>"]
83+
divisor: int = validated_args["<divisor>"]
84+
log_level: str = validated_args["--log-level"]
85+
86+
# Set up logging
87+
logging.basicConfig(
88+
format="%(asctime)-15s %(levelname)s %(message)s", level=log_level.upper()
89+
)
90+
91+
logging.info("%d / %d == %f", dividend, divisor, example_div(dividend, divisor))
92+
93+
# Access some data from an environment variable
94+
message: str = os.getenv("ECHO_MESSAGE", DEFAULT_ECHO_MESSAGE)
95+
logging.info('ECHO_MESSAGE="%s"', message)
96+
97+
# Access some data from our package data (see the setup.py)
98+
secret_message: str = (
99+
files(__package__).joinpath("data", "secret.txt").read_text().strip()
100+
)
101+
logging.info('Secret="%s"', secret_message)
102+
103+
# Stop logging and clean up
104+
logging.shutdown()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
"""This file defines the version of this module."""
22

3+
<<<<<<< HEAD:src/mongo_db_from_config/_version.py
34
__version__ = "1.1.0"
5+
=======
6+
__version__ = "0.2.2"
7+
>>>>>>> b122bbddb6b6be656c655a1049d88bbdf12f940a:src/example/_version.py

0 commit comments

Comments
 (0)