Skip to content
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
18 changes: 18 additions & 0 deletions pre_commit_mirror_maker/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ def rust_get_package_versions(package_name: str) -> list[str]:
return list(reversed([version['num'] for version in resp['versions']]))


def haskell_get_package_versions(package_name: str) -> list[str]:
url = f'https://hackage.haskell.org/package/{package_name}/preferred.json'
resp = json.load(urllib.request.urlopen(url))
versions = {
*resp.get('normal-version', ()),
*resp.get('deprecated-version', ()),
}
return sorted(versions, key=version.parse)


def golang_get_package_versions(package_name: str) -> list[str]:
# https://pkg.go.dev/golang.org/x/mod/module#EscapePath
# https://github.com/golang/mod/blob/d271cf332fd221d661d13b186b51a11d7e66ff74/module/module.go#L707
Expand Down Expand Up @@ -78,6 +88,12 @@ def rust_get_additional_dependencies(
return [f'cli:{package_name}:{package_version}']


def haskell_get_additional_dependencies(
package_name: str, package_version: str,
) -> list[str]:
return [f'{package_name}-{package_version}']


def golang_get_additional_dependencies(
package_name: str, package_version: str,
) -> list[str]:
Expand All @@ -86,6 +102,7 @@ def golang_get_additional_dependencies(

LIST_VERSIONS = {
'golang': golang_get_package_versions,
'haskell': haskell_get_package_versions,
'node': node_get_package_versions,
'python': python_get_package_versions,
'ruby': ruby_get_package_versions,
Expand All @@ -94,6 +111,7 @@ def golang_get_additional_dependencies(

ADDITIONAL_DEPENDENCIES = {
'golang': golang_get_additional_dependencies,
'haskell': haskell_get_additional_dependencies,
'node': node_get_additional_dependencies,
'rust': rust_get_additional_dependencies,
}
2 changes: 2 additions & 0 deletions pre_commit_mirror_maker/make_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def _commit_version(
with importlib.resources.as_file(files) as files_p:
for lang in ('all', language):
src = files_p.joinpath(lang)
if not os.path.exists(src):
continue
format_files(
src,
repo,
Expand Down
7 changes: 7 additions & 0 deletions tests/languages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from pre_commit_mirror_maker.languages import golang_get_package_versions
from pre_commit_mirror_maker.languages import haskell_get_package_versions
from pre_commit_mirror_maker.languages import node_get_package_versions
from pre_commit_mirror_maker.languages import python_get_package_versions
from pre_commit_mirror_maker.languages import ruby_get_package_versions
Expand Down Expand Up @@ -44,6 +45,12 @@ def test_rust_get_package_version_output():
assert_all_text(ret)


def test_haskell_get_package_version_output():
ret = haskell_get_package_versions('hlint')
assert ret
assert_all_text(ret)


@pytest.mark.parametrize(
'package_name',
(
Expand Down
16 changes: 16 additions & 0 deletions tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ def test_main_passes_args(mock_make_repo):
)


def test_main_passes_haskell_args(mock_make_repo):
assert not main.main((
'.',
'--language', 'haskell',
'--package-name', 'hlint',
'--types', 'haskell',
))
mock_make_repo.assert_called_once_with(
'.',
language='haskell', name='hlint', description='',
entry='hlint',
id='hlint', match_key='types', match_val='[haskell]', args='[]',
require_serial='false', minimum_pre_commit_version='0',
)


def test_main_defaults_entry_to_package_name(mock_make_repo):
assert not main.main((
'.',
Expand Down
19 changes: 19 additions & 0 deletions tests/make_repo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,22 @@ def test_golang_integration(in_git_dir):
assert _cmd('git', 'log', '--oneline')

# TODO: test that the package is installable


def test_haskell_integration(in_git_dir):
make_repo(
'.',
language='haskell', name='hlint', description='',
entry='hlint', id='hlint', match_key='types', match_val='haskell',
args='[]', require_serial='false', minimum_pre_commit_version='0',
)
assert in_git_dir.join('.version').exists()
assert in_git_dir.join('.pre-commit-hooks.yaml').exists()

contents = in_git_dir.join('.pre-commit-hooks.yaml').read()
assert yaml.safe_load(contents)[0]['additional_dependencies'] == [
f"hlint-{in_git_dir.join('.version').read().strip()}",
]

assert _cmd('git', 'tag', '-l')
assert _cmd('git', 'log', '--oneline')
Loading