Skip to content

Commit

Permalink
Merge branch 'main' into fix-cygwin-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jan 7, 2024
2 parents aa3a996 + bc0abc4 commit 8806280
Show file tree
Hide file tree
Showing 40 changed files with 717 additions and 200 deletions.
9 changes: 9 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[run]
omit =
# leading `*/` for pytest-dev/pytest-cov#456
*/.tox/*
disable_warnings =
couldnt-parse

[report]
show_missing = True
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
root = true

[*]
charset = utf-8
indent_style = tab
indent_size = 4
insert_final_newline = true
end_of_line = lf

[*.py]
indent_style = space
max_line_length = 88

[*.{yml,yaml}]
indent_style = space
indent_size = 2

[*.rst]
indent_style = space
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
allow:
- dependency-type: "all"
110 changes: 91 additions & 19 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,94 @@
name: tests

on: [push, pull_request]
on:
merge_group:
push:
branches-ignore:
# disabled for jaraco/skeleton#103
# - gh-readonly-queue/** # Temporary merge queue-related GH-made branches
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
group: >-
${{ github.workflow }}-
${{ github.ref_type }}-
${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

permissions:
contents: read

env:
# Environment variable to support color support (jaraco/skeleton#66)
FORCE_COLOR: 1

# Suppress noisy pip warnings
PIP_DISABLE_PIP_VERSION_CHECK: 'true'
PIP_NO_PYTHON_VERSION_WARNING: 'true'
PIP_NO_WARN_SCRIPT_LOCATION: 'true'

# Ensure tests can sense settings about the environment
TOX_OVERRIDE: >-
testenv.pass_env+=GITHUB_*,FORCE_COLOR
jobs:
test:
strategy:
matrix:
python:
# Build on pre-releases until stable, then stable releases.
# actions/setup-python#213
- ~3.7.0-0
- ~3.10.0-0
- ~3.11.0-0
- "3.8"
- "3.11"
- "3.12"
platform:
- ubuntu-latest
- macos-latest
- windows-latest
include:
- platform: ubuntu-latest
python: 'pypy3.9'
- python: "3.9"
platform: ubuntu-latest
- python: "3.10"
platform: ubuntu-latest
- python: pypy3.10
platform: ubuntu-latest
runs-on: ${{ matrix.platform }}
continue-on-error: ${{ matrix.python == '3.13' }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
allow-prereleases: true
- name: Install tox
run: |
python -m pip install tox
- name: Run tests
run: python -m pip install tox
- name: Run
run: tox

collateral:
strategy:
fail-fast: false
matrix:
job:
- diffcov
- docs
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.python == '3.12' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Install tox
run: python -m pip install tox
- name: Eval ${{ matrix.job }}
run: tox -e ${{ matrix.job }}

test_cygwin:
# disabled due to lack of Rust support pypa/setuptools#3921
if: ${{ false }}
strategy:
matrix:
python:
Expand Down Expand Up @@ -65,6 +117,7 @@ jobs:

ci_setuptools:
# Integration testing with setuptools
if: ${{ false }} # disabled for deprecation warnings
strategy:
matrix:
python:
Expand Down Expand Up @@ -101,21 +154,40 @@ jobs:
env:
VIRTUALENV_NO_SETUPTOOLS: null

check: # This job does nothing and is only used for the branch protection
if: always()

needs:
- test
- collateral
# disabled due to disabled job
# - test_cygwin

runs-on: ubuntu-latest

steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}

release:
needs: test
permissions:
contents: write
needs:
- check
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: 3.11-dev
- name: Install tox
run: |
python -m pip install tox
- name: Release
run: python -m pip install tox
- name: Run
run: tox -e release
env:
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.8
hooks:
- id: ruff
- id: ruff-format
12 changes: 12 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
python:
install:
- path: .
extra_requirements:
- docs

# required boilerplate readthedocs/readthedocs.org#10401
build:
os: ubuntu-22.04
tools:
python: "3"
17 changes: 17 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
Empty file added NEWS.rst
Empty file.
19 changes: 19 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
.. image:: https://img.shields.io/pypi/v/distutils.svg
:target: https://pypi.org/project/distutils

.. image:: https://img.shields.io/pypi/pyversions/distutils.svg

.. image:: https://github.com/pypa/distutils/actions/workflows/main.yml/badge.svg
:target: https://github.com/pypa/distutils/actions?query=workflow%3A%22tests%22
:alt: tests

.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json
:target: https://github.com/astral-sh/ruff
:alt: Ruff

.. .. image:: https://readthedocs.org/projects/PROJECT_RTD/badge/?version=latest
.. :target: https://PROJECT_RTD.readthedocs.io/en/latest/?badge=latest
.. image:: https://img.shields.io/badge/skeleton-2024-informational
:target: https://blog.jaraco.com/skeleton

Python Module Distribution Utilities extracted from the Python Standard Library

Synchronizing
Expand Down
53 changes: 53 additions & 0 deletions distutils/_functools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import collections.abc
import functools


Expand All @@ -18,3 +19,55 @@ def wrapper(param, *args, **kwargs):
return func(param, *args, **kwargs)

return wrapper


# from jaraco.functools 4.0
@functools.singledispatch
def _splat_inner(args, func):
"""Splat args to func."""
return func(*args)


@_splat_inner.register
def _(args: collections.abc.Mapping, func):
"""Splat kargs to func as kwargs."""
return func(**args)


def splat(func):
"""
Wrap func to expect its parameters to be passed positionally in a tuple.
Has a similar effect to that of ``itertools.starmap`` over
simple ``map``.
>>> import itertools, operator
>>> pairs = [(-1, 1), (0, 2)]
>>> _ = tuple(itertools.starmap(print, pairs))
-1 1
0 2
>>> _ = tuple(map(splat(print), pairs))
-1 1
0 2
The approach generalizes to other iterators that don't have a "star"
equivalent, such as a "starfilter".
>>> list(filter(splat(operator.add), pairs))
[(0, 2)]
Splat also accepts a mapping argument.
>>> def is_nice(msg, code):
... return "smile" in msg or code == 0
>>> msgs = [
... dict(msg='smile!', code=20),
... dict(msg='error :(', code=1),
... dict(msg='unknown', code=0),
... ]
>>> for msg in filter(splat(is_nice), msgs):
... print(msg)
{'msg': 'smile!', 'code': 20}
{'msg': 'unknown', 'code': 0}
"""
return functools.wraps(func)(functools.partial(_splat_inner, func=func))
72 changes: 72 additions & 0 deletions distutils/_modified.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Timestamp comparison of files and groups of files."""

import functools
import os.path

from .errors import DistutilsFileError
from .py39compat import zip_strict
from ._functools import splat


def _newer(source, target):
return not os.path.exists(target) or (
os.path.getmtime(source) > os.path.getmtime(target)
)


def newer(source, target):
"""
Is source modified more recently than target.
Returns True if 'source' is modified more recently than
'target' or if 'target' does not exist.
Raises DistutilsFileError if 'source' does not exist.
"""
if not os.path.exists(source):
raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source))

return _newer(source, target)


def newer_pairwise(sources, targets, newer=newer):
"""
Filter filenames where sources are newer than targets.
Walk two filename iterables in parallel, testing if each source is newer
than its corresponding target. Returns a pair of lists (sources,
targets) where source is newer than target, according to the semantics
of 'newer()'.
"""
newer_pairs = filter(splat(newer), zip_strict(sources, targets))
return tuple(map(list, zip(*newer_pairs))) or ([], [])


def newer_group(sources, target, missing='error'):
"""
Is target out-of-date with respect to any file in sources.
Return True if 'target' is out-of-date with respect to any file
listed in 'sources'. In other words, if 'target' exists and is newer
than every file in 'sources', return False; otherwise return True.
``missing`` controls how to handle a missing source file:
- error (default): allow the ``stat()`` call to fail.
- ignore: silently disregard any missing source files.
- newer: treat missing source files as "target out of date". This
mode is handy in "dry-run" mode: it will pretend to carry out
commands that wouldn't work because inputs are missing, but
that doesn't matter because dry-run won't run the commands.
"""

def missing_as_newer(source):
return missing == 'newer' and not os.path.exists(source)

ignored = os.path.exists if missing == 'ignore' else None
return any(
missing_as_newer(source) or _newer(source, target)
for source in filter(ignored, sources)
)


newer_pairwise_group = functools.partial(newer_pairwise, newer=newer_group)
Loading

0 comments on commit 8806280

Please sign in to comment.