Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shortcut expansion in Python jgo #55

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion jgo/jgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def find_endpoint(argv, shortcuts={}):
pattern = re.compile('.*https?://.*')
indices = []
for index, arg in enumerate(argv):
if arg in shortcuts or (Endpoint.is_endpoint(arg) and not pattern.match(arg)):
if any(a in shortcuts for a in arg.split('+')) or (Endpoint.is_endpoint(arg) and not pattern.match(arg)):
indices.append(index)
return -1 if len(indices) == 0 else indices[-1]

Expand Down Expand Up @@ -367,6 +367,7 @@ def split_endpoint_string(endpoint_string):
return endpoint_strings

def endpoints_from_strings(endpoint_strings, shortcuts={}):
_logger.debug('Creating endpoints from strings %s with shortcuts %s', endpoint_strings, shortcuts)
return [Endpoint.parse_endpoint(expand_coordinate(ep, shortcuts=shortcuts)) for ep in endpoint_strings]

def coordinates_from_endpoints(endpoints):
Expand Down
29 changes: 29 additions & 0 deletions tests/test_shortcut_expansion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import jgo
import pathlib
import tempfile
import unittest

import logging
_logger = logging.getLogger(__name__)

class ExpansionTest(unittest.TestCase):

def test_groovy_issue_46(self):
shortcuts = {'groovy': 'org.codehaus.groovy:groovy-groovysh:org.codehaus.groovy.tools.shell.Main+commons-cli:commons-cli:1.3.1'}

tmp_dir = tempfile.mkdtemp(prefix='jgo-test-cache-dir')
m2_repo = pathlib.Path.home() / '.m2' / 'repository'

primary_endpoint, workspace = jgo.resolve_dependencies(
'groovy',
cache_dir = tmp_dir,
m2_repo = m2_repo,
update_cache = True,
shortcuts = shortcuts,
verbose = 1)
_logger.debug('Got primary_endpoint %s and workspace %s', primary_endpoint, workspace)


if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
unittest.main()