Skip to content

Commit f079a59

Browse files
authored
Merge pull request #68 from xonsh/anki-uv
feat: Add uv support
2 parents 506bad5 + fdaff70 commit f079a59

8 files changed

Lines changed: 100 additions & 9 deletions

File tree

.github/workflows/test.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,63 @@ jobs:
3939
run: pip install ".[dev]"
4040
- name: Run tests
4141
run: pytest
42+
43+
e2e-load:
44+
name: e2e (${{ matrix.package_manager.name }}, autoload=${{ matrix.autoloading }})
45+
needs: testing
46+
runs-on: ubuntu-latest
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
autoloading: ["true", "false"]
51+
package_manager:
52+
- { name: setuptools, install: 'pip install ".[dev]"', run: '' }
53+
- { name: poetry, install: 'poetry install --no-interaction', run: 'poetry run ' }
54+
- { name: uv, install: 'uv sync', run: 'uv run ' }
55+
steps:
56+
- uses: actions/checkout@v5
57+
58+
- uses: actions/setup-python@v6
59+
with:
60+
python-version: "3.13"
61+
62+
- name: Install poetry
63+
if: matrix.package_manager.name == 'poetry'
64+
run: pipx install poetry
65+
66+
- name: Install uv
67+
if: matrix.package_manager.name == 'uv'
68+
uses: astral-sh/setup-uv@v6
69+
70+
- name: Install copier
71+
run: pip install 'copier>=9' copier-templates-extensions
72+
73+
- name: Generate xontrib
74+
run: |
75+
copier copy --trust --defaults --vcs-ref=HEAD \
76+
--data full_name=Test \
77+
--data email=test@test.test \
78+
--data github_username=test \
79+
--data project_name=my-prompt \
80+
--data project_short_description=test \
81+
--data package_manager=${{ matrix.package_manager.name }} \
82+
--data enable_autoloading=${{ matrix.autoloading }} \
83+
. _generated
84+
85+
- name: Install generated xontrib
86+
working-directory: _generated/xontrib-my-prompt
87+
run: ${{ matrix.package_manager.install }}
88+
89+
- name: Verify autoloading
90+
if: matrix.autoloading == 'true'
91+
working-directory: _generated/xontrib-my-prompt
92+
run: |
93+
${{ matrix.package_manager.run }}xonsh -c "xontrib list" | tee out.txt
94+
grep my_prompt out.txt | grep loaded | grep auto
95+
96+
- name: Verify manual loading
97+
if: matrix.autoloading == 'false'
98+
working-directory: _generated/xontrib-my-prompt
99+
run: |
100+
${{ matrix.package_manager.run }}xonsh -c 'xontrib load my_prompt; xontrib list' | tee out.txt
101+
grep my_prompt out.txt | grep loaded | grep manual

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
A template for creating the <a href="https://github.com/xonsh/xonsh">xonsh</a> contributions called <a href="https://xon.sh/tutorial_xontrib.html">xontribs</a>.
2+
A template for creating the <a href="https://github.com/xonsh/xonsh">xonsh</a> extensions called <a href="https://xon.sh/tutorial_xontrib.html">xontribs</a>.
33
</p>
44

55
<p align="center">
@@ -13,7 +13,10 @@ If you like the template click ⭐ on the repo.
1313
This template includes good pack of prebuilt files:
1414

1515
* `README` with the info and xontrib promotion instructions
16-
* [`PEP 621`](https://peps.python.org/pep-0621/) or `poetry` based `pyproject.toml` file to make and install PyPi package easily
16+
* `pyproject.toml` file to make and install PyPi package easily — pick a build backend when prompted by `copier`:
17+
* `setuptools` — classic [`PEP 621`](https://peps.python.org/pep-0621/) layout
18+
* `poetry`[Poetry](https://python-poetry.org/) project layout
19+
* `uv`[uv](https://docs.astral.sh/uv/)-managed project with `hatchling` backend and PEP 735 dependency groups
1720
* `.gitattributes` file to enable Github syntax highlighting for `*.xsh` files
1821
* `.gitignore` file with standard list of directories to ignore
1922
* `.github/workflow/push-test.yml` to automatically test the code using Github Actions

copier.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ package_manager:
4646
choices:
4747
- setuptools
4848
- poetry
49+
- uv
4950

5051
enable_autoloading:
5152
type: bool

project-template/{{ project_repo_name }}/.github/workflows/test.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,30 @@ jobs:
2626
{%- if package_manager == 'poetry' %}
2727
- name: Install poetry
2828
run: pipx install poetry
29+
{% elif package_manager == 'uv' %}
30+
- name: Install uv
31+
uses: astral-sh/setup-uv@v6
32+
with:
33+
enable-cache: true
2934
{% endif -%}
3035
{% raw %}
3136
- name: Set up Python ${{ matrix.python-version }}
3237
uses: actions/setup-python@v6
3338
with:
3439
python-version: ${{ matrix.python-version }} {% endraw %}
35-
cache: {% if package_manager == 'poetry' %}poetry{% else %}pip{% endif %}
40+
{%- if package_manager == 'poetry' %}
41+
cache: poetry
42+
cache-dependency-path: pyproject.toml
43+
{%- elif package_manager == 'uv' %}
44+
{%- else %}
45+
cache: pip
3646
cache-dependency-path: pyproject.toml
47+
{%- endif %}
3748

3849
- uses: pre-commit/action@v3.0.0
3950
- name: Install dependencies
40-
run: {% if package_manager == 'poetry' %}poetry install{% else %}pip install ".[dev]"{% endif %}
51+
run: {% if package_manager == 'poetry' %}poetry install{% elif package_manager == 'uv' %}uv sync{% else %}pip install ".[dev]"{% endif %}
4152
- name: Run tests
4253
run: |
43-
xonsh -c "xontrib load {{ project_package_name}}"
44-
{% if package_manager == 'poetry' %}poetry run pytest{% else %}pytest{% endif %}
54+
{% if package_manager == 'uv' %}uv run {% endif %}xonsh -c "xontrib load {{ project_package_name}}"
55+
{% if package_manager == 'poetry' %}poetry run pytest{% elif package_manager == 'uv' %}uv run pytest{% else %}pytest{% endif %}

project-template/{{ project_repo_name }}/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pre-commit autoupdate
5454

5555
- Bump the version of your package.
5656
- Create a GitHub release (The release notes are automatically generated as a draft release after each push).
57-
- And publish with `poetry publish --build` or `twine`
57+
- And publish with `poetry publish --build`, `uv publish`, or `twine`
5858

5959
## Credits
6060

project-template/{{ project_repo_name }}/pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ xonsh = ">=0.23.0"
7171
{% if package_manager == 'poetry' %}
7272
[tool.poetry.group.dev.dependencies]
7373
pytest = ">=7.0"
74+
{% elif package_manager == 'uv' %}
75+
[dependency-groups]
76+
dev = ["pytest>=7.0"]
77+
78+
[tool.uv]
7479
{% else %}
7580
[project.optional-dependencies]
7681
dev = ["pytest>=7.0"]
@@ -80,6 +85,17 @@ dev = ["pytest>=7.0"]
8085
[build-system]
8186
requires = ["poetry-core>=1.3.0"]
8287
build-backend = "poetry.core.masonry.api"
88+
{% elif package_manager == 'uv' %}
89+
[build-system]
90+
requires = ["hatchling"]
91+
build-backend = "hatchling.build"
92+
93+
[tool.hatch.build.targets.wheel]
94+
{% if enable_autoloading %}
95+
packages = ["{{ py_module_name }}"]
96+
{% else %}
97+
packages = ["xontrib"]
98+
{% endif %}
8399
{% else %}
84100
[build-system]
85101
requires = [

project-template/{{ project_repo_name }}/{%if enable_autoloading%}{{ py_module_name }}{%endif%}/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
def _load_xontrib_(xsh: XonshSession, **_):
55

66
# If your xontrib was made only for interactive mode it's good practice to check this before executing.
7-
if XSH.env.get("XONSH_INTERACTIVE"):
7+
if xsh.env.get("XONSH_INTERACTIVE"):
88
var = xsh.env.get("VAR", "default")
99
print("Autoloading xontrib: {{ project_repo_name }}")
1010

tests/test_generation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
@pytest.mark.parametrize("autoloading", [False, True])
11-
@pytest.mark.parametrize("builder", ["setuptools", "poetry"])
11+
@pytest.mark.parametrize("builder", ["setuptools", "poetry", "uv"])
1212
def test_it_generates(bake_cookie, builder, autoloading):
1313
out = bake_cookie(package_manager=builder, enable_autoloading=autoloading)
1414
expected = get_expected_files(builder, autoloading)

0 commit comments

Comments
 (0)