Skip to content

Instantly share code, notes, and snippets.

Avatar

Brett Cannon brettcannon

View GitHub Profile
@brettcannon
brettcannon / metadata.py
Last active Oct 18, 2022
`RawMetadata` with caching functions to access normalized values
View metadata.py
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 Oct 16, 2022
`packaging.metadata` with lazy data validation
View metadata.py
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 Nov 26, 2021
Make Jeff feel better about Python packaging
View back-in-my-day.py
"""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 Feb 2, 2022
WASI-SDK w/ CPython
View config.site
cross_compiling=yes
ac_cv_file__dev_ptmx=no
ac_cv_file__dev_ptc=no
View stdlib_modules.json
{
"__future__": [],
"_xxsubinterpreters": [],
"abc": ["_abc", "_py_abc"],
"aifc": [],
"antigravity": [],
"argparse": [],
"array": [],
"ast": ["_ast"],
"asynchat": [],
@brettcannon
brettcannon / pow_test.py
Created Aug 23, 2020
Demonstration of how **= does not follow the data model appropriately
View pow_test.py
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__")
@brettcannon
brettcannon / stats_tables.sql
Last active Jun 26, 2020
Database schema for repo statistics
View stats_tables.sql
CREATE TABLE issues (
recording_date TEXT NOT NULL DEFAULT CURRENT_DATE,
gh_num INTEGER NOT NULL CHECK(gh_num >= 1),
url TEXT NOT NULL,
title TEXT NOT NULL,
created TEXT NOT NULL, -- Date of issue creation
by_team INT NOT NULL DEFAULT 0 CHECK(upvotes >= 0),
assignee TEXT NULL, -- Who the issue is assigned to
last_OP_comment TEXT NULL, -- When the last comment from the OP was
@brettcannon
brettcannon / steps.yml
Created Jan 24, 2020
GitHub Actions steps to cache VS Code stable when running extension tests
View steps.yml
- name: Get VS Code versions
run: curl --output vscode-stable-versions.json https://update.code.visualstudio.com/api/releases/stable
- uses: actions/cache@v1
with:
path: .vscode-test/
key: ${{ runner.os }}-vscode-test-${{ hashFiles('vscode-stable-versions.json') }}
restore-keys: |
${{ runner.os }}-vscode-test-
@brettcannon
brettcannon / parse_wheel_filename.py
Created May 8, 2019
Parse a wheel filename using packaging.tags
View parse_wheel_filename.py
import packaging.tags
def parse_wheel_filename(path):
name = os.path.splitext(_compat.fspath(path))[0]
index = len(name)
for _ in range(3): # interpreter, ABI, platform.
index = name.rindex("-", 0, index)
return packaging.tags.parse_tag(name[index + 1 :])
@brettcannon
brettcannon / cloudSettings
Last active Jun 18, 2018
Visual Studio Code Settings Sync Gist
View cloudSettings
{"lastUpload":"2018-06-18T21:57:18.905Z","extensionVersion":"v2.9.2"}