Skip to content

Instantly share code, notes, and snippets.

@brettcannon
brettcannon / pdm.lock
Last active September 10, 2024 22:07
Lock files with groups
# This file is @generated by PDM.
# It is not intended for manual editing.
[metadata]
groups = ["default", "dev1", "dev2"]
strategy = ["inherit_metadata"]
lock_version = "4.5.0"
content_hash = "sha256:6e2057cd4fe2aa34574cd5b65f833983a72f632225c08fdfe1e16f8c656d80a7"
[[metadata.targets]]
@brettcannon
brettcannon / pdm.lock
Last active September 6, 2024 22:10
Lock files with extras
# This file is @generated by PDM.
# It is not intended for manual editing.
[metadata]
groups = ["default", "extra-A", "extra-B"]
strategy = ["inherit_metadata"]
lock_version = "4.5.0"
content_hash = "sha256:0c137fae99f4123508584ab1444667a46e13237f440c0577bb8d633ee82eaf47"
[[metadata.targets]]
@brettcannon
brettcannon / pdm.lock
Created September 3, 2024 23:49
Lock file comparison
# This file is @generated by PDM.
# It is not intended for manual editing.
[metadata]
groups = ["default"]
strategy = ["inherit_metadata"]
lock_version = "4.5.0"
content_hash = "sha256:ad8d737d864c796dd999f825b17b9226e856eca6f3e7b8c2c654917eec423d19"
[[metadata.targets]]
@brettcannon
brettcannon / fluent.py
Created December 4, 2023 22:54
Provide a function that lets you use a fluent-style API when a method returns e.g. `None` instead of `self`
def fluent(bound_method, /, *args, **kwargs):
"""Call a bound method and return `self` from that method."""
bound_method(*args, **kwargs)
return bound_method.__self__
@brettcannon
brettcannon / metadata.py
Last active October 18, 2022 03:13
`RawMetadata` with caching functions to access normalized values
import functools
from typing import Any, Callable, Dict, Iterable, List, Optional, TypeVar
from .requirements import Requirement
from .specifiers import SpecifierSet
from .utils import NormalizedName, canonicalize_name
from .version import Version
_T = TypeVar("_T")
@brettcannon
brettcannon / metadata.py
Created October 16, 2022 18:00
`packaging.metadata` with lazy data validation
import pathlib
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
from .requirements import Requirement
from .specifiers import SpecifierSet
from .utils import NormalizedName, canonicalize_name
from .version import Version
class Metadata:
@brettcannon
brettcannon / back-in-my-day.py
Created November 26, 2021 22:31
Make Jeff feel better about Python packaging
"""Back in my day, we only needed **one** command. 🧓"""
import runpy
import sys
def run(command):
sys.argv[0] = command
runpy.run_module(command, run_name="__main__")
@brettcannon
brettcannon / config.site
Last active February 2, 2022 22:49
WASI-SDK w/ CPython
cross_compiling=yes
ac_cv_file__dev_ptmx=no
ac_cv_file__dev_ptc=no
@brettcannon
brettcannon / stdlib_modules.json
Created February 20, 2021 23:41
Stdlib modules
{
"__future__": [],
"_xxsubinterpreters": [],
"abc": ["_abc", "_py_abc"],
"aifc": [],
"antigravity": [],
"argparse": [],
"array": [],
"ast": ["_ast"],
"asynchat": [],
@brettcannon
brettcannon / pow_test.py
Created August 23, 2020 19:32
Demonstration of how **= does not follow the data model appropriately
class PowTest:
def __init__(self, name):
self.name = name
def __ipow__(self, _):
print(f"{self.name}.__ipow__")
return NotImplemented
def __pow__(self, _):
print(f"{self.name}.__pow__")