Skip to content

Commit

Permalink
fix(minecraft): update yarn sources path to src for 1.20.5
Browse files Browse the repository at this point in the history
Closes: #55
  • Loading branch information
clabe45 committed May 3, 2024
1 parent 1ec1e99 commit df6bdf9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 19 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- *namedSrc not found* error when decompiling Minecraft 1.20.5 with Yarn mappings.

### Security
- Updated `cryptography` from 40.0.2 to 42.0.4
- Updated `requests` from 2.28.1 to 2.31.0
Expand Down
2 changes: 1 addition & 1 deletion src/minecraft/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _generate_sources_with_yarn(version: Version, path: str) -> None:

# Move the generated source code to $repo_dir/src
shutil.move(
os.path.join(decompiler_repo.path, 'namedSrc'),
os.path.join(decompiler_repo.path, 'src' if version >= Version.of('1.20.5') else 'namedSrc'),
src_path
)

Expand Down
6 changes: 6 additions & 0 deletions src/minecraft/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def __gt__(self, other) -> bool:

return self._index > other._index

def __le__(self, other) -> bool:
return self < other or self == other

def __ge__(self, other) -> bool:
return self > other or self == other

def to(self, other: Optional[Version], snapshots=True) -> List[Version]:
"""Iterate over all the versions from this version (inclusive) to
`other` (exclusive)
Expand Down
23 changes: 15 additions & 8 deletions tests/minecraft/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,32 @@

MANIFEST_DATA = {
'latest': {
'release': '1.0.0',
'snapshot': '1.0.0'
'release': '1.20.5',
'snapshot': 'abcdef'
},
'versions': [
{
'type': 'release',
'id': '1.0.0'
'id': '1.20.5'
},
{
'type': 'snapshot',
'id': 'abcdef'
},
{
'type': 'release',
'id': '1.20.4'
}
]
}


class TestVersions:
def __init__(self, snapshot: Version, release: Version) -> None:
def __init__(self, v1_20_4: Version, snapshot: Version, v1_20_5: Version) -> None:
self.v1_20_4 = v1_20_4
self.snapshot = snapshot
self.release = release
self.v1_20_5 = v1_20_5
self.release = v1_20_5


def create_repo(mocker, path: str):
Expand Down Expand Up @@ -71,11 +77,12 @@ def rev_parse():

@pytest.fixture
def versions():
load_manifest(MANIFEST_DATA, earliest_supported_version_id='abcdef')
load_manifest(MANIFEST_DATA, earliest_supported_version_id='1.20.4')

v1_20_4 = Version.of('1.20.4')
snapshot = Version.of('abcdef')
release = Version.of('1.0.0')
v1_20_5 = Version.of('1.20.5')

yield TestVersions(snapshot, release)
yield TestVersions(v1_20_4, snapshot, v1_20_5)

clear_manifest()
26 changes: 24 additions & 2 deletions tests/minecraft/unit/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_generate_sources_with_yarn_removes_old_decompiler_dir_if_exists(mocker,
rmtree.assert_any_call(old_decompiler_dir)


def test_generate_sources_with_yarn_moves_sources_to_repo(mocker, versions, yarn_project):
def test_generate_sources_with_1_20_4_and_yarn_moves_sources_to_repo(mocker, versions, yarn_project):
root_path = 'foo'
decompiler_dir = os.path.join(root_path, 'DecompilerMC')

Expand All @@ -110,7 +110,7 @@ def test_generate_sources_with_yarn_moves_sources_to_repo(mocker, versions, yarn
mocker.patch('os.makedirs')
move = mocker.patch('shutil.move')

generate_sources(versions.snapshot, 'yarn', root_path)
generate_sources(versions.v1_20_4, 'yarn', root_path)

decompiler_dir = os.path.join(root_path, 'yarn')
move.assert_called_once_with(
Expand All @@ -119,6 +119,28 @@ def test_generate_sources_with_yarn_moves_sources_to_repo(mocker, versions, yarn
)


def test_generate_sources_with_1_20_5_and_yarn_moves_sources_to_repo(mocker, versions, yarn_project):
root_path = 'foo'
decompiler_dir = os.path.join(root_path, 'DecompilerMC')

mocker.patch(
'subprocess.run',
return_value=SubprocessMock()
)
mocker.patch('minecraft.source.click')
mocker.patch('shutil.rmtree')
mocker.patch('os.makedirs')
move = mocker.patch('shutil.move')

generate_sources(versions.v1_20_5, 'yarn', root_path)

decompiler_dir = os.path.join(root_path, 'yarn')
move.assert_called_once_with(
os.path.join(decompiler_dir, 'src'),
os.path.join(root_path, 'src')
)


def test_generate_sources_with_mojang_runs_decompiler(mocker, versions, decompiler_mc_repo):
root_path = 'foo'
decompiler_dir = os.path.join(root_path, 'DecompilerMC')
Expand Down
16 changes: 8 additions & 8 deletions tests/minecraft/unit/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_release_to_snapshot_raises_version_error(self, versions):
versions.release.to(versions.snapshot)

def test_pattern_with_no_range_operator_returns_list_containing_version(self, versions):
assert Version.pattern('1.0.0') == [versions.release]
assert Version.pattern('1.20.5') == [versions.release]

def test_pattern_with_snapshot_two_dots_returns_list_containing_release(self, versions):
assert Version.pattern('abcdef..') == [versions.release]
Expand All @@ -45,13 +45,13 @@ def test_pattern_with_snapshot_three_dots_returns_list_containing_snapshot_and_r
assert Version.pattern('abcdef...') == [versions.snapshot, versions.release]

def test_pattern_with_release_two_dots_returns_list_containing_release(self, versions):
assert Version.pattern('1.0.0..') == [versions.release]
assert Version.pattern('1.20.5..') == [versions.release]

def test_pattern_with_release_two_dots_release_returns_list_containing_release(self, versions):
assert Version.pattern('1.0.0..1.0.0') == [versions.release]
assert Version.pattern('1.20.5..1.20.5') == [versions.release]

def test_pattern_with_snapshot_three_dots_release_returns_list_containing_snapshot_and_release(self, versions):
assert Version.pattern('abcdef...1.0.0') == [versions.snapshot, versions.release]
assert Version.pattern('abcdef...1.20.5') == [versions.snapshot, versions.release]

def test_pattern_with_three_dots_on_empty_repo_throws_value_error(self, versions):
with pytest.raises(ValueError, match='No commits from which to derive current version'):
Expand All @@ -67,13 +67,13 @@ def test_patterns_with_empty_list_returns_empty_list(self, versions):
assert Version.patterns([]) == []

def test_patterns_with_one_positive_id_returns_corresponding_version(self, versions):
assert Version.patterns(['1.0.0']) == [versions.release]
assert Version.patterns(['1.20.5']) == [versions.release]

def test_patterns_with_two_positive_identical_ids_returns_one_version(self, versions):
assert Version.patterns(['1.0.0', '1.0.0']) == [versions.release]
assert Version.patterns(['1.20.5', '1.20.5']) == [versions.release]

def test_patterns_with_one_positive_id_and_the_same_negative_id_returns_empty_list(self, versions):
assert Version.patterns(['1.0.0', '-1.0.0']) == []
assert Version.patterns(['1.20.5', '-1.20.5']) == []

def test_patterns_with_one_positive_id_and_the_same_negative_id_and_the_same_positive_id_returns_one_version(self, versions):
assert Version.patterns(['1.0.0', '-1.0.0', '1.0.0']) == [versions.release]
assert Version.patterns(['1.20.5', '-1.20.5', '1.20.5']) == [versions.release]

0 comments on commit df6bdf9

Please sign in to comment.