Skip to content

Instantly share code, notes, and snippets.

@jsm222
Last active December 15, 2022 09:08
Show Gist options
  • Save jsm222/61c37e8a06aeca4c5902773d0a88cf92 to your computer and use it in GitHub Desktop.
Save jsm222/61c37e8a06aeca4c5902773d0a88cf92 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.req_command import RequirementCommand, with_cleanup
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 InstallRequirement, LegacySetupPyOptionsCheckMode, check_legacy_setup_py_options
from pip._internal.models.installation_report import InstallationReport
from pip._internal.cache import WheelCache
from pip._internal.resolution.resolvelib.factory import Factory
c = InstallCommand("d","ss") #summary and name seem arbitrary
with global_tempdir_manager():
options,args = c.parse_args(["install", "--dry-run","/usr/ports/distfiles/Twisted-22.10.0.tar.gz"])
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,
)
c.trace_basic_info(finder)
requirement_set = resolver.resolve(reqs, check_supported_wheels=not options.target_dir)
#report = InstallationReport(requirement_set.all_requirements)
#print_json(data=report.to_dict())
if options.dry_run:
for r in requirement_set.all_requirements:
print("name: " + r.metadata["name"],"version:" +r.metadata["version"])
for k in r.get_dist().metadata_dict.keys():
print("{0}:{1}".format(k,r.get_dist().metadata_dict[k]))
except OSError as error:
raise(errror)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment