Skip to content

Instantly share code, notes, and snippets.

View jriddy's full-sized avatar
🐱
Just vibin

Josh Reed jriddy

🐱
Just vibin
View GitHub Profile
from pants.engine.addresses import Address
from pants.engine.fs import PathGlobs, Paths
from pants.engine.internals.graph import Owners, OwnersRequest
from pants.engine.rules import Get, UnionRule, collect_rules, rule
from pants.engine.target import (
COMMON_TARGET_FIELDS,
Dependencies,
InjectedDependencies,
InjectDependenciesRequest,
StringSequenceField,
@jriddy
jriddy / rdeps.py
Last active March 7, 2022 19:08
Determine python reverse dependencies by import scanning
from collections import defaultdict
from pathlib import Path
from pprint import pprint
import argparse
import ast
import networkx as nx
import os.path
from dataclasses import dataclass, field
import logging
from os.path import commonprefix
from typing import Sequence
from pants.core.goals.package import PackageFieldSet, BuiltPackage
from pants.core.util_rules.source_files import SourceFiles, SourceFilesRequest
from pants.core.target_types import FilesSources
from pants.engine.addresses import UnparsedAddressInputs
from pants.engine.fs import (
from dataclasses import dataclass
import logging
from pathlib import Path
from pants.core.goals.package import PackageFieldSet, BuiltPackage
from pants.core.util_rules.source_files import SourceFiles, SourceFilesRequest
from pants.core.util_rules.stripped_source_files import StrippedSourceFiles
from pants.engine.addresses import Address, AddressInput
from pants.engine.fs import EMPTY_DIGEST, MergeDigests, Snapshot
from pants.engine.process import (
from collections import deque
from typing import Generic, TypeVar, Callable, Iterable
T = TypeVar('T')
IC = TypeVar('IC')
OC = TypeVar('OC')
class ContainerTransformer(Generic[T, IC, OC]):
item_type : Type[T]
def iterable_nonstring(x):
"""Determines whether an object is iterable and not a string or unicode.
This is incorrect for python 3.
"""
return hasattr(x, '__iter__')
def iterable(x):
"""Determines whether an object can be iterated over.
# Test on delivery
def register(key):
def decorator(method):
method.response = key
return method
return decorator
@register('$')
@defer.inlineCallbacks
def retry(self, method, *args, **kwds):
for i in xrange(self.tries):
try:
result = yield method(*args, **kwds)
except:
if i == self.tries - 1:
raise
else:
defer.returnValue(result)