Skip to content

Commit

Permalink
🐛 cross-platform hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
juftin authored Jan 10, 2024
1 parent 81dc79f commit d008612
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ on:
- cron: 0 12 1 * *
jobs:
test-suite:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
Expand All @@ -31,56 +30,73 @@ jobs:
command: "matrix:cov",
matrix: "+py=3.12",
hatch_version: "1.0",
os: ubuntu-latest,
}
- {
name: Python-3.11,
python: "3.11",
command: "matrix:cov",
matrix: "+py=3.11",
hatch_version: "1.0",
os: ubuntu-latest,
}
- {
name: Python-3.10,
python: "3.10",
command: "matrix:cov",
matrix: "+py=3.10",
hatch_version: "1.0",
os: ubuntu-latest,
}
- {
name: Python-3.9,
python: "3.9",
command: "matrix:cov",
matrix: "+py=3.9",
hatch_version: "1.0",
os: ubuntu-latest,
}
- {
name: Python-3.8,
python: "3.8",
command: "matrix:cov",
matrix: "+py=3.8",
hatch_version: "1.0",
os: ubuntu-latest,
}
- {
name: Hatch-1.7.x,
python: "3.11",
command: "versions:cov",
matrix: "+version=1.7.x",
hatch_version: "1.7.0",
os: ubuntu-latest,
}
- {
name: Hatch-1.8.x,
python: "3.11",
command: "versions:cov",
matrix: "+version=1.8.x",
hatch_version: "1.8.0",
os: ubuntu-latest,
}
- {
name: Hatch-1.9.x,
python: "3.11",
command: "versions:cov",
matrix: "+version=1.9.x",
hatch_version: "1.9.0",
os: ubuntu-latest,
}
- {
name: Hatch-Windows,
python: "3.11",
command: "matrix:cov",
matrix: "+py=3.11",
hatch_version: "1.0",
os: windows-latest,
}
runs-on: ${{ matrix.os }}
concurrency:
group: ${{ github.workflow }}-${{ matrix.name }}-${{ github.ref }}
cancel-in-progress: true
Expand Down
4 changes: 1 addition & 3 deletions docs/gen_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@

mkdocs_gen_files.set_edit_path(full_doc_path, path)


with open("README.md") as in_file:
readme_content = in_file.read()
readme_content = Path("README.md").read_text(encoding="utf-8")
# Exclude parts that are between two exact `<!--skip-->` lines
readme_content = "\n".join(readme_content.split("\n<!--skip-->\n")[::2])
with mkdocs_gen_files.open("index.md", "w") as index_file:
Expand Down
8 changes: 6 additions & 2 deletions hatch_pip_compile/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def process_lock(self, lockfile: pathlib.Path) -> None:
lockfile_text,
)
if self.constraints_file is not None:
constraint_sha = hashlib.sha256(self.constraints_file.read_bytes()).hexdigest()
lockfile_contents = self.constraints_file.read_bytes()
cross_platform_contents = lockfile_contents.replace(b"\r\n", b"\n")
constraint_sha = hashlib.sha256(cross_platform_contents).hexdigest()
constraints_path = self.constraints_file.relative_to(self.project_root).as_posix()
constraints_line = f"# [constraints] {constraints_path} (SHA256: {constraint_sha})"
joined_dependencies = "\n".join([constraints_line, "#", joined_dependencies])
Expand Down Expand Up @@ -156,7 +158,9 @@ def get_file_content_hash(self) -> str:
"""
Get hash of lock file
"""
return hashlib.sha256(self.lock_file.read_bytes()).hexdigest()
lockfile_contents = self.lock_file.read_bytes()
cross_platform_contents = lockfile_contents.replace(b"\r\n", b"\n")
return hashlib.sha256(cross_platform_contents).hexdigest()

def read_lock_requirements(self) -> List[Requirement]:
"""
Expand Down
3 changes: 3 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
and external tools (pip-tools / pip).
"""

import sys
from typing import Dict, Type

import hatch
Expand All @@ -28,6 +29,8 @@ def test_new_dependency(
"""
Test adding a new dependency
"""
if installer == "pip-sync" and sys.platform == "win32":
pytest.skip("Flaky test on Windows")
original_requirements = pip_compile.default_environment.piptools_lock.read_header_requirements()
assert original_requirements == [packaging.requirements.Requirement("hatch")]
pip_compile.toml_doc["project"]["dependencies"] = ["requests"]
Expand Down

0 comments on commit d008612

Please sign in to comment.