44# command line options are passed through to the conda install process
55from __future__ import annotations
66
7+ import importlib .metadata
78import json
89import os
910import pathlib
1011import subprocess
1112import sys
1213from typing import Optional
1314
14- import pkg_resources
15+ from packaging . requirements import Requirement
1516
1617import dlstbx
1718
@@ -81,17 +82,15 @@ def check():
8182 conda_environment = {
8283 package ["name" ]: package ["version" ] for package in json .loads (conda_list )
8384 }
84- requirements = [
85- (spec , pkg_resources .Requirement .parse (spec )) for spec in sorted (conda_required )
86- ]
85+ requirements = [(spec , Requirement (spec )) for spec in sorted (conda_required )]
8786
8887 # Now we should have an unduplicated set of requirements
8988 action_list = []
9089 for original_spec , requirement in requirements :
9190 # Check if package is installed in development mode
9291 try :
93- currentversion = pkg_resources . require (requirement .name )[ 0 ]. version
94- except Exception :
92+ currentversion = importlib . metadata . version (requirement .name )
93+ except importlib . metadata . PackageNotFoundError :
9594 pass
9695 else :
9796 location = None
@@ -101,13 +100,13 @@ def check():
101100 with open (egg_link ) as fh :
102101 location = fh .readline ().strip ()
103102 break
104- if location and currentversion in requirement :
103+ if location and currentversion in requirement . specifier :
105104 print (
106105 "requires conda package %s, has %s as developer installation"
107106 % (requirement , currentversion )
108107 )
109108 continue
110- elif location and currentversion not in requirement :
109+ elif location and currentversion not in requirement . specifier :
111110 _notice (
112111 " WARNING: Can not update package {package} automatically." ,
113112 "" ,
@@ -125,7 +124,7 @@ def check():
125124
126125 # Check if package is installed with conda
127126 if requirement .name in conda_environment :
128- if conda_environment [requirement .name ] in requirement :
127+ if conda_environment [requirement .name ] in requirement . specifier :
129128 print (
130129 "requires conda package %s, has %s"
131130 % (requirement , conda_environment [requirement .name ])
0 commit comments