Skip to content

Commit bbd9397

Browse files
authored
Merge pull request #95 from sanders41/testing
Add setuptools to CI tests
2 parents 78d789a + 1832e6c commit bbd9397

File tree

3 files changed

+102
-65
lines changed

3 files changed

+102
-65
lines changed

.github/workflows/testing.yml

Lines changed: 87 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
uses: Swatinem/[email protected]
4949
- name: Run cargo test
5050
run: cargo test --locked
51-
pure-python-linting:
51+
poetry-linting:
5252
strategy:
5353
fail-fast: false
5454
matrix:
@@ -61,38 +61,21 @@ jobs:
6161
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
6262
- name: Cache Rust dependencies
6363
uses: Swatinem/[email protected]
64-
- name: Set up Python
65-
uses: actions/setup-python@v4
66-
with:
67-
python-version: "${{ env.MIN_PYTHON_VERSION }}"
68-
- name: Get full Python version
69-
id: full-python-version
70-
run: echo version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") >> $GITHUB_OUTPUT
7164
- name: Install Poetry
72-
run: |
73-
pip install -U pip
74-
pip install pipx
75-
pipx install poetry
65+
run: pipx install poetry
7666
- name: Configure poetry
7767
run: |
7868
poetry config virtualenvs.create true
7969
poetry config virtualenvs.in-project true
70+
- name: Set up Python
71+
uses: actions/setup-python@v4
72+
with:
73+
python-version: "${{ env.MIN_PYTHON_VERSION }}"
8074
- name: Build package
8175
run: cargo build --release
8276
- name: Run creation
8377
run: |
8478
./scripts/ci_run.sh ${{ matrix.project_type }} 1
85-
- name: Cache poetry venv
86-
uses: actions/cache@v3
87-
id: poetry-cache
88-
with:
89-
path: my-project/.venv
90-
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
91-
- name: Ensure cache is healthy
92-
working-directory: ${{ env.WORKING_DIR }}
93-
if: steps.poetry-cache.outputs.cache-hit == 'true'
94-
shell: bash
95-
run: timeout 10s poetry run pip --version || rm -rf .venv
9679
- name: Install Dependencies
9780
working-directory: ${{ env.WORKING_DIR }}
9881
run: poetry install
@@ -102,7 +85,7 @@ jobs:
10285
- name: ruff
10386
working-directory: ${{ env.WORKING_DIR }}
10487
run: poetry run ruff check .
105-
pure-python-test:
88+
poetry-test:
10689
strategy:
10790
fail-fast: false
10891
matrix:
@@ -116,38 +99,21 @@ jobs:
11699
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
117100
- name: Cache Rust dependencies
118101
uses: Swatinem/[email protected]
119-
- name: Set up Python
120-
uses: actions/setup-python@v4
121-
with:
122-
python-version: "3.11"
123-
- name: Get full Python version
124-
id: full-python-version
125-
run: echo version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") >> $GITHUB_OUTPUT
126102
- name: Install Poetry
127-
run: |
128-
pip install -U pip
129-
pip install pipx
130-
pipx install poetry
103+
run: pipx install poetry
131104
- name: Configure poetry
132105
run: |
133106
poetry config virtualenvs.create true
134107
poetry config virtualenvs.in-project true
108+
- name: Set up Python
109+
uses: actions/setup-python@v4
110+
with:
111+
python-version: "3.11"
135112
- name: Build package
136113
run: cargo build --release
137114
- name: Run creation
138115
run: |
139116
./scripts/ci_run.sh ${{ matrix.project_type }} 1
140-
- name: Cache poetry venv
141-
uses: actions/cache@v3
142-
id: poetry-cache
143-
with:
144-
path: my-project/.venv
145-
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
146-
- name: Ensure cache is healthy
147-
working-directory: ${{ env.WORKING_DIR }}
148-
if: steps.poetry-cache.outputs.cache-hit == 'true'
149-
shell: bash
150-
run: timeout 10s poetry run pip --version || rm -rf .venv
151117
- name: Install Dependencies
152118
working-directory: ${{ env.WORKING_DIR }}
153119
run: poetry install
@@ -183,11 +149,11 @@ jobs:
183149
- name: Install Dependencies
184150
working-directory: ${{ env.WORKING_DIR }}
185151
run: |
186-
pip install -U pip
187-
pip install -r requirements-dev.txt
188-
pip install -e .
152+
python -m pip install -U pip
153+
python -m pip install -r requirements-dev.txt
154+
python -m pip install -e .
189155
maturin build --out dist
190-
pip install --no-index --find-links=dist/ my-project
156+
python -m pip install --no-index --find-links=dist/ my-project
191157
- name: MyPy
192158
working-directory: ${{ env.WORKING_DIR }}
193159
run: just mypy
@@ -225,11 +191,78 @@ jobs:
225191
- name: Install Dependencies
226192
working-directory: ${{ env.WORKING_DIR }}
227193
run: |
228-
pip install -U pip
229-
pip install -r requirements-dev.txt
230-
pip install -e .
194+
python -m pip install -U pip
195+
python -m pip install -r requirements-dev.txt
196+
python -m pip install -e .
231197
maturin build --out dist
232-
pip install --no-index --find-links=dist/ my-project
198+
python -m pip install --no-index --find-links=dist/ my-project
199+
- name: Pre-commit install
200+
working-directory: ${{ env.WORKING_DIR }}
201+
run: pre-commit install
202+
- name: Test with pytest
203+
working-directory: ${{ env.WORKING_DIR }}
204+
run: pytest
205+
setuptools-linting:
206+
strategy:
207+
fail-fast: false
208+
matrix:
209+
project_type: ["application", "lib"]
210+
runs-on: ubuntu-latest
211+
steps:
212+
- uses: actions/checkout@v4
213+
- name: Install Rust
214+
run: |
215+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
216+
- name: Cache Rust dependencies
217+
uses: Swatinem/[email protected]
218+
- name: Set up Python
219+
uses: actions/setup-python@v4
220+
with:
221+
python-version: "${{ env.MIN_PYTHON_VERSION }}"
222+
- name: Build package
223+
run: cargo build --release
224+
- name: Run creation
225+
run: |
226+
./scripts/ci_run.sh ${{ matrix.project_type }} 3
227+
- name: Install Dependencies
228+
working-directory: ${{ env.WORKING_DIR }}
229+
run: |
230+
python -m pip install -U pip
231+
python -m pip install -r requirements-dev.txt
232+
- name: MyPy
233+
working-directory: ${{ env.WORKING_DIR }}
234+
run: mypy .
235+
- name: ruff
236+
working-directory: ${{ env.WORKING_DIR }}
237+
run: ruff check .
238+
setuptools-test:
239+
strategy:
240+
fail-fast: false
241+
matrix:
242+
project_type: ["application", "lib"]
243+
os: [ubuntu-latest, macos-latest]
244+
runs-on: ${{ matrix.os }}
245+
steps:
246+
- uses: actions/checkout@v4
247+
- name: Install Rust
248+
run: |
249+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
250+
- name: Cache Rust dependencies
251+
uses: Swatinem/[email protected]
252+
- name: Set up Python
253+
uses: actions/setup-python@v4
254+
with:
255+
python-version: "3.11"
256+
- name: Build package
257+
run: cargo build --release
258+
- name: Run creation
259+
run: |
260+
./scripts/ci_run.sh ${{ matrix.project_type }} 3
261+
- name: Install Dependencies
262+
working-directory: ${{ env.WORKING_DIR }}
263+
run: |
264+
python -m pip install -U pip
265+
python -m pip install -r requirements-dev.txt
233266
- name: Pre-commit install
234267
working-directory: ${{ env.WORKING_DIR }}
235268
run: pre-commit install

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 2 ]; then
20+
if [ $2 -lt 1 ] || [ $2 -gt 3 ]; then
2121
echo "Invalid project_manager value"
2222
exit 1
2323
else

src/python_files.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fn save_version_file(project_info: &ProjectInfo) -> Result<()> {
190190
Ok(())
191191
}
192192

193-
fn create_version_test_file(source_dir: &str, project_manager: &ProjectManager) -> Option<String> {
193+
fn create_version_test_file(source_dir: &str, project_manager: &ProjectManager) -> String {
194194
let version_test: &str = match project_manager {
195195
ProjectManager::Maturin => {
196196
r#"def test_versions_match():
@@ -210,10 +210,17 @@ fn create_version_test_file(source_dir: &str, project_manager: &ProjectManager)
210210
211211
assert VERSION == pyproject_version"#
212212
}
213-
ProjectManager::Setuptools => return None,
213+
ProjectManager::Setuptools => {
214+
return format!(
215+
r#"from {source_dir}._version import VERSION
216+
217+
def test_versions_match():
218+
assert VERSION == "0.1.0""#
219+
)
220+
}
214221
};
215222

216-
Some(format!(
223+
format!(
217224
r#"import sys
218225
from pathlib import Path
219226
@@ -227,16 +234,13 @@ else:
227234
228235
{version_test}
229236
"#
230-
))
237+
)
231238
}
232239

233240
fn save_version_test_file(project_info: &ProjectInfo) -> Result<()> {
234-
if let Some(content) =
235-
create_version_test_file(&project_info.source_dir, &project_info.project_manager)
236-
{
237-
let file_path = project_info.base_dir().join("tests/test_version.py");
238-
save_file_with_content(&file_path, &content)?;
239-
};
241+
let file_path = project_info.base_dir().join("tests/test_version.py");
242+
let content = create_version_test_file(&project_info.source_dir, &project_info.project_manager);
243+
save_file_with_content(&file_path, &content)?;
240244

241245
Ok(())
242246
}

0 commit comments

Comments
 (0)