Skip to content

Commit 0693535

Browse files
Merge pull request Backblaze#991 from Backblaze/pdm
Manage dependencies with PDM
2 parents 92ef2c8 + 3463fff commit 0693535

20 files changed

+1966
-373
lines changed

.github/workflows/cd.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
with:
2626
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
2727
- name: Install dependencies
28-
run: python -m pip install --upgrade nox pip setuptools
28+
run: python -m pip install --upgrade nox pdm
2929
- name: Build the distribution
3030
id: build
3131
run: nox -vs build >> $GITHUB_OUTPUT
@@ -64,7 +64,7 @@ jobs:
6464
run: |
6565
apt-get -y update
6666
apt-get -y install patchelf
67-
python -m pip install --upgrade nox pip setuptools
67+
python -m pip install --upgrade nox pdm
6868
git config --global --add safe.directory '*'
6969
- name: Bundle the distribution
7070
id: bundle
@@ -97,7 +97,7 @@ jobs:
9797
with:
9898
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
9999
- name: Install dependencies
100-
run: python -m pip install --upgrade nox pip setuptools
100+
run: python -m pip install --upgrade nox pdm
101101
- name: Bundle the distribution
102102
id: bundle
103103
shell: bash

.github/workflows/ci.yml

+25-28
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ jobs:
2020
with:
2121
ignore_words_list: datas re-use
2222
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
23-
uses: actions/setup-python@v4
23+
uses: actions/setup-python@v5
2424
with:
2525
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
2626
- name: Install dependencies
27-
run: python -m pip install --upgrade nox pip setuptools
27+
run: python -m pip install --upgrade nox pdm
2828
- name: Run linters
2929
run: nox -vs lint
3030
- name: Validate new changelog entries
@@ -45,7 +45,7 @@ jobs:
4545
with:
4646
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
4747
- name: Install dependencies
48-
run: python -m pip install --upgrade nox pip setuptools
48+
run: python -m pip install --upgrade nox pdm
4949
- name: Build the distribution
5050
run: nox -vs build >> $GITHUB_OUTPUT
5151
cleanup_buckets:
@@ -67,7 +67,7 @@ jobs:
6767
cache: "pip"
6868
- name: Install dependencies
6969
if: ${{ env.B2_TEST_APPLICATION_KEY != '' && env.B2_TEST_APPLICATION_KEY_ID != '' }} # TODO: skip this whole job instead
70-
run: python -m pip install --upgrade nox pip setuptools
70+
run: python -m pip install --upgrade nox pdm
7171
- name: Find and remove old buckets
7272
if: ${{ env.B2_TEST_APPLICATION_KEY != '' && env.B2_TEST_APPLICATION_KEY_ID != '' }} # TODO: skip this whole job instead
7373
run: nox -vs cleanup_buckets
@@ -81,31 +81,30 @@ jobs:
8181
fail-fast: false
8282
matrix:
8383
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
84-
# pypy version pin was required due 7.3.13 being broken https://foss.heptapod.net/pypy/pypy/-/issues/4021
85-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.10-nightly"]
84+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.9", "pypy3.10"]
8685
exclude:
8786
- os: "macos-latest"
88-
python-version: "pypy-3.10-nightly"
87+
python-version: "pypy3.10"
8988
- os: "windows-latest"
90-
python-version: "pypy-3.10-nightly"
89+
python-version: "pypy3.10"
9190
steps:
9291
- uses: actions/checkout@v3
9392
with:
9493
fetch-depth: 0
9594
- name: Set up Python ${{ matrix.python-version }}
96-
uses: actions/setup-python@v4
95+
uses: actions/setup-python@v5
9796
with:
9897
python-version: ${{ matrix.python-version }}
9998
- name: Install dependencies
100-
run: python -m pip install --upgrade nox pip setuptools
99+
run: python -m pip install --upgrade nox pdm
101100
- name: Run unit tests
102-
run: nox -vs unit
101+
run: nox -vs unit -p ${{ matrix.python-version }}
103102
- name: Run integration tests (without secrets)
104-
run: nox -vs integration -- -m "not require_secrets"
103+
run: nox -vs integration -p ${{ matrix.python-version }} -- -m "not require_secrets"
105104
- name: Run integration tests (with secrets)
106105
# Limit CI workload by running integration tests with secrets only on edge Python versions.
107-
if: ${{ env.B2_TEST_APPLICATION_KEY != '' && env.B2_TEST_APPLICATION_KEY_ID != '' && contains(fromJSON('["3.7", "pypy-3.10-nightly", "3.12"]'), matrix.python-version) }}
108-
run: nox -vs integration -- -m "require_secrets" --cleanup
106+
if: ${{ env.B2_TEST_APPLICATION_KEY != '' && env.B2_TEST_APPLICATION_KEY_ID != '' && contains(fromJSON('["3.7", "pypy3.10", "3.12"]'), matrix.python-version) }}
107+
run: nox -vs integration -p ${{ matrix.python-version }} -- -m "require_secrets" --cleanup
109108
test-docker:
110109
needs: cleanup_buckets
111110
env:
@@ -117,13 +116,11 @@ jobs:
117116
with:
118117
fetch-depth: 0
119118
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
120-
uses: actions/setup-python@v4
119+
uses: actions/setup-python@v5
121120
with:
122121
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
123-
- name: setup sudo NOX_PYTHONS
124-
run: echo NOX_PYTHONS=$(sudo python3 --version | cut -d ' ' -f 2) >> "$GITHUB_ENV"
125122
- name: Install dependencies
126-
run: sudo python -m pip install --upgrade nox pip setuptools
123+
run: sudo python -m pip install --upgrade nox pdm
127124
- name: Generate Dockerfile
128125
run: nox -vs generate_dockerfile
129126
- name: Set up QEMU
@@ -139,7 +136,7 @@ jobs:
139136
platforms: linux/amd64
140137
- name: Run tests with docker
141138
if: ${{ env.B2_TEST_APPLICATION_KEY != '' && env.B2_TEST_APPLICATION_KEY_ID != '' }}
142-
run: sudo NOX_PYTHONS=$NOX_PYTHONS B2_TEST_APPLICATION_KEY=${{ env.B2_TEST_APPLICATION_KEY }} B2_TEST_APPLICATION_KEY_ID=${{ env.B2_TEST_APPLICATION_KEY_ID }} nox -vs docker_test -- backblazeit/b2:test
139+
run: nox -vs docker_test -- backblazeit/b2:test
143140
test-linux-bundle:
144141
needs: cleanup_buckets
145142
env:
@@ -158,7 +155,7 @@ jobs:
158155
run: |
159156
apt-get -y update
160157
apt-get -y install patchelf
161-
python -m pip install --upgrade nox pip setuptools
158+
python -m pip install --upgrade nox pdm
162159
git config --global --add safe.directory '*'
163160
- name: Bundle the distribution
164161
id: bundle
@@ -167,10 +164,10 @@ jobs:
167164
id: hashes
168165
run: nox -vs make_dist_digest
169166
- name: Run integration tests (without secrets)
170-
run: nox -vs integration -- --sut=${{ steps.bundle.outputs.sut_path }} -m "not require_secrets"
167+
run: nox -vs integration -p ${{ env.PYTHON_DEFAULT_VERSION }} -- --sut=${{ steps.bundle.outputs.sut_path }} -m "not require_secrets"
171168
- name: Run integration tests (with secrets)
172169
if: ${{ env.B2_TEST_APPLICATION_KEY != '' && env.B2_TEST_APPLICATION_KEY_ID != '' }}
173-
run: nox -vs integration -- --sut=${{ steps.bundle.outputs.sut_path }} -m "require_secrets" --cleanup
170+
run: nox -vs integration -p ${{ env.PYTHON_DEFAULT_VERSION }} -- --sut=${{ steps.bundle.outputs.sut_path }} -m "require_secrets" --cleanup
174171
- name: Upload assets
175172
if: failure()
176173
uses: actions/upload-artifact@v2
@@ -193,11 +190,11 @@ jobs:
193190
with:
194191
fetch-depth: 0
195192
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
196-
uses: actions/setup-python@v4
193+
uses: actions/setup-python@v5
197194
with:
198195
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
199196
- name: Install dependencies
200-
run: python -m pip install --upgrade nox pip setuptools
197+
run: python -m pip install --upgrade nox pdm
201198
- name: Bundle the distribution
202199
id: bundle
203200
shell: bash
@@ -206,10 +203,10 @@ jobs:
206203
id: hashes
207204
run: nox -vs make_dist_digest
208205
- name: Run integration tests (without secrets)
209-
run: nox -vs integration -- --sut=${{ steps.bundle.outputs.sut_path }} -m "not require_secrets"
206+
run: nox -vs integration -p ${{ env.PYTHON_DEFAULT_VERSION }} -- --sut=${{ steps.bundle.outputs.sut_path }} -m "not require_secrets"
210207
- name: Run integration tests (with secrets)
211208
if: ${{ env.B2_TEST_APPLICATION_KEY != '' && env.B2_TEST_APPLICATION_KEY_ID != '' }}
212-
run: nox -vs integration -- --sut=${{ steps.bundle.outputs.sut_path }} -m "require_secrets" --cleanup
209+
run: nox -vs integration -p ${{ env.PYTHON_DEFAULT_VERSION }} -- --sut=${{ steps.bundle.outputs.sut_path }} -m "require_secrets" --cleanup
213210
- name: Upload assets
214211
if: failure()
215212
uses: actions/upload-artifact@v2
@@ -225,7 +222,7 @@ jobs:
225222
with:
226223
fetch-depth: 0
227224
- name: Set up Python ${{ env.PYTHON_DEFAULT_VERSION }}
228-
uses: actions/setup-python@v4
225+
uses: actions/setup-python@v5
229226
with:
230227
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
231228
- name: Install dependencies
@@ -234,6 +231,6 @@ jobs:
234231
run: |
235232
sudo apt-get update -y
236233
sudo apt-get install -y graphviz plantuml
237-
python -m pip install --upgrade nox pip setuptools
234+
python -m pip install --upgrade nox pdm
238235
- name: Build the docs
239236
run: nox --non-interactive -vs doc

.github/workflows/push_docker.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
with:
2222
python-version: ${{ env.PYTHON_DEFAULT_VERSION }}
2323
- name: Install dependencies
24-
run: python -m pip install --upgrade nox pip setuptools
24+
run: python -m pip install --upgrade nox pdm
2525
- name: Build Dockerfile
2626
run: nox -vs generate_dockerfile
2727
- name: Set up QEMU
@@ -34,11 +34,9 @@ jobs:
3434
with:
3535
username: ${{ secrets.DOCKERHUB_USERNAME }}
3636
password: ${{ secrets.DOCKERHUB_TOKEN }}
37-
- name: install setuptools_scm
38-
run: pip install setuptools_scm
3937
- name: get version
4038
id: package_version
41-
run: echo package_version=`python -m setuptools_scm` >> $GITHUB_OUTPUT
39+
run: echo package_version=`pdm show --version --quiet` >> $GITHUB_OUTPUT
4240
- name: echo
4341
run: echo ${{ steps.package_version.outputs.package_version }}
4442
- name: Build and push

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
.eggs/
55
.idea
66
.nox/
7+
.pdm-build/
8+
.pdm-python
79
.python-version
810
b2_cli.log
911
b2.egg-info
@@ -14,4 +16,4 @@ venv
1416
doc/source/main_help.rst
1517
Dockerfile
1618
b2/licenses_output.txt
17-
*.spec
19+
*.spec

.readthedocs.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ version: 2
88
build:
99
os: ubuntu-22.04
1010
tools:
11-
python: "3.11"
11+
python: "3.12"
12+
jobs:
13+
post_create_environment:
14+
- pip install pdm
15+
- pdm export --format requirements --prod --group doc --output requirements-doc.txt --no-hashes
1216

1317
# Build documentation in the docs/ directory with Sphinx
1418
sphinx:
@@ -20,8 +24,6 @@ formats: all
2024
# Optionally set the version of Python and requirements required to build your docs
2125
python:
2226
install:
23-
- requirements: requirements.txt
27+
- requirements: requirements-doc.txt
2428
- method: pip
25-
path: .
26-
extra_requirements:
27-
- doc
29+
path: .

CONTRIBUTING.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ for a given github issue).
5555

5656
## Developer Info
5757

58-
You'll need to have [nox](https://github.com/theacodes/nox) installed:
58+
You'll need to have [nox](https://github.com/theacodes/nox) and [pdm](https://pdm-project.org/) installed:
5959

60-
* `pip install nox`
60+
* `pip install nox pdm`
6161

6262
With `nox`, you can run different sessions (default are `lint` and `test`):
6363

@@ -69,7 +69,6 @@ With `nox`, you can run different sessions (default are `lint` and `test`):
6969
* `generate_dockerfile` -> generate dockerfile
7070
* `docker_test` -> run integration tests against a docker image
7171
* `build_and_test_docker` -> build a docker image and integration tests against it
72-
* `deploy` -> Deploy the distribution to the PyPi.
7372
* `doc` -> Build the documentation.
7473
* `doc_cover` -> Perform coverage analysis for the documentation.
7574

@@ -105,6 +104,14 @@ With the above setting, session `test` will run on Python 3.9 and 3.10, and all
105104

106105
Given Python interpreters should be installed in the operating system or via [pyenv](https://github.com/pyenv/pyenv).
107106

107+
## Managing dependencies
108+
109+
We use [pdm](https://pdm-project.org/) for managing dependencies and developing locally.
110+
If you want to change any of the project requirements (or requirement bounds) in `pyproject.toml`,
111+
make sure that `pdm.lock` file reflects those changes by using `pdm add`, `pdm update` or other
112+
commands - see [documentation](https://pdm-project.org/latest/). You can verify that lock file
113+
is up to date by running the linter.
114+
108115
## Linting
109116

110117
To run all available linters:

Dockerfile.template

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
FROM python:${python_version}-slim as base
1+
FROM python:${python_version}-slim as builder
2+
3+
RUN apt-get update -y && apt-get install git patchelf -y && pip install -U pdm
4+
5+
WORKDIR /b2
6+
COPY ./b2 /b2/b2
7+
COPY pyproject.toml pdm.lock LICENSE README.md /b2/
8+
9+
ENV PDM_BUILD_SCM_VERSION=${version}
10+
RUN pdm install --prod --group license
11+
RUN pdm run b2 license --dump --with-packages
12+
# Run pdm in PEP 582 mode, install packaged to __pypackages__, not virtualenv
13+
RUN rm -r .venv && mkdir __pypackages__ && pdm install --prod --group full --no-editable
14+
15+
FROM python:${python_version}-slim
216

317
LABEL vendor=${vendor}
418
LABEL name="${name}"
@@ -9,11 +23,10 @@ LABEL vcs-url="${vcs_url}"
923
LABEL vcs-ref="${vcs_ref}"
1024
LABEL build-date-iso8601="${build_date}"
1125

12-
WORKDIR /root
13-
14-
# due https://github.com/moby/moby/issues/47021 we cannot have /root/.cache leftover as it causes random errors in CI
15-
RUN --mount=type=bind,source=${tar_path}/${tar_name},target=/tmp/${tar_name} \
16-
pip install --no-cache-dir /tmp/${tar_name}[full] && rm -rf /root/.cache
26+
ENV PYTHONPATH=/opt/b2
27+
COPY --from=builder /b2/__pypackages__/${python_version}/lib /opt/b2
28+
COPY --from=builder /b2/__pypackages__/${python_version}/bin/* /bin/
1729

30+
WORKDIR /root
1831
ENTRYPOINT ["b2"]
1932
CMD ["--help"]

MANIFEST.in

-4
This file was deleted.

changelog.d/+pdm.infrastructure.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use pdm for building, testing and managing dependencies. Remove unnecessary files (continuous integration scripts, tests) from sdist tarball.

0 commit comments

Comments
 (0)