Skip to content

Commit c0952f5

Browse files
author
saville
committed
Migrate project to uv
1 parent cbff371 commit c0952f5

File tree

21 files changed

+998
-310
lines changed

21 files changed

+998
-310
lines changed

.github/workflows/build.yaml

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
python-version:
13-
- 3.8
14-
- 3.9
13+
- '3.9'
1514
- '3.10'
1615
- '3.11'
16+
- '3.12'
17+
- '3.13'
1718
steps:
1819
- uses: actions/checkout@v2
19-
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v2
20+
- name: Set up Docker Compose
21+
uses: docker/setup-compose-action@v1
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v6
2124
with:
2225
python-version: ${{ matrix.python-version }}
2326
- name: Install dependencies
24-
run: |
25-
python -m pip install --upgrade pip
26-
pip install -r requirements.txt
27-
pip install -r test_requirements.txt
27+
run: uv sync --locked
2828
- name: Run pre-commit checks
29-
run: pre-commit run --all-files
29+
run: uv run pre-commit run --all-files
3030
- name: Test with pytest
31-
run: pytest --junitxml=test-reports/test-results.xml
31+
run: uv run pytest --junitxml=test-reports/test-results.xml
3232
- name: Publish test results
3333
uses: EnricoMi/publish-unit-test-result-action@v2
3434
if: always()
@@ -44,19 +44,16 @@ jobs:
4444
with:
4545
# Fetch all history in order to get the commit count for the version in setup.py
4646
fetch-depth: 0
47-
- name: Set up Python
48-
uses: actions/setup-python@v2
47+
- name: Install uv
48+
uses: astral-sh/setup-uv@v6
4949
with:
50-
python-version: 3.8
51-
- name: Remove version file
52-
# This is just in case something else created it, destroy it so we'll get a fresh version
53-
run: rm -f pydc_control/VERSION
54-
- name: Install wheel
55-
run: pip install wheel
50+
python-version: 3.9
51+
- name: Set version
52+
run: uv version --no-sync "$(uv version --short).$(git rev-list --count HEAD)"
5653
- name: Build
57-
run: python setup.py sdist bdist_wheel
54+
run: uv build
5855
- name: Check upload
59-
run: pip install twine && twine check dist/*
56+
run: uv run --with twine twine check dist/*
6057
- name: Publish to PyPi
6158
# Only publish if this was a push
6259
if: github.event_name == 'push'

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,5 @@ dist/
99
*.swp
1010
pytest_cache
1111

12-
# This is generated on every build
13-
pydc_control/VERSION
14-
1512
./docker-compose.env
1613
./docker-compose.yml

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
33
# Ruff version.
4-
rev: v0.1.7
4+
rev: v0.12.7
55
hooks:
66
# Run the linter.
7-
- id: ruff
7+
- id: ruff-check
88
args: [ --fix ]
99
# Run the formatter.
1010
- id: ruff-format

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.11.4
1+
3.11

MANIFEST.in

Lines changed: 0 additions & 2 deletions
This file was deleted.

README-example.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@ this project.
1212
* `Docker <https://www.docker.com/>`_ must be installed on your machine and the ``docker-compose`` command must
1313
be available from the command line.
1414
* The ``git`` command must be available if using Git repositories and ``appctl`` will be used for cloning them.
15-
* A python environment or virtualenv. `pyenv <https://github.com/pyenv/pyenv>`_ is highly recommended to manage
16-
your python installation for different versions.
17-
* The `pydc-control <https://github.com/adobe/pydc-control>`_ python module must be installed into your current
18-
python environment or virtualenv before using ``appctl``. This may be installed from pypi by running:
19-
20-
.. code-block:: console
21-
22-
pip install pydc-control
15+
* `uv <https://github.com/astral-sh/uv>`_ is highly recommended to manage virtualenvs and python versions.
16+
If using ``uv``, ensure that the ``uv`` command is available from the command line.
17+
* If ``uv`` is not used, the ``pydc-control`` module must be installed in your current Python environment.
18+
This may be done by running ``pip install pydc-control``.
2319

2420
Project setup
2521
#############

README.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ upstream docker images or developing using local code.
2525
installing in each configured project
2626

2727

28+
## Development
29+
30+
To develop pydc-control itself, you'll need to set up the development environment:
31+
32+
1. Install [uv](https://docs.astral.sh/uv/) if you haven't already
33+
2. Clone the repository and navigate to the project directory
34+
3. Install dependencies: `uv sync`
35+
4. Run tests: `uv run pytest`
36+
37+
The development dependencies include pytest, ruff for linting/formatting, and other tools needed for development.
38+
2839
## Setup
2940

3041
### Application filesystem layout
@@ -79,19 +90,27 @@ it into a local environment for easy execution.
7990
#### Control script
8091

8192
Add a single python script to the project. Using naming such as `<app>ctl` is
82-
recommended to make it easy to execute.
93+
recommended to make it easy to execute. It is recommended to make this script run with
94+
``uv`` as that will ensure that the correct python version and dependencies are used.
8395

8496
```python
85-
#!/usr/bin/env python3
97+
#!/usr/bin/env -S uv run --script
98+
#
99+
# /// script
100+
# requires-python = ">=3.11"
101+
# dependencies = [
102+
# "pydc-control",
103+
# ]
104+
# ///
86105

87-
import os
88106
import sys
89-
import pydc_control
107+
from pathlib import Path
90108

109+
import pydc_control
91110

92111
if __name__ == '__main__':
93112
# The base path is the location of your control project
94-
base_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
113+
base_path = Path(__file__).parent.parent.resolve()
95114
# Run pydc_control, returns an exit code
96115
sys.exit(pydc_control.run(base_path))
97116
```
@@ -362,11 +381,19 @@ is enabled with s3).
362381
It is easy to create additional commands using pydc_control.
363382

364383
```python
365-
#!/usr/bin/env python3
384+
#!/usr/bin/env -S uv run --script
385+
#
386+
# /// script
387+
# requires-python = ">=3.11"
388+
# dependencies = [
389+
# "pydc-control",
390+
# ]
391+
# ///
366392

367393
import argparse
368394
import os
369395
import sys
396+
from pathlib import Path
370397

371398
import pydc_control
372399

@@ -393,7 +420,7 @@ def configure_parsers(parser: argparse.ArgumentParser, commands_parser: argparse
393420

394421

395422
if __name__ == '__main__':
396-
base_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
423+
base_path = Path(__file__).parent.parent.resolve()
397424
sys.exit(pydc_control.run(base_path, configure_parsers))
398425
```
399426

pydc_control/cli.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
import argparse
1010
import os
11-
from typing import Callable, List, Optional, Sequence
11+
from pathlib import Path
12+
from typing import Callable, List, Optional, Sequence, Union
1213

1314
from . import commands, config, log
1415
from .data import Project, Service
@@ -289,7 +290,7 @@ def _detect_current_project(dev_project_names: List[str]) -> None:
289290

290291

291292
def run(
292-
base_dir: str,
293+
base_dir: Union[str, Path],
293294
configure_parsers: Callable = None,
294295
args: Optional[Sequence[str]] = None,
295296
) -> int:
@@ -302,7 +303,7 @@ def run(
302303
:return: The exit code
303304
"""
304305
# Initialize config based on the base dir
305-
config.initialize(base_dir)
306+
config.initialize(str(base_dir))
306307

307308
args = _parse_args(configure_parsers, args)
308309

pydc_control/commands.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _run_docker_compose_with_projects(
6161
docker_compose_args: List[str],
6262
) -> int:
6363
# Always use the same project name to allow containers to be started/stopped from any repo
64-
commands = ["docker-compose", "-p", config.get_dc_project()]
64+
commands = ["docker", "compose", "-p", config.get_dc_project()]
6565
commands.extend(["-f", config.get_docker_compose_path()])
6666
for project in dev_projects:
6767
commands.extend(["-f", os.path.join(project.path, config.DOCKER_COMPOSE_FILE)])
@@ -87,7 +87,7 @@ def _run_docker_compose_with_projects(
8787
core_commands.extend(core_service_names)
8888

8989
log.get_logger().info(
90-
f'Starting {len(core_service_names)} core service(s) (detached) by calling {" ".join(core_commands)}'
90+
f"Starting {len(core_service_names)} core service(s) (detached) by calling {' '.join(core_commands)}"
9191
)
9292
exit_code = call_commands(core_commands)
9393
if exit_code:
@@ -115,7 +115,7 @@ def _run_docker_compose_with_projects(
115115
base_commands.extend(base_services)
116116

117117
log.get_logger().info(
118-
f'Starting {len(base_services)} base service(s) (detached) by calling {" ".join(base_commands)}'
118+
f"Starting {len(base_services)} base service(s) (detached) by calling {' '.join(base_commands)}"
119119
)
120120
exit_code = subprocess.call(base_commands)
121121
if exit_code:
@@ -139,7 +139,7 @@ def _run_docker_compose_with_projects(
139139
)
140140
commands.extend(all_services)
141141

142-
log.get_logger().info(f'Calling {" ".join(commands)}')
142+
log.get_logger().info(f"Calling {' '.join(commands)}")
143143
return call_commands(commands)
144144

145145

pydc_control/data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
66
with the terms of the Adobe license agreement accompanying it.
77
"""
8+
89
import argparse
910
import os
1011
from functools import lru_cache
@@ -42,7 +43,7 @@ def container_name(self):
4243
The actual container name.
4344
"""
4445
prefix = get_service_prefix("core" if self.core else "service")
45-
return f'{prefix}{self.data.get("name")}'
46+
return f"{prefix}{self.data.get('name')}"
4647

4748
@property
4849
def dc_name(self):

0 commit comments

Comments
 (0)