Skip to content

Commit f27cd26

Browse files
author
mcdonnnj
committed
# Conflicts: # .github/workflows/build.yml # .pre-commit-config.yaml # src/example/example.py # src/pshtt/_version.py
2 parents 7340854 + b122bbd commit f27cd26

4 files changed

Lines changed: 187 additions & 4 deletions

File tree

.github/workflows/build.yml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,13 @@ jobs:
203203
uses: mxschmitt/action-tmate@v3
204204
if: env.RUN_TMATE
205205
test:
206-
name: test source - py${{ matrix.python-version }}
206+
name: test source - py${{ matrix.python-version }} - ${{ matrix.platform }}
207207
needs:
208208
- diagnostics
209209
permissions:
210210
# actions/checkout needs this to fetch code
211211
contents: read
212+
<<<<<<< HEAD
212213
runs-on: ${{ matrix.os }}
213214
strategy:
214215
fail-fast: false
@@ -218,6 +219,19 @@ jobs:
218219
python-version: "3.7"
219220
os:
220221
- ubuntu-latest
222+
=======
223+
runs-on: ${{ matrix.platform }}
224+
strategy:
225+
fail-fast: false
226+
matrix:
227+
# We test on all of the latest platforms available to use with GitHub-
228+
# hosted runners for public repositories.
229+
platform:
230+
- macos-latest
231+
- ubuntu-24.04-arm
232+
- ubuntu-latest
233+
- windows-latest
234+
>>>>>>> b122bbddb6b6be656c655a1049d88bbdf12f940a
221235
python-version:
222236
- "3.8"
223237
- "3.9"
@@ -259,7 +273,8 @@ jobs:
259273
python-version: ${{ matrix.python-version }}
260274
- uses: actions/cache@v4
261275
env:
262-
BASE_CACHE_KEY: ${{ github.job }}-${{ runner.os }}-\
276+
BASE_CACHE_KEY: ${{ github.job }}-\
277+
${{ runner.os }}-${{ runner.arch }}-\
263278
py${{ steps.setup-python.outputs.python-version }}-
264279
with:
265280
path: ${{ env.PIP_CACHE_DIR }}
@@ -418,13 +433,14 @@ jobs:
418433
uses: mxschmitt/action-tmate@v3
419434
if: env.RUN_TMATE
420435
test-build:
421-
name: test built wheel - py${{ matrix.python-version }}
436+
name: test built wheel - py${{ matrix.python-version }} - ${{ matrix.platform }}
422437
needs:
423438
- diagnostics
424439
- build
425440
permissions:
426441
# actions/checkout needs this to fetch code
427442
contents: read
443+
<<<<<<< HEAD
428444
runs-on: ${{ matrix.os }}
429445
strategy:
430446
fail-fast: false
@@ -434,6 +450,19 @@ jobs:
434450
python-version: "3.7"
435451
os:
436452
- ubuntu-latest
453+
=======
454+
runs-on: ${{ matrix.platform }}
455+
strategy:
456+
fail-fast: false
457+
matrix:
458+
# We test on all of the latest platforms available to use with GitHub-
459+
# hosted runners for public repositories.
460+
platform:
461+
- macos-latest
462+
- ubuntu-24.04-arm
463+
- ubuntu-latest
464+
- windows-latest
465+
>>>>>>> b122bbddb6b6be656c655a1049d88bbdf12f940a
437466
python-version:
438467
- "3.8"
439468
- "3.9"
@@ -475,7 +504,8 @@ jobs:
475504
python-version: ${{ matrix.python-version }}
476505
- uses: actions/cache@v4
477506
env:
478-
BASE_CACHE_KEY: ${{ github.job }}-${{ runner.os }}-\
507+
BASE_CACHE_KEY: ${{ github.job }}-\
508+
${{ runner.os }}-${{ runner.arch }}-\
479509
py${{ steps.setup-python.outputs.python-version }}-
480510
with:
481511
path: ${{ env.PIP_CACHE_DIR }}

.pre-commit-config.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ repos:
218218
- id: pyupgrade
219219

220220
# Ansible hooks
221+
<<<<<<< HEAD
221222
# - repo: https://github.com/ansible/ansible-lint
222223
# # ansible-lint no longer supports Python 3.7 as of version 6.0, so
223224
# # we cannot upgrade past the 5.4.0 release:
@@ -269,6 +270,50 @@ repos:
269270
# # made in requirements.txt in cisagov/skeleton-packer and
270271
# # requirements-test.txt in cisagov/skeleton-ansible-role.
271272
# - ansible-core>=2.17
273+
=======
274+
- repo: https://github.com/ansible/ansible-lint
275+
rev: v25.4.0
276+
hooks:
277+
- id: ansible-lint
278+
additional_dependencies:
279+
# On its own ansible-lint does not pull in ansible, only
280+
# ansible-core. Therefore, if an Ansible module lives in
281+
# ansible instead of ansible-core, the linter will complain
282+
# that the module is unknown. In these cases it is
283+
# necessary to add the ansible package itself as an
284+
# additional dependency, with the same pinning as is done in
285+
# requirements-test.txt of cisagov/skeleton-ansible-role.
286+
#
287+
# Version 10 is required because the pip-audit pre-commit
288+
# hook identifies a vulnerability in ansible-core 2.16.13,
289+
# but all versions of ansible 9 have a dependency on
290+
# ~=2.16.X.
291+
#
292+
# It is also a good idea to go ahead and upgrade to version
293+
# 10 since version 9 is going EOL at the end of November:
294+
# https://endoflife.date/ansible
295+
# - ansible>=10,<11
296+
# ansible-core 2.16.3 through 2.16.6 suffer from the bug
297+
# discussed in ansible/ansible#82702, which breaks any
298+
# symlinked files in vars, tasks, etc. for any Ansible role
299+
# installed via ansible-galaxy. Hence we never want to
300+
# install those versions.
301+
#
302+
# Note that the pip-audit pre-commit hook identifies a
303+
# vulnerability in ansible-core 2.16.13. The pin of
304+
# ansible-core to >=2.17 effectively also pins ansible to
305+
# >=10.
306+
#
307+
# It is also a good idea to go ahead and upgrade to
308+
# ansible-core 2.17 since security support for ansible-core
309+
# 2.16 ends this month:
310+
# https://docs.ansible.com/ansible/devel/reference_appendices/release_and_maintenance.html#ansible-core-support-matrix
311+
#
312+
# Note that any changes made to this dependency must also be
313+
# made in requirements.txt in cisagov/skeleton-packer and
314+
# requirements-test.txt in cisagov/skeleton-ansible-role.
315+
- ansible-core>=2.17
316+
>>>>>>> b122bbddb6b6be656c655a1049d88bbdf12f940a
272317

273318
# Terraform hooks
274319
- repo: https://github.com/antonbabenko/pre-commit-terraform

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()

src/pshtt/_version.py

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/pshtt/_version.py
34
__version__ = "0.7.1"
5+
=======
6+
__version__ = "0.2.2"
7+
>>>>>>> b122bbddb6b6be656c655a1049d88bbdf12f940a:src/example/_version.py

0 commit comments

Comments
 (0)