Skip to content

Commit

Permalink
Merge pull request #146 from jedie/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
jedie authored Jan 17, 2025
2 parents 9e5128a + 23b8be5 commit aa8d997
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 294 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ default_install_hook_types:

repos:
- repo: https://github.com/jedie/cli-base-utilities
rev: v0.13.1
rev: v0.15.1
hooks:
- id: update-readme-history
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ Usage: ./dev-cli.py [OPTIONS] COMMAND [ARGS]...
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────╮
│ build Build the manageproject (More a test of │
│ manageprojects.utilities.publish.build) │
│ check-code-style Check code style by calling darker + flake8 │
│ coverage Run tests and show coverage report. │
│ fix-code-style Fix code style of all manageprojects source code files via darker │
Expand Down Expand Up @@ -347,6 +349,9 @@ See also git tags: https://github.com/jedie/manageprojects/tags

[comment]: <> (✂✂✂ auto generated history start ✂✂✂)

* [v0.21.0rc1](https://github.com/jedie/manageprojects/compare/v0.20.0...v0.21.0rc1)
* 2025-01-17 - Prefere to build with "uv build"
* 2025-01-17 - Update requirements
* [v0.20.0](https://github.com/jedie/manageprojects/compare/v0.19.2...v0.20.0)
* 2024-11-11 - Bugfix publish: Add "build" dep.
* 2024-11-11 - Bugfix publish command: Add missing "setuptools" dep.
Expand All @@ -359,12 +364,12 @@ See also git tags: https://github.com/jedie/manageprojects/tags
* 2024-09-24 - Update requirements
* [v0.19.1](https://github.com/jedie/manageprojects/compare/v0.19.0...v0.19.1)
* 2024-09-15 - Bugfix and enhance "setup_python.py"
* [v0.19.0](https://github.com/jedie/manageprojects/compare/v0.18.0...v0.19.0)
* 2024-09-15 - NEW: setup_python.py
* 2024-09-15 - Update requirements

<details><summary>Expand older history entries ...</summary>

* [v0.19.0](https://github.com/jedie/manageprojects/compare/v0.18.0...v0.19.0)
* 2024-09-15 - NEW: setup_python.py
* 2024-09-15 - Update requirements
* [v0.18.0](https://github.com/jedie/manageprojects/compare/v0.17.1...v0.18.0)
* 2024-08-29 - Fix wrong "module" in publish call :(
* 2024-08-29 - Fix wrong "distribution_name" in publish command
Expand Down
2 changes: 1 addition & 1 deletion manageprojects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"""

# See https://packaging.python.org/en/latest/specifications/version-specifiers/
__version__ = '0.20.0'
__version__ = '0.21.0rc1'
__author__ = 'Jens Diemer <[email protected]>'
11 changes: 11 additions & 0 deletions manageprojects/cli_dev/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import manageprojects
from manageprojects.cli_dev import PACKAGE_ROOT, cli
from manageprojects.utilities.publish import build as publish_build
from manageprojects.utilities.publish import publish_package


Expand All @@ -25,6 +26,16 @@ def install():
tools_executor.verbose_check_call('pip', 'install', '--no-deps', '-e', '.')


@cli.command()
@click.option('-v', '--verbosity', **OPTION_KWARGS_VERBOSE)
def build(verbosity: int):
"""
Build the manageproject (More a test of manageprojects.utilities.publish.build)
"""
setup_logging(verbosity=verbosity)
publish_build(PACKAGE_ROOT)


def run_pip_audit(verbosity: int):
tools_executor = ToolsExecutor(cwd=PACKAGE_ROOT)

Expand Down
2 changes: 1 addition & 1 deletion manageprojects/tests/test_utilities_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def return_callback(popenargs, args, kwargs):
self.assertEqual(
call_mock.get_popenargs(rstrip_paths=(str(Path(sys.executable).parent),)),
[
['.../python3', '-m', 'build'],
['.../uv', 'build'],
],
)

Expand Down
34 changes: 32 additions & 2 deletions manageprojects/utilities/publish.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging
import os
import shutil
import tempfile
from collections.abc import Iterable
Expand All @@ -7,6 +9,8 @@
from bx_py_utils.dict_utils import dict_get
from bx_py_utils.path import assert_is_file

from manageprojects.constants import PY_BIN_PATH


try:
import tomllib # New in Python 3.11
Expand All @@ -21,6 +25,29 @@
from rich import print # noqa


logger = logging.getLogger(__name__)


def lookup_python_tool(tool_name: str) -> Path | None: # TODO: Move into cli_base
bin_path_str = str(PY_BIN_PATH)
if bin_path_str not in os.environ['PATH']:
# The PATH doesn't contain the python bin path! So shutil.which() will not search in ".venv" ?
# Check first there:
if tool_path := Path(PY_BIN_PATH, tool_name):
logger.debug('%r found in: %s', tool_name, tool_path)
return tool_path

if tool_path := shutil.which(tool_name):
logger.debug('%r found in PATH: %s', tool_name, tool_path)
return Path(tool_path)

logger.debug('%r not found!', tool_name)


def get_uv_path() -> Path | None:
return lookup_python_tool('uv')


def exit_with_error(txt, hint=None):
print(f'[red]ERROR: {txt}')
if hint:
Expand Down Expand Up @@ -205,10 +232,13 @@ def rmtree(path):
print('OK')

if Path(package_path / 'poetry.lock').is_file():
# Poetry used -> build with it
logger.info('Poetry lock file found: build with poetry')
output = verbose_check_output('poetry', 'build', verbose=True, exit_on_error=True)
elif uv_path := get_uv_path():
logger.info('uv found: build with uv')
output = verbose_check_output(uv_path, 'build', verbose=True, exit_on_error=True)
else:
# use normal build
logger.info('use normal build')
output = verbose_check_output(sys.executable, '-m', 'build', verbose=True, exit_on_error=True)

with tempfile.NamedTemporaryFile(
Expand Down
6 changes: 0 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dev = [
"urllib3", # for deny_requests.deny_any_real_request() in tests
"uv", # https://github.com/astral-sh/uv
"setuptools", # https://github.com/pypa/setuptools
"build", # https://github.com/pypa/build
"tox", # https://github.com/tox-dev/tox
"tox-uv", # https://github.com/tox-dev/tox-uv
"coverage", # https://github.com/nedbat/coveragepy
Expand All @@ -64,11 +63,6 @@ dev = [
# https://github.com/pycqa/isort
# https://github.com/pygments/pygments
"darker[flynt, isort, color]",

# Work-a-round for: https://github.com/jazzband/pip-tools/issues/1866
# see also: https://github.com/jazzband/pip-tools/issues/994#issuecomment-1321226661
# backports.tarfile is needed for python <3.12
'backports.tarfile', # via jaraco-context -> keyring -> twine
]

[project.urls]
Expand Down
Loading

0 comments on commit aa8d997

Please sign in to comment.