Skip to content

Commit 9bb1512

Browse files
authored
Merge pull request #470 from apcamargo/pixi-project-support
Add support for Pixi projects
2 parents 61b17bd + 7dc96cf commit 9bb1512

12 files changed

+414
-4
lines changed

.github/workflows/testing.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,35 @@ jobs:
273273
- name: ruff
274274
working-directory: ${{ env.WORKING_DIR }}
275275
run: uv run ruff check .
276+
pixi-linting:
277+
strategy:
278+
fail-fast: false
279+
matrix:
280+
project_type: ["application", "lib"]
281+
runs-on: ubuntu-latest
282+
steps:
283+
- uses: actions/checkout@v4
284+
- name: Install Rust
285+
run: |
286+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
287+
- name: Cache Rust dependencies
288+
uses: Swatinem/[email protected]
289+
- name: Build package
290+
run: cargo build --release
291+
- name: Run creation
292+
run: |
293+
./scripts/ci_run.sh ${{ matrix.project_type }} 5
294+
- name: Install Pixi
295+
uses: prefix-dev/[email protected]
296+
with:
297+
manifest-path: ${{ env.WORKING_DIR }}/pyproject.toml
298+
pixi-version: v0.30.0
299+
- name: Set up Python
300+
working-directory: ${{ env.WORKING_DIR }}
301+
run: pixi add python=="${{ env.MIN_PYTHON_VERSION }}.*"
302+
- name: MyPy
303+
working-directory: ${{ env.WORKING_DIR }}
304+
run: pixi run -e dev mypy .
305+
- name: ruff
306+
working-directory: ${{ env.WORKING_DIR }}
307+
run: pixi run -e dev ruff check .

scripts/ci_run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ project_manager="1"
1717

1818
# Check for user provided project manager input
1919
if [ $# -gt 1 ]; then
20-
if [ $2 -lt 1 ] || [ $2 -gt 4 ]; then
20+
if [ $2 -lt 1 ] || [ $2 -gt 5 ]; then
2121
echo "Invalid project_manager value"
2222
exit 1
2323
else

src/github_actions.rs

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,59 @@ jobs:
218218
)
219219
}
220220

221+
fn create_pixi_ci_testing_linux_only_file(
222+
min_python_version: &str,
223+
github_action_python_test_versions: &[String],
224+
) -> String {
225+
let python_versions = build_actions_python_test_versions(github_action_python_test_versions);
226+
227+
format!(
228+
r#"name: Testing
229+
230+
on:
231+
push:
232+
branches:
233+
- main
234+
pull_request:
235+
env:
236+
PYTHON_VERSION: "{min_python_version}"
237+
jobs:
238+
linting:
239+
runs-on: ubuntu-latest
240+
steps:
241+
- uses: actions/checkout@v4
242+
- name: Install Pixi
243+
uses: prefix-dev/[email protected]
244+
with:
245+
pixi-version: v0.30.0
246+
- name: Set up Python
247+
run: pixi add python=="${{{{ env.PYTHON_VERSION }}}}.*"
248+
- name: Ruff format check
249+
run: pixi run run-ruff-format
250+
- name: Lint with ruff
251+
run: pixi run run-ruff-check
252+
- name: mypy check
253+
run: pixi run run-mypy
254+
testing:
255+
strategy:
256+
fail-fast: false
257+
matrix:
258+
python-version: [{python_versions}]
259+
runs-on: ubuntu-latest
260+
steps:
261+
- uses: actions/checkout@v4
262+
- name: Install Pixi
263+
uses: prefix-dev/[email protected]
264+
with:
265+
pixi-version: v0.30.0
266+
- name: Set up Python ${{{{ matrix.python-version }}}}
267+
run: pixi add python=="${{{{ matrix.python-version }}}}.*"
268+
- name: Test with pytest
269+
run: pixi run run-pytest
270+
"#
271+
)
272+
}
273+
221274
fn create_ci_testing_linux_only_file_pyo3(
222275
source_dir: &str,
223276
min_python_version: &str,
@@ -334,6 +387,10 @@ pub fn save_ci_testing_linux_only_file(project_info: &ProjectInfo) -> Result<()>
334387
&project_info.min_python_version,
335388
&project_info.github_actions_python_test_versions,
336389
),
390+
ProjectManager::Pixi => create_pixi_ci_testing_linux_only_file(
391+
&project_info.min_python_version,
392+
&project_info.github_actions_python_test_versions,
393+
),
337394
};
338395

339396
save_file_with_content(&file_path, &content)?;
@@ -648,6 +705,60 @@ jobs:
648705
)
649706
}
650707

708+
fn create_pixi_ci_testing_multi_os_file(
709+
min_python_version: &str,
710+
github_action_python_test_versions: &[String],
711+
) -> String {
712+
let python_versions = build_actions_python_test_versions(github_action_python_test_versions);
713+
714+
format!(
715+
r#"name: Testing
716+
717+
on:
718+
push:
719+
branches:
720+
- main
721+
pull_request:
722+
env:
723+
PYTHON_VERSION: "{min_python_version}"
724+
jobs:
725+
linting:
726+
runs-on: ubuntu-latest
727+
steps:
728+
- uses: actions/checkout@v4
729+
- name: Install Pixi
730+
uses: prefix-dev/[email protected]
731+
with:
732+
pixi-version: v0.30.0
733+
- name: Set up Python
734+
run: pixi add python=="${{{{ env.PYTHON_VERSION }}}}.*"
735+
- name: Ruff format check
736+
run: pixi run run-ruff-formar
737+
- name: Lint with ruff
738+
run: pixi run run-ruff-check
739+
- name: mypy check
740+
run: pixi run run-mypy
741+
testing:
742+
strategy:
743+
fail-fast: false
744+
matrix:
745+
python-version: [{python_versions}]
746+
os: [ubuntu-latest, windows-latest, macos-latest]
747+
runs-on: ${{{{ matrix.os }}}}
748+
steps:
749+
- uses: actions/checkout@v4
750+
- name: Install Pixi
751+
uses: prefix-dev/[email protected]
752+
with:
753+
pixi-version: v0.30.0
754+
- name: Set up Python ${{{{ matrix.python-version }}}}
755+
run: pixi add python=="${{{{ matrix.python-version }}}}.*"
756+
- name: Test with pytest
757+
run: pixi run run-pytest
758+
"#
759+
)
760+
}
761+
651762
pub fn save_ci_testing_multi_os_file(project_info: &ProjectInfo) -> Result<()> {
652763
let file_path = project_info
653764
.base_dir()
@@ -673,6 +784,10 @@ pub fn save_ci_testing_multi_os_file(project_info: &ProjectInfo) -> Result<()> {
673784
&project_info.min_python_version,
674785
&project_info.github_actions_python_test_versions,
675786
),
787+
ProjectManager::Pixi => create_pixi_ci_testing_multi_os_file(
788+
&project_info.min_python_version,
789+
&project_info.github_actions_python_test_versions,
790+
),
676791
};
677792

678793
save_file_with_content(&file_path, &content)?;
@@ -1013,6 +1128,35 @@ jobs:
10131128
)
10141129
}
10151130

1131+
fn create_pixi_pypi_publish_file(python_version: &str) -> String {
1132+
format!(
1133+
r#"name: PyPi Publish
1134+
on:
1135+
release:
1136+
types:
1137+
- published
1138+
jobs:
1139+
deploy:
1140+
runs-on: ubuntu-latest
1141+
steps:
1142+
- uses: actions/checkout@v4
1143+
- name: Install Pixi
1144+
uses: prefix-dev/[email protected]
1145+
with:
1146+
pixi-version: v0.30.0
1147+
- name: Set up Python
1148+
run: pixi add python=="{python_version}.*"
1149+
- name: Build and publish package
1150+
env:
1151+
TWINE_USERNAME: __token__
1152+
TWINE_PASSWORD: ${{{{ secrets.PYPI_API_KEY }}}}
1153+
run: |
1154+
pixi exec --spec python=="{python_version}.*" --spec python-build pyproject-build
1155+
pixi exec --spec python=="{python_version}.*" --spec twine twine upload dist/*
1156+
"#
1157+
)
1158+
}
1159+
10161160
pub fn save_pypi_publish_file(project_info: &ProjectInfo) -> Result<()> {
10171161
let file_path = project_info
10181162
.base_dir()
@@ -1024,6 +1168,7 @@ pub fn save_pypi_publish_file(project_info: &ProjectInfo) -> Result<()> {
10241168
create_setuptools_pypi_publish_file(&project_info.python_version)
10251169
}
10261170
ProjectManager::Uv => create_uv_pypi_publish_file(&project_info.python_version),
1171+
ProjectManager::Pixi => create_pixi_pypi_publish_file(&project_info.python_version),
10271172
};
10281173

10291174
save_file_with_content(&file_path, &content)?;
@@ -1218,6 +1363,23 @@ mod tests {
12181363
assert_yaml_snapshot!(content);
12191364
}
12201365

1366+
#[test]
1367+
fn test_save_pixi_ci_testing_linux_only_file() {
1368+
let mut project_info = project_info_dummy();
1369+
project_info.project_manager = ProjectManager::Pixi;
1370+
project_info.use_multi_os_ci = false;
1371+
let base = project_info.base_dir();
1372+
create_dir_all(base.join(".github/workflows")).unwrap();
1373+
let expected_file = base.join(".github/workflows/testing.yml");
1374+
save_ci_testing_linux_only_file(&project_info).unwrap();
1375+
1376+
assert!(expected_file.is_file());
1377+
1378+
let content = std::fs::read_to_string(expected_file).unwrap();
1379+
1380+
assert_yaml_snapshot!(content);
1381+
}
1382+
12211383
#[test]
12221384
fn test_save_poetry_ci_testing_multi_os_file() {
12231385
let mut project_info = project_info_dummy();
@@ -1286,6 +1448,23 @@ mod tests {
12861448
assert_yaml_snapshot!(content);
12871449
}
12881450

1451+
#[test]
1452+
fn test_save_pixi_ci_testing_multi_os_file() {
1453+
let mut project_info = project_info_dummy();
1454+
project_info.project_manager = ProjectManager::Pixi;
1455+
project_info.use_multi_os_ci = true;
1456+
let base = project_info.base_dir();
1457+
create_dir_all(base.join(".github/workflows")).unwrap();
1458+
let expected_file = base.join(".github/workflows/testing.yml");
1459+
save_ci_testing_multi_os_file(&project_info).unwrap();
1460+
1461+
assert!(expected_file.is_file());
1462+
1463+
let content = std::fs::read_to_string(expected_file).unwrap();
1464+
1465+
assert_yaml_snapshot!(content);
1466+
}
1467+
12891468
#[test]
12901469
fn test_save_dependabot_file() {
12911470
let mut project_info = project_info_dummy();

0 commit comments

Comments
 (0)