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

Remove poetry and use UV #27

Open
wants to merge 6 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
43 changes: 10 additions & 33 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,24 @@ jobs:

steps:
#----------------------------------------------
# check-out repo and set-up python
# check-out repo
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v4
- name: Set up python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: 3.9
#----------------------------------------------
# ----- install & configure poetry -----
# ----- install & configure UV -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
virtualenvs-create: true
virtualenvs-in-project: true
#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
# Install a specific version of uv.
version: "0.5.9"
- name: Set up python
uses: actions/setup-python@v5
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install library
run: poetry install --no-interaction
python-version-file: ".python-version"
#----------------------------------------------
# run test suite
#----------------------------------------------
- name: Run tests
run: |
source .venv/bin/activate
pytest tests/ --cov=./
run: uv run pytest tests/ --cov=./
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ e.g. your `pyproject.toml` file may have a version range specified, but it may n

You could run poetry show [dependency] to get the installed version, then pop over to PyPi to check the latest version but if you have a lot of dependencies, this can be time-consuming, so let this tool do it for you.

## Requirements

- Python 3.11+
- UV https://docs.astral.sh/uv/

## Installation

Clone this repository and run the following commands in the root of the project:

## Usage

```bash
poetry install
poetry run check [-r] [local or remote]
uv run check [-r] [local or remote]
```

If you run `uv check` without any arguments, it will display the help text.

Steps:

- Enter the url for your remote repository or the path to your local repository
Expand All @@ -45,10 +51,6 @@ poetry run check local --help

- Only works if the Dockerfile uses poetry to install dependencies

## TODO

- Add support for different dependency managers (requirements.txt, etc.)

## How it works

It will do the following:
Expand Down
47 changes: 26 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
[tool.poetry]
[project]
name = "dependency-checker"
version = "0.1.0"
description = ""
authors = ["Nick Moreton <[email protected]>"]
authors = [
{ name = "Nick Moreton", email = "[email protected]" }
]
readme = "README.md"
packages = [{include = "src"}]

[tool.poetry.dependencies]
python = "^3.9"
requests = "^2.31.0"
click = "^8.1.7"
tomli = "^2.0.1"
rich = "^13.7.1"
requires-python = ">=3.11"
dependencies = [
"click>=8.1.7",
"requests>=2.32.3",
"rich>=13.9.4",
"tomli>=2.2.1",
]

[dependency-groups]
dev = [
"black>=24.10.0",
"flake8>=7.1.1",
"isort>=5.13.2",
"pre-commit>=4.0.1",
"pytest>=8.3.4",
"pytest-cov>=6.0.0",
]

[tool.poetry.group.dev.dependencies]
isort = "^5.13.2"
flake8 = "^7.1.1"
black = "^24.10.0"
pre-commit = "^3.7.0"
pytest = "^8.1.1"
pytest-cov = "^5.0.0"
[project.scripts]
check = "src.main:cli"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.poetry.scripts]
check = "src.main:cli"
[tool.hatch.build.targets.wheel]
packages = ["src"]

[tool.pytest.ini_options]
addopts = "-ra -q --cov=src --cov-report=term-missing --cov-report=html"
Expand Down
6 changes: 5 additions & 1 deletion src/check_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ def check_local(path: str, report: bool) -> None:

# process the requirements-frozen.txt file as a FrozenParser object
# it's used to lookup the package name and version installed in the docker image
frozen = TextParser(pathlib.Path(repository_manager.get_repo_dir / "requirements-frozen.txt").absolute())
requirements_file = pathlib.Path(repository_manager.get_repo_dir / "requirements-frozen.txt").absolute()
frozen = TextParser(requirements_file)

# delete the requirements-frozen.txt file
requirements_file.unlink()

# process the pyproject.toml file as a TomlParser object
# it's used to lookup the package name and version specified in the pyproject.toml file
Expand Down
17 changes: 11 additions & 6 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ def remote(ctx: click.Context, repo_url: str):


@cli.command()
@click.option("--path", prompt="Path to the repository", help="The path to the repository to check.")
@click.argument(
"path",
type=click.Path(
exists=True,
file_okay=False,
dir_okay=True,
resolve_path=True,
path_type=pathlib.Path,
),
)
@click.pass_context
def local(ctx: click.Context, path: str):
def local(ctx: click.Context, path: pathlib.Path):
"""Analyze the dependencies of a local repository"""
# check the path exists
if not pathlib.Path(path).exists():
click.echo("The path does not exist.")
exit()
check_local(path, ctx.obj["report"])
19 changes: 1 addition & 18 deletions src/managers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,4 @@ def __init__(self, path):
super().__init__()

self.repo_url = "local"
self.repo_dir = self.get_absolute_path(path)

def get_absolute_path(self, path):
path_parts = path.strip("/").split("/")
parent_dirs_count = 0
dir_parts = []

for part in path_parts:
if part == "..":
parent_dirs_count += 1
else:
dir_parts.append(part)

cwd = pathlib.Path.cwd()
for _ in range(parent_dirs_count):
cwd = cwd.parent

return cwd.joinpath(*dir_parts)
self.repo_dir = path
Loading
Loading