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

🐛 dependency_hash #48

Merged
merged 3 commits into from
Dec 20, 2023
Merged
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
68 changes: 60 additions & 8 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,64 @@ jobs:
fail-fast: true
matrix:
include:
- { name: Python 3.12, python: "3.12" }
- { name: Python 3.11, python: "3.11" }
- { name: Python 3.10, python: "3.10" }
- { name: Python 3.9, python: "3.9" }
- { name: Python 3.8, python: "3.8" }
- {
name: Python-3.12,
python: "3.12",
command: "matrix:cov",
matrix: "+py=3.12",
hatch_version: "1.0",
}
- {
name: Python-3.11,
python: "3.11",
command: "matrix:cov",
matrix: "+py=3.11",
hatch_version: "1.0",
}
- {
name: Python-3.10,
python: "3.10",
command: "matrix:cov",
matrix: "+py=3.10",
hatch_version: "1.0",
}
- {
name: Python-3.9,
python: "3.9",
command: "matrix:cov",
matrix: "+py=3.9",
hatch_version: "1.0",
}
- {
name: Python-3.8,
python: "3.8",
command: "matrix:cov",
matrix: "+py=3.8",
hatch_version: "1.0",
}
- {
name: Hatch-1.7.x,
python: "3.11",
command: "versions:cov",
matrix: "+version=1.7.x",
hatch_version: "1.7.0",
}
- {
name: Hatch-1.8.x,
python: "3.11",
command: "versions:cov",
matrix: "+version=1.8.x",
hatch_version: "1.8.0",
}
- {
name: Hatch-1.9.x,
python: "3.11",
command: "versions:cov",
matrix: "+version=1.9.x",
hatch_version: "1.9.0",
}
concurrency:
group: ${{ github.workflow }}-${{ matrix.python }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ matrix.name }}-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Set up Github Workspace
Expand All @@ -50,11 +101,12 @@ jobs:
- name: Install Hatch
run: |
python -m pip install --upgrade pip wheel
python -m pip install -q hatch pre-commit
python -m pip install -q "hatch~=${{ matrix.hatch_version }}"
python -m pip install -q pre-commit
python -m pip install -q "${{ github.workspace }}"
hatch --version
- name: Test Suite
run: |
echo "::add-matcher::.github/workflows/matchers/python.json"
hatch run +py=${{ matrix.python }} matrix:cov
hatch run ${{ matrix.matrix }} ${{ matrix.command }}
echo "::remove-matcher owner=python::"
8 changes: 8 additions & 0 deletions hatch_pip_compile/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,11 @@ def compare_constraint_sha(self, sha: str) -> bool:
if match is None:
return False
return match.group(1).strip() == sha.strip()

def get_hash(self) -> Optional[str]:
"""
Get hash of lock file
"""
if not self.lock_file.exists():
return None
return hashlib.sha256(self.lock_file.read_bytes()).hexdigest()
23 changes: 18 additions & 5 deletions hatch_pip_compile/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ def get_option_types() -> Dict[str, Any]:
"pip-compile-install-args": List[str],
}

def dependency_hash(self) -> str:
"""
Get the dependency hash
"""
self.run_pip_compile()
hatch_hash = super().dependency_hash()
if not self.dependencies:
return hatch_hash
else:
lockfile_hash = self.piptools_lock.get_hash()
return hashlib.sha256(f"{hatch_hash}-{lockfile_hash}".encode()).hexdigest()

def install_pip_tools(self) -> None:
"""
Install pip-tools (if not already installed)
Expand Down Expand Up @@ -350,8 +362,9 @@ def plugin_check_command(
"""
Run a command from the virtualenv
"""
return self.virtual_env.platform.check_command(
command=command,
shell=shell,
**kwargs,
)
with self.safe_activation():
return self.virtual_env.platform.check_command(
command=command,
shell=shell,
**kwargs,
)
27 changes: 25 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy"
]
dependencies = [
"hatch"
"hatch>=1.7.0"
]
description = "hatch plugin to use pip-compile to manage project dependencies"
dynamic = ["version"]
Expand Down Expand Up @@ -127,7 +127,30 @@ dependencies = [

[tool.hatch.envs.test.scripts]
cov = [
"pytest --cov-config=pyproject.toml --cov {args:tests}"
"pytest --cov-config=pyproject.toml --cov {args: tests/ -v}"
]

[tool.hatch.envs.versions]
dependencies = []
pip-compile-constraint = ""
template = "test"
type = "pip-compile"

[[tool.hatch.envs.versions.matrix]]
version = [
"1.7.x",
"1.8.x",
"1.9.x"
]

[tool.hatch.envs.versions.overrides]
matrix.version.dependencies = [
"pytest",
"pytest-cov",
"tomlkit",
{value = "hatch~=1.7.0", if = ["1.7.x"]},
{value = "hatch~=1.8.0", if = ["1.8.x"]},
{value = "hatch~=1.9.0", if = ["1.9.x"]}
]

[tool.hatch.version]
Expand Down
28 changes: 8 additions & 20 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
#
# This file is autogenerated by hatch-pip-compile with Python 3.11
#
# - hatch
# - hatch>=1.7.0
#

anyio==4.1.0
anyio==4.2.0
# via httpx
certifi==2023.11.17
# via
# httpcore
# httpx
cffi==1.16.0
# via cryptography
click==8.1.7
# via
# hatch
# userpath
cryptography==41.0.7
# via secretstorage
distlib==0.3.7
distlib==0.3.8
# via virtualenv
editables==0.5
# via hatchling
filelock==3.13.1
# via virtualenv
h11==0.14.0
# via httpcore
hatch==1.7.0
hatch==1.9.0
# via hatch.envs.default
hatchling==1.18.0
hatchling==1.21.0
# via hatch
httpcore==1.0.2
# via httpx
Expand All @@ -45,10 +41,6 @@ importlib-metadata==7.0.0
# via keyring
jaraco-classes==3.3.0
# via keyring
jeepney==0.8.0
# via
# keyring
# secretstorage
keyring==24.3.0
# via hatch
markdown-it-py==3.0.0
Expand All @@ -61,7 +53,7 @@ packaging==23.2
# via
# hatch
# hatchling
pathspec==0.11.2
pathspec==0.12.1
# via hatchling
pexpect==4.9.0
# via hatch
Expand All @@ -73,16 +65,10 @@ pluggy==1.3.0
# via hatchling
ptyprocess==0.7.0
# via pexpect
pycparser==2.21
# via cffi
pygments==2.17.2
# via rich
pyperclip==1.8.2
# via hatch
rich==13.7.0
# via hatch
secretstorage==3.3.3
# via keyring
shellingham==1.5.4
# via hatch
sniffio==1.3.0
Expand All @@ -101,3 +87,5 @@ virtualenv==20.25.0
# via hatch
zipp==3.17.0
# via importlib-metadata
zstandard==0.22.0
# via hatch
49 changes: 14 additions & 35 deletions requirements/requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# This file is autogenerated by hatch-pip-compile with Python 3.11
#
# [constraints] requirements.txt (SHA256: 9dc610f2c50b92a04dc522873ebc8dd69d35bf8ce9feeef14c5341e8e4ef3019)
# [constraints] requirements.txt (SHA256: 7b84213e35a035caf05934f59f047bf3d12cf93d8623fa26893a37d9c4a2a552)
#
# - markdown-callouts
# - markdown-exec
Expand All @@ -13,25 +13,21 @@
# - mkdocstrings
# - mkdocstrings-python
# - pymdown-extensions
# - hatch
# - hatch>=1.7.0
#

anyio==4.1.0
anyio==4.2.0
# via
# -c requirements.txt
# httpx
babel==2.13.1
babel==2.14.0
# via mkdocs-material
certifi==2023.11.17
# via
# -c requirements.txt
# httpcore
# httpx
# requests
cffi==1.16.0
# via
# -c requirements.txt
# cryptography
charset-normalizer==3.3.2
# via requests
click==8.1.7
Expand All @@ -45,11 +41,7 @@ colorama==0.4.6
# via
# griffe
# mkdocs-material
cryptography==41.0.7
# via
# -c requirements.txt
# secretstorage
distlib==0.3.7
distlib==0.3.8
# via
# -c requirements.txt
# virtualenv
Expand All @@ -63,17 +55,17 @@ filelock==3.13.1
# virtualenv
ghp-import==2.1.0
# via mkdocs
griffe==0.38.0
griffe==0.38.1
# via mkdocstrings-python
h11==0.14.0
# via
# -c requirements.txt
# httpcore
hatch==1.7.0
hatch==1.9.0
# via
# -c requirements.txt
# hatch.envs.docs
hatchling==1.18.0
hatchling==1.21.0
# via
# -c requirements.txt
# hatch
Expand Down Expand Up @@ -104,11 +96,6 @@ jaraco-classes==3.3.0
# via
# -c requirements.txt
# keyring
jeepney==0.8.0
# via
# -c requirements.txt
# keyring
# secretstorage
jinja2==3.1.2
# via
# mkdocs
Expand Down Expand Up @@ -160,7 +147,7 @@ mkdocs-gen-files==0.5.0
# via hatch.envs.docs
mkdocs-literate-nav==0.6.1
# via hatch.envs.docs
mkdocs-material==9.4.14
mkdocs-material==9.5.2
# via hatch.envs.docs
mkdocs-material-extensions==1.3.1
# via mkdocs-material
Expand All @@ -184,7 +171,7 @@ packaging==23.2
# mkdocs
paginate==0.5.6
# via mkdocs-material
pathspec==0.11.2
pathspec==0.12.1
# via
# -c requirements.txt
# hatchling
Expand All @@ -208,10 +195,6 @@ ptyprocess==0.7.0
# via
# -c requirements.txt
# pexpect
pycparser==2.21
# via
# -c requirements.txt
# cffi
pygments==2.17.2
# via
# -c requirements.txt
Expand All @@ -223,10 +206,6 @@ pymdown-extensions==10.5
# markdown-exec
# mkdocs-material
# mkdocstrings
pyperclip==1.8.2
# via
# -c requirements.txt
# hatch
python-dateutil==2.8.2
# via ghp-import
pyyaml==6.0.1
Expand All @@ -244,10 +223,6 @@ rich==13.7.0
# via
# -c requirements.txt
# hatch
secretstorage==3.3.3
# via
# -c requirements.txt
# keyring
shellingham==1.5.4
# via
# -c requirements.txt
Expand Down Expand Up @@ -287,3 +262,7 @@ zipp==3.17.0
# via
# -c requirements.txt
# importlib-metadata
zstandard==0.22.0
# via
# -c requirements.txt
# hatch
Loading