Skip to content

Commit 1078049

Browse files
authored
Add option to use uv in pyo3 projects (#550)
* Add option to use uv in pyo3 projects * Fix CI * Install uv * Fix commands * Fix commands * Fix ci_run.sh
1 parent b6ea7f7 commit 1078049

23 files changed

+630
-87
lines changed

.github/workflows/testing.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ jobs:
223223
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
224224
- name: Cache Rust dependencies
225225
uses: Swatinem/[email protected]
226+
- name: Install uv
227+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
226228
- name: Set up Python
227229
uses: actions/setup-python@v5
228230
with:
@@ -234,11 +236,9 @@ jobs:
234236
- name: Install Dependencies
235237
working-directory: ${{ env.WORKING_DIR }}
236238
run: |
237-
python -m pip install -U pip
238-
python -m pip install -r requirements-dev.txt
239-
python -m pip install -e .
240-
maturin build --out dist
241-
python -m pip install --no-index --find-links=dist/ my-project
239+
uv lock
240+
uv sync --frozen
241+
uv run maturin build
242242
- name: MyPy
243243
working-directory: ${{ env.WORKING_DIR }}
244244
run: just mypy
@@ -247,7 +247,7 @@ jobs:
247247
run: just ruff-check
248248
- name: ruff format
249249
working-directory: ${{ env.WORKING_DIR }}
250-
run: python -m ruff format --check .
250+
run: uv run ruff format --check .
251251
- name: Generated Project Clippy
252252
working-directory: ${{ env.WORKING_DIR }}
253253
run: just clippy
@@ -268,6 +268,8 @@ jobs:
268268
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
269269
- name: Cache Rust dependencies
270270
uses: Swatinem/[email protected]
271+
- name: Install uv
272+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
271273
- name: Set up Python
272274
uses: actions/setup-python@v5
273275
with:
@@ -279,20 +281,18 @@ jobs:
279281
- name: Install Dependencies
280282
working-directory: ${{ env.WORKING_DIR }}
281283
run: |
282-
python -m pip install -U pip
283-
python -m pip install -r requirements-dev.txt
284-
python -m pip install -e .
285-
maturin build --out dist
286-
python -m pip install --no-index --find-links=dist/ my-project
284+
uv lock
285+
uv sync --frozen
286+
uv run maturin build
287287
- name: Pre-commit check
288288
working-directory: ${{ env.WORKING_DIR }}
289289
run: |
290-
pre-commit install
290+
uv run pre-commit install
291291
git add .
292-
pre-commit run --all-files
292+
uv run pre-commit run --all-files
293293
- name: Test with pytest
294294
working-directory: ${{ env.WORKING_DIR }}
295-
run: pytest
295+
run: uv run pytest
296296
setuptools-linting:
297297
strategy:
298298
fail-fast: false

scripts/ci_run.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ use_dependabot=""
4242
use_continuous_deployment=""
4343
use_release_drafter=""
4444
use_multi_os_ci=""
45+
pyo3_python_manager=""
4546

46-
./target/release/python-project create -s << EOF
47+
if [[ project_manager -eq 3 ]]; then
48+
./target/release/python-project create -s << EOF
4749
$project_name
4850
$project_slug
4951
$source_dir
@@ -57,13 +59,37 @@ $python_version
5759
$min_python_version
5860
$gha_versions
5961
$project_manager
62+
$pyo3_python_manager
6063
$application
6164
$max_line_length
6265
$use_dependabot
6366
$use_continuous_deployment
6467
$use_release_drafter
6568
$use_multi_os_ci
6669
EOF
70+
else
71+
./target/release/python-project create -s << EOF
72+
$project_name
73+
$project_slug
74+
$source_dir
75+
$project_description
76+
$creator
77+
$creator_email
78+
$license
79+
$copyright_year
80+
$version
81+
$python_version
82+
$min_python_version
83+
$gha_versions
84+
$project_manager
85+
$application
86+
$max_line_length
87+
$use_dependabot
88+
$use_continuous_deployment
89+
$use_release_drafter
90+
$use_multi_os_ci
91+
EOF
92+
fi
6793

6894
if [ ! -d $project_slug ]; then
6995
echo "Directory not created"

src/cli.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use clap::{Parser, Subcommand, ValueEnum};
22

3-
use crate::project_info::{Day, DependabotSchedule, LicenseType, ProjectManager};
3+
use crate::project_info::{
4+
Day, DependabotSchedule, LicenseType, ProjectManager, Pyo3PythonManager,
5+
};
46

57
#[derive(Clone, Debug, ValueEnum)]
68
pub enum ApplicationOrLib {
@@ -87,6 +89,12 @@ pub enum Param {
8789
/// Remove the saved project manager
8890
ResetProjectManager,
8991

92+
/// Save a default PyO3 python manager
93+
Pyo3PythonManager { value: Pyo3PythonManager },
94+
95+
/// Remove the saved PyO3 Python manager
96+
ResetPyo3PythonManager,
97+
9098
/// Save a default value for is async project
9199
IsAsyncProject { value: BooleanChoice },
92100

src/config.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use serde::{Deserialize, Serialize};
1111

1212
use crate::project_info::{
1313
is_valid_python_version, Day, DependabotSchedule, LicenseType, ProjectManager,
14+
Pyo3PythonManager,
1415
};
1516

1617
#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
@@ -21,6 +22,7 @@ pub struct Config {
2122
pub python_version: Option<String>,
2223
pub min_python_version: Option<String>,
2324
pub project_manager: Option<ProjectManager>,
25+
pub pyo3_python_manager: Option<Pyo3PythonManager>,
2426
pub is_async_project: Option<bool>,
2527
pub is_application: Option<bool>,
2628
pub github_actions_python_test_versions: Option<Vec<String>>,
@@ -51,6 +53,7 @@ impl Default for Config {
5153
python_version: None,
5254
min_python_version: None,
5355
project_manager: None,
56+
pyo3_python_manager: None,
5457
is_async_project: None,
5558
is_application: None,
5659
github_actions_python_test_versions: None,
@@ -84,6 +87,7 @@ impl Config {
8487
python_version: config.python_version,
8588
min_python_version: config.min_python_version,
8689
project_manager: config.project_manager,
90+
pyo3_python_manager: config.pyo3_python_manager,
8791
is_async_project: config.is_async_project,
8892
is_application: config.is_application,
8993
github_actions_python_test_versions: config
@@ -202,6 +206,16 @@ impl Config {
202206
Ok(())
203207
}
204208

209+
pub fn save_pyo3_python_manager(&self, value: Pyo3PythonManager) -> Result<()> {
210+
self.handle_save_config(|config| &mut config.pyo3_python_manager, Some(value))?;
211+
Ok(())
212+
}
213+
214+
pub fn reset_pyo3_python_manager(&self) -> Result<()> {
215+
self.handle_save_config(|config| &mut config.pyo3_python_manager, None)?;
216+
Ok(())
217+
}
218+
205219
pub fn save_is_async_project(&self, value: bool) -> Result<()> {
206220
self.handle_save_config(|config| &mut config.is_async_project, Some(value))?;
207221
Ok(())
@@ -408,6 +422,7 @@ impl Config {
408422
}
409423

410424
print_config_value("Project Manager", &config.project_manager);
425+
print_config_value("PyO3 Python Manager", &config.pyo3_python_manager);
411426
print_config_value("Async Project", &config.is_async_project);
412427
print_config_value("Max Line Length", &config.max_line_length);
413428
print_config_value("Use Dependabot", &config.use_dependabot);
@@ -659,6 +674,28 @@ mod tests {
659674
assert_eq!(result.project_manager, None);
660675
}
661676

677+
#[test]
678+
fn test_save_pyo3_python_manger() {
679+
let config = mock_config();
680+
let expected = Pyo3PythonManager::Uv;
681+
config.save_pyo3_python_manager(expected.clone()).unwrap();
682+
let result = config.load_config();
683+
684+
assert_eq!(result.pyo3_python_manager, Some(expected));
685+
}
686+
687+
#[test]
688+
fn test_reset_pyo3_project_manager() {
689+
let config = mock_config();
690+
config
691+
.save_pyo3_python_manager(Pyo3PythonManager::Uv)
692+
.unwrap();
693+
config.reset_pyo3_python_manager().unwrap();
694+
let result = config.load_config();
695+
696+
assert_eq!(result.pyo3_python_manager, None);
697+
}
698+
662699
#[test]
663700
fn test_save_is_async_project() {
664701
let config = mock_config();

0 commit comments

Comments
 (0)