Skip to content

Commit 7af0fd4

Browse files
feat: Switch package management from pipenv to uv (#1155)
* feat: Switch package management from pipenv to uv * line break * Get rid of tox * Update readme * setup
1 parent d3770bc commit 7af0fd4

File tree

11 files changed

+827
-131
lines changed

11 files changed

+827
-131
lines changed

.github/workflows/functional-test.yml

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,12 @@ jobs:
7171
with:
7272
python-version: 3.12
7373

74-
- run: |
75-
# Separate 'run' creates differnet pipenv env. Does them in one run for now.
76-
pip install --upgrade pip
77-
pip install --upgrade pipenv
78-
pipenv lock --clear
79-
pipenv install -d --system
80-
pytest ${{ matrix.test_targets.target}} --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
74+
- name: Install uv
75+
run: make install-uv
76+
77+
- name: Run Tests
78+
run: |
79+
uv run pytest ${{ matrix.test_targets.target}} --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
8180
env:
8281
LOCAL_PREBUILT_WDA: ${{ github.workspace }}/wda/WebDriverAgentRunner-Runner.app
8382

@@ -161,12 +160,8 @@ jobs:
161160
api-level: ${{ env.API_LEVEL }}
162161
arch: ${{ env.ARCH }}
163162
script: |
164-
# Separate 'run' creates differnet pipenv env. Does them in one run for now.
165-
pip install --upgrade pip
166-
pip install --upgrade pipenv
167-
pipenv lock --clear
168-
pipenv install -d --system
169-
pytest ${{ matrix.test_targets.target}} --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
163+
make install-uv
164+
uv run pytest ${{ matrix.test_targets.target}} --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
170165
target: google_apis
171166
profile: Nexus 5X
172167
disable-spellchecker: true
@@ -251,12 +246,8 @@ jobs:
251246
with:
252247
api-level: ${{ env.API_LEVEL }}
253248
script: |
254-
pip install --upgrade pip
255-
pip install --upgrade pipenv
256-
pipenv lock --clear
257-
pipenv install -d --system
258-
export PLATFORM=android
259-
pytest test/functional/flutter_integration/*_test.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
249+
make install-uv
250+
uv run pytest test/functional/flutter_integration/*_test.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
260251
target: default
261252
disable-spellchecker: true
262253
disable-animations: true
@@ -296,10 +287,6 @@ jobs:
296287
- name: Run IOS tests
297288
if: matrix.e2e-tests == 'flutter-ios'
298289
run: |
299-
# Separate 'run' creates differnet pipenv env. Does them in one run for now.
300-
pip install --upgrade pip
301-
pip install --upgrade pipenv
302-
pipenv lock --clear
303-
pipenv install -d --system
290+
make install-uv
304291
export PLATFORM=ios
305-
pytest test/functional/flutter_integration/*_test.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
292+
uv run pytest test/functional/flutter_integration/*_test.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html

.github/workflows/unit-test.yml

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,7 @@ jobs:
1919
uses: actions/setup-python@v5
2020
with:
2121
python-version: ${{ matrix.python-version }}
22-
- name: Install tox
23-
run: pip install tox
24-
- name: Run Tox
25-
run: tox -e py
26-
27-
# test-win:
28-
# runs-on: windows-latest
29-
# strategy:
30-
# matrix:
31-
# python-version: ["3.7", "3.8", "3.9", "3.10"]
32-
# steps:
33-
# - uses: actions/checkout@v3
34-
# - name: Set up Python ${{ matrix.python-version }}
35-
# uses: actions/setup-python@v3
36-
# with:
37-
# python-version: ${{ matrix.python-version }}
38-
# - name: Install tox
39-
# run: pip install tox
40-
# - name: Run Tox
41-
# run: tox -e py
22+
- name: Install uv
23+
run: make install-uv
24+
- name: Run Unit Tests
25+
run: uv run pytest test/unit

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ __pycache__
2424

2525
# Virtual Environments
2626
venv*
27+
.venv
2728
.tox
2829

29-
Pipfile.lock
30-
3130
.coverage

Makefile

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,42 @@ check: check-lint check-format
1010

1111
.PHONY: check-lint
1212
check-lint:
13-
python -m ruff check .
13+
uv run ruff check .
1414

1515
.PHONY: check-format
1616
check-format:
17-
python -m ruff format --check .
17+
uv run ruff format --check .
1818

1919
.PHONY: fix
2020
fix: fix-lint fix-format
2121

2222
.PHONY: fix-lint
2323
fix-lint:
24-
python -m ruff check --fix .
24+
uv run ruff check --fix .
2525

2626
.PHONY: fix-format
2727
fix-format:
28-
python -m ruff format .
29-
28+
uv run ruff format .
29+
30+
.PHONY: install-uv
31+
install-uv:
32+
@command -v uv >/dev/null 2>&1 || { \
33+
echo "Installing uv"; \
34+
curl -LsSf https://astral.sh/uv/install.sh | sh; \
35+
if [ -n "$$GITHUB_PATH" ]; then \
36+
echo "PATH=$$HOME/.local/bin:$$PATH" >> $$GITHUB_PATH; \
37+
else \
38+
echo "Please restart your shell or run 'exec $$SHELL'"; \
39+
fi; \
40+
}
41+
42+
.PHONY: sync-dev
43+
sync-dev:
44+
uv sync
3045

3146
.PHONY: unittest
3247
unittest: ## Run unittest
33-
python -m pytest $(ARGS) test/unit/
48+
uv run pytest $(ARGS) test/unit/
3449

3550
.PHONY: help
3651
help: ## Display this help screen

Pipfile

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

README.md

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ the Selenium Python binding update might affect the Appium Python Client behavio
5656
For example, some changes in the Selenium binding could break the Appium client.
5757

5858
> **Note**
59-
> We strongly recommend you manage dependencies with version management tools such as Pipenv and requirements.txt
60-
> to keep compatible version combinations.
59+
> We strongly recommend you manage dependencies with version management tools such as
60+
> [uv](https://docs.astral.sh/uv/) to keep compatible version combinations.
6161

6262

6363
### Quick migration guide from v4 to v5
@@ -448,61 +448,82 @@ You have two methods to extend the read timeout.
448448
449449
### Setup
450450
451-
- `pip install --user pipenv`
452-
- `python -m pipenv lock --clear`
453-
- If you experience `Locking Failed! unknown locale: UTF-8` error, then refer [pypa/pipenv#187](https://github.com/pypa/pipenv/issues/187) to solve it.
454-
- `python -m pipenv install --dev --system`
455-
- `pre-commit install`
451+
```bash
452+
make install-uv
453+
exec $SHELL
454+
make sync-dev
455+
```
456+
457+
Running above commands should automatically setup the virtual environment for the project
458+
using the default system Python version and put it into the `.venv` folder under the project root.
459+
If you'd like to customize the Python version then run the following command before `make sync-dev`:
460+
461+
```bash
462+
uv venv --python <V>
463+
```
464+
465+
where `<V>` is the actual Python version, for example `3.12`.
456466
457-
### Run tests
467+
If you want to customize the folder where uv stores the virtual environment by default
468+
(e.g. `.venv`) then add an argument containing the destination folder path to the above command:
469+
470+
```bash
471+
uv venv /venv/root/folder
472+
```
473+
474+
In order to activate the newly created virtual environment you may either source it:
475+
476+
```bash
477+
source /venv/root/folder/bin/activate
478+
```
458479
459-
You can run all of the tests running on CI via `tox` in your local.
480+
or add it to PATH:
460481
461482
```bash
462-
$ tox
483+
export "PATH=/venv/root/folder/bin:$PATH"
463484
```
464485
465-
You also can run particular tests like below.
486+
### Testing
466487
467488
#### Unit
468489
469490
```bash
470-
$ pytest test/unit
491+
uv run pytest test/unit
471492
```
472493
473-
Run with `pytest-xdist`
494+
Run in parallel (2 threads)
474495
475496
```bash
476-
$ pytest -n 2 test/unit
497+
uv run pytest -n 2 test/unit
477498
```
478499
479500
#### Functional
480501
481502
```bash
482-
$ pytest test/functional/ios/search_context/find_by_ios_class_chain_tests.py
503+
uv run pytest test/functional/ios/search_context/find_by_ios_class_chain_tests.py
483504
```
484505
485506
#### In parallel for iOS
486507
487508
1. Create simulators named 'iPhone X - 8100' and 'iPhone X - 8101'
488-
2. Install test libraries via pip, `pip install pytest pytest-xdist`
489-
3. Run tests
509+
1. Run tests
490510
491511
```bash
492-
$ pytest -n 2 test/functional/ios/search_context/find_by_ios_class_chain_tests.py
512+
uv run pytest -n 2 test/functional/ios/search_context/find_by_ios_class_chain_tests.py
493513
```
494514
495515
## Release
496516
497517
Follow the below steps.
498518
499519
```bash
500-
$ pip install twine
501-
$ pip install git+git://github.com/vaab/gitchangelog.git # Getting via GitHub repository is necessary for Python 3.7
520+
uv pip install setuptools
521+
uv pip install twine
522+
uv pip install git+https://github.com/vaab/gitchangelog.git # Getting via GitHub repository is necessary for Python 3.7
502523
# Type the new version number and 'yes' if you can publish it
503524
# You can test the command with DRY_RUN
504-
$ DRY_RUN=1 ./release.sh
505-
$ ./release.sh # release
525+
DRY_RUN=1 ./release.sh
526+
./release.sh # release
506527
```
507528
508529
If the `pypi` was not able to publish with user name and password, please try out `-u` and `-p` option by yourself with `twine` such as `twine upload -u <name> -p <pass> dist/Appium-Python-Client-4.1.0.tar.gz`.

pyproject.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[project]
2+
name = "Appium-Python-Client"
3+
dynamic = [
4+
"version",
5+
"description",
6+
"readme",
7+
"license",
8+
"authors",
9+
"maintainers",
10+
"keywords",
11+
"classifiers"
12+
]
13+
requires-python = ">=3.9"
14+
dependencies = [
15+
"selenium>=4.26,<5.0",
16+
"typing-extensions~=4.13.2",
17+
]
18+
19+
[tool.uv]
20+
dev-dependencies = [
21+
"httpretty~=1.1",
22+
"mock~=5.2",
23+
"pre-commit~=4.2",
24+
"pytest~=8.4",
25+
"pytest-cov~=6.2",
26+
"pytest-xdist~=3.8",
27+
"python-dateutil~=2.9",
28+
"ruff~=0.12.7",
29+
"types-python-dateutil~=2.9",
30+
]
31+
32+
[build-system]
33+
requires = ["hatchling"]
34+
build-backend = "hatchling.build"
35+
36+
[tool.hatch.version]
37+
source = "regex"
38+
path = "appium/version.py"
39+
pattern = "(?P<version>\\d+\\.\\d+\\.\\d+)"
40+
41+
[tool.hatch.build.targets.wheel]
42+
packages = ["appium"]

release.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
set -e
44
set -o pipefail
55

6-
if [ -z "$PYTHON_BIN_PATH" ]; then
7-
PYTHON_BIN_PATH=$(which python || true)
8-
fi
9-
10-
export PYTHON_BIN_PATH
11-
126
CONFIGURE_DIR=$(dirname "$0")
13-
"$PYTHON_BIN_PATH" "${CONFIGURE_DIR}/script/release.py" "$@"
7+
uv run python "${CONFIGURE_DIR}/script/release.py" "$@"
148

159
echo "Finish release process"

script/release.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ def commit_version_code(new_version_num):
6666

6767
def tag_and_generate_changelog(new_version_num):
6868
call_bash_script('git tag "v{}"'.format(new_version_num))
69-
call_bash_script('gitchangelog > {}'.format(CHANGELOG_PATH))
69+
call_bash_script('uv run gitchangelog > {}'.format(CHANGELOG_PATH))
7070
call_bash_script('git commit {} -m "Update changelog for {}"'.format(CHANGELOG_PATH, new_version_num))
7171

7272

7373
def upload_sdist(new_version_num):
7474
push_file = 'dist/appium_python_client-{}.tar.gz'.format(new_version_num)
7575
try:
76-
call_bash_script('twine upload "{}"'.format(push_file))
76+
call_bash_script('uv run twine upload "{}"'.format(push_file))
7777
except Exception as e:
7878
print(
7979
'Failed to upload {} to pypi. Please fix the original error and push it again later. Original error: {}'.format(
@@ -99,21 +99,12 @@ def ensure_publication(new_version_num):
9999

100100

101101
def build_sdist():
102-
call_bash_script('{} setup.py sdist'.format(sys.executable))
103-
104-
105-
def validate_release_env():
106-
if os.system('which twine') != 0:
107-
sys.exit("Please get twine via 'pip install twine'")
108-
if os.system('which gitchangelog') != 0:
109-
sys.exit(
110-
"Please get twine via 'pip install gitchangelog' or 'pip install git+git://github.com/vaab/gitchangelog.git' for Python 3.7"
111-
)
102+
call_bash_script('uv run python setup.py sdist')
112103

113104

114105
def build() -> None:
115106
shutil.rmtree(BUILT_APPIUM_DIR_PATH, ignore_errors=True)
116-
status, output = subprocess.getstatusoutput('{} setup.py install'.format(os.getenv('PYTHON_BIN_PATH')))
107+
status, output = subprocess.getstatusoutput('uv run python setup.py install')
117108
if status != 0:
118109
sys.exit(f'Failed to build the package:\n{output}')
119110

@@ -149,8 +140,6 @@ def assert_files_count_in_package() -> None:
149140

150141

151142
def main():
152-
validate_release_env()
153-
154143
get_current_version()
155144
new_version = get_new_version()
156145

0 commit comments

Comments
 (0)