Skip to content

Instantly share code, notes, and snippets.

@jsm222
Last active December 15, 2022 18:12
Show Gist options
  • Save jsm222/bc9173913e5283c72397e8a18bfafa73 to your computer and use it in GitHub Desktop.
Save jsm222/bc9173913e5283c72397e8a18bfafa73 to your computer and use it in GitHub Desktop.
from pip._internal.utils.temp_dir import TempDirectory,TempDirectoryTypeRegistry,tempdir_registry,global_tempdir_manager
from pip._internal.commands.install import InstallCommand,reject_location_related_install_options
from pip._internal.cli.cmdoptions import make_target_python
from pip._internal.operations.build.build_tracker import get_build_tracker
from pip._internal.req.req_install import LegacySetupPyOptionsCheckMode, check_legacy_setup_py_options
from pip._internal.cache import WheelCache
from pip._internal.resolution.resolvelib.provider import PipProvider
from pip._internal.resolution.resolvelib.reporter import BaseReporter
from pip._internal.resolution.resolvelib.requirements import SpecifierRequirement
from pip._vendor.resolvelib.resolvers import Resolver
import sys
c = InstallCommand("d","ss") #summary and name seem arbitrary
if len(sys.argv) != 1:
port = sys.argv[1]
else:
port = "/usr/ports/devel/py-twisted/work-py39/Twisted-22.10.0[tls]"
with global_tempdir_manager():
options,args = c.parse_args(["install", "--dry-run",port])
#c.tempdir_registry = tempdir_registry()
#c.verbosity = False;
c._in_main_context = True;
target_python = make_target_python(options)
session = c.get_default_session(options)
finder =c._build_package_finder(
options=options,
session=session,
target_python=target_python,
ignore_requires_python=options.ignore_requires_python,
)
with get_build_tracker() as build_tracker:
try:
reqs = c.get_requirements(args, options, finder, session)
check_legacy_setup_py_options(options, reqs, LegacySetupPyOptionsCheckMode.INSTALL)
if "no-binary-enable-wheel-cache" in options.features_enabled:
# TODO: remove format_control from WheelCache when the deprecation cycle
# is over
wheel_cache = WheelCache(options.cache_dir)
else:
if options.format_control.no_binary:
deprecated(
reason=(
"--no-binary currently disables reading from "
"the cache of locally built wheels. In the future "
"--no-binary will not influence the wheel cache."
),
replacement="to use the --no-cache-dir option",
feature_flag="no-binary-enable-wheel-cache",
issue=11453,
gone_in="23.1",
)
wheel_cache = WheelCache(options.cache_dir, options.format_control)
# Only when installing is it permitted to use PEP 660.
# In other circumstances (pip wheel, pip download) we generate
# regular (i.e. non editable) metadata and wheels.
for req in reqs:
req.permit_editable_wheels = True
reject_location_related_install_options(reqs, options.install_options)
directory = TempDirectory(
delete=not options.no_clean,
kind="install",
globally_managed=True,
)
preparer = c.make_requirement_preparer(
temp_build_dir=directory,
options=options,
build_tracker=build_tracker,
session=session,
finder=finder,
use_user_site=options.use_user_site,
verbosity=True
)
resolver = c.make_resolver(
preparer=preparer,
finder=finder,
options=options,
wheel_cache=wheel_cache,
use_user_site=options.use_user_site,
ignore_installed=True,
ignore_requires_python=options.ignore_requires_python,
force_reinstall=options.force_reinstall,
upgrade_strategy="to-satisfy-only",
use_pep517=options.use_pep517,
)
collected = resolver.factory.collect_root_requirements(reqs)
provider = PipProvider(
factory=resolver.factory,
constraints=collected.constraints,
ignore_dependencies=False,
upgrade_strategy="only-if-needed",
user_requested=collected.user_requested,
)
try_to_avoid_resolution_too_deep = 2000000
resolver1 = Resolver(
provider,
BaseReporter(),
)
try_to_avoid_resolution_too_deep = 2000000
result = resolver1.resolve(
collected.requirements,max_rounds=try_to_avoid_resolution_too_deep
)
for k in result.criteria.keys():
if isinstance(result.criteria[k].information[0].requirement,SpecifierRequirement):
if str(result.criteria[k].information[0][1]) == str(collected.requirements[1]):
print(result.criteria[k].information[0].requirement)
except OSError as e:
raise e
@jsm222
Copy link
Author

jsm222 commented Dec 15, 2022

python hookintopip2.py /usr/ports/devel/py-twisted/work-py39/Twisted-22.10.0[tls]
attrs>=19.2.0
constantly>=15.1
zope.interface>=4.4.2
incremental>=21.3.0
Automat>=0.8.0
typing-extensions>=3.6.5
hyperlink>=17.1.1
pyopenssl>=21.0.0; extra == "tls"
service-identity>=18.1.0; extra == "tls"
idna>=2.4; extra == "tls"

python hookintopip2.py /usr/ports/distfiles/python/Sphinx-4.5.0.tar.gz
sphinxcontrib-applehelp
sphinxcontrib-devhelp
sphinxcontrib-jsmath
sphinxcontrib-htmlhelp>=2.0.0
sphinxcontrib-serializinghtml>=1.1.5
sphinxcontrib-qthelp
Jinja2>=2.3
Pygments>=2.0
docutils<0.18,>=0.14
snowballstemmer>=1.1
babel>=1.3
alabaster<0.8,>=0.7
imagesize
requests>=2.5.0
packaging
importlib-metadata>=4.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment