Skip to content

Commit

Permalink
2.0.4 - Better editable install handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Aug 5, 2024
1 parent 3a33f44 commit 3ba3873
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
- run: |
mk python-release owner=vkottler \
repo=vmklib version=2.0.3
repo=vmklib version=2.0.4
if: |
matrix.python-version == '3.12'
&& matrix.system == 'ubuntu-latest'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
=====================================
generator=datazen
version=3.1.4
hash=c9f109357706db34fbe6c3c4b3b9d9a2
hash=43e9f25280d496418215c22cd0c49c7f
=====================================
-->

# vmklib ([2.0.3](https://pypi.org/project/vmklib/))
# vmklib ([2.0.4](https://pypi.org/project/vmklib/))

[![python](https://img.shields.io/pypi/pyversions/vmklib.svg)](https://pypi.org/project/vmklib/)
![Build Status](https://github.com/vkottler/vmklib/workflows/Python%20Package/badge.svg)
Expand Down
2 changes: 1 addition & 1 deletion local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
major: 2
minor: 0
patch: 3
patch: 4
entry: mk
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"

[project]
name = "vmklib"
version = "2.0.3"
version = "2.0.4"
description = "Simplify project workflows by standardizing use of GNU Make."
readme = "README.md"
requires-python = ">=3.10"
Expand Down
25 changes: 11 additions & 14 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

# built-in
from contextlib import contextmanager
import os
from pathlib import Path
from shutil import rmtree
import tempfile
from typing import Iterator, List

# third-party
import pkg_resources

# module under test
from vmklib import PKG_NAME

Expand All @@ -30,9 +27,7 @@ def get_args() -> Iterator[List[str]]:

def get_resource(resource_name: str) -> str:
"""Locate the path to a test resource."""

resource_path = os.path.join("data", resource_name)
return pkg_resources.resource_filename(__name__, resource_path)
return str(Path(__file__).parent.joinpath("data", resource_name))


@contextmanager
Expand All @@ -42,19 +37,21 @@ def build_cleaned_resource(resource_name: str) -> Iterator[str]:
is cleaned up before and after providing it.
"""

path = get_resource(resource_name)
path = Path(get_resource(resource_name))

# Try our best to clean up virtual environments.
to_clean = ["build", "venv"] + [
f"venv3.{x}" for x in [6, 7, 8, 9, 10, 11, 12]
]
to_clean = ["build", "venv"] + [f"venv3.{x}" for x in range(6, 6 + 20)]

for clean in to_clean:
clean_path = os.path.join(path, clean)
clean_path = path.joinpath(clean)
rmtree(clean_path, ignore_errors=True)
if clean_path.is_file():
clean_path.unlink()

yield path
yield str(path)

for clean in to_clean:
clean_path = os.path.join(path, clean)
clean_path = path.joinpath(clean)
rmtree(clean_path, ignore_errors=True)
if clean_path.is_file():
clean_path.unlink()
8 changes: 4 additions & 4 deletions tests/test_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def target_tests(
def test_entry_python_tasks():
"""Ensure that we can run Python-based tasks."""

scenario = "python-tasks"

passes = [
(
"python-lint python-sa"
Expand All @@ -124,11 +126,9 @@ def test_entry_python_tasks():
"python-test-add",
"dz-sync",
]
fails = ["python-deps", "python-editable"]
fails = ["python-deps", "python-editable", f"python-install-{scenario}"]

with target_tests(
"python-tasks", passes, fails, {"python-deps", "python-editable"}
) as test_dir:
with target_tests(scenario, passes, fails, set(fails)) as test_dir:
for _ in range(2):
assert mk_main([PKG_NAME, "-C", test_dir, "-d", "venv"]) == 0

Expand Down
4 changes: 2 additions & 2 deletions vmklib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.1.4
# hash=a5d53b6399d66ef76c6e395d072c6018
# hash=54451b981a0a3faef0b7641dd6877695
# =====================================

"""
Expand All @@ -10,4 +10,4 @@

DESCRIPTION = "Simplify project workflows by standardizing use of GNU Make."
PKG_NAME = "vmklib"
VERSION = "2.0.3"
VERSION = "2.0.4"
3 changes: 2 additions & 1 deletion vmklib/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

# internal
from vmklib import PKG_NAME
from vmklib.util import to_slug

LOG = logging.getLogger(__name__)
DEFAULT_FILE = Path("Makefile")
Expand All @@ -36,7 +37,7 @@ def project(path: Path, name: str = None) -> str:
"""
path = path.resolve()
if name is None:
parent_slug = path.name.replace("-", "_")
parent_slug = to_slug(path.name)
if path.joinpath(parent_slug).is_dir():
name = parent_slug
else:
Expand Down
27 changes: 22 additions & 5 deletions vmklib/tasks/python/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# internal
from vmklib.tasks.mixins.concrete import ConcreteOnceMixin
from vmklib.tasks.python import PREFIX
from vmklib.util import to_slug


class PythonPackage(ConcreteOnceMixin, SubprocessLogMixin):
Expand All @@ -24,11 +25,22 @@ class PythonPackage(ConcreteOnceMixin, SubprocessLogMixin):
async def run(self, inbox: Inbox, outbox: Outbox, *args, **kwargs) -> bool:
"""Create or update a project's virtual environment."""

install_args = [*args]

to_install = kwargs["package"]
project = kwargs.get("project")

# Perform an editable install if we're the install target.
if project and to_slug(project) == to_slug(to_install):
install_args.append("-e")
to_install = "."

install_args.append(to_install)

return await self.exec(
str(inbox["venv"]["venv{python_version}"]["pip"]),
"install",
*args,
kwargs["package"],
*install_args,
)


Expand All @@ -40,19 +52,24 @@ def register(
) -> bool:
"""Register Python package tasks to the manager."""

del project
del cwd
del substitutions

# A target that installs a package.
manager.register(
PythonPackage("python{python_version}-install-{package}"), []
PythonPackage(
"python{python_version}-install-{package}", project=project
),
[],
)

# A target that attempts to upgrade a package.
manager.register(
PythonPackage(
"python{python_version}-upgrade-{package}", "--upgrade", once=False
"python{python_version}-upgrade-{package}",
"--upgrade",
once=False,
project=project,
),
[],
)
Expand Down
8 changes: 8 additions & 0 deletions vmklib/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
An interface exposing miscellaneous utilities.
"""


def to_slug(data: str) -> str:
"""Convert a string to an import slug."""
return data.replace("-", "_")

0 comments on commit 3ba3873

Please sign in to comment.