Skip to content

Commit

Permalink
Drop packaging dependency in favor of a simple version-parsing func…
Browse files Browse the repository at this point in the history
…tion (#352)
  • Loading branch information
akx authored May 28, 2024
1 parent 3e574a5 commit dc114e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions nodeenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
import http
IncompleteRead = http.client.IncompleteRead

from packaging import version

nodeenv_version = '1.8.0'

join = os.path.join
Expand Down Expand Up @@ -170,16 +168,23 @@ def remove_env_bin_from_path(env, env_bin_dir):
return env.replace(env_bin_dir + ':', '')


def parse_version(version_str):
"""
Parse version string to a tuple of integer parts
"""
return tuple(map(int, version_str.replace('v', '').split('.')))


def node_version_from_args(args):
"""
Parse the node version from the argparse args
"""
if args.node == 'system':
out, err = subprocess.Popen(
["node", "--version"], stdout=subprocess.PIPE).communicate()
return version.parse(clear_output(out).replace('v', ''))
return parse_version(clear_output(out))

return version.parse(args.node)
return parse_version(args.node)


def create_logger():
Expand Down Expand Up @@ -520,7 +525,7 @@ def callit(cmd, show_stdout=True, in_shell=False,


def get_root_url(version_str):
if version.parse(version_str) > version.parse("0.5.0"):
if parse_version(version_str) > (0, 5):
return '%s/v%s/' % (src_base_url, version_str)
else:
return src_base_url
Expand Down Expand Up @@ -1004,7 +1009,7 @@ def create_environment(env_dir, args):
# before npm install, npm use activate
# for install
install_activate(env_dir, args)
if node_version_from_args(args) < version.parse("0.6.3") or args.with_npm:
if node_version_from_args(args) < (0, 6, 3) or args.with_npm:
instfunc = install_npm_win if is_WIN or is_CYGWIN else install_npm
instfunc(env_dir, src_dir, args)
if args.requirements:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def read_file(file_name):
license='BSD',
author='Eugene Kalinin',
author_email='[email protected]',
install_requires=['packaging'],
install_requires=[],
python_requires=(
">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*"
),
Expand Down

0 comments on commit dc114e1

Please sign in to comment.