Skip to content

Commit 7faf243

Browse files
authored
refactor: manage pdm and pre-commit with make prerequisites (#637)
1 parent 36c1316 commit 7faf243

File tree

12 files changed

+82
-82
lines changed

12 files changed

+82
-82
lines changed

.devcontainer/Dockerfile

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ ENV PYTHONDONTWRITEBYTECODE=1
1717
ENV PYTHONHASHSEED=0
1818
ENV PYTHONUNBUFFERED=1
1919

20+
# Config pipx
21+
ENV PIPX_HOME=/usr/local/pipx
22+
ENV PIPX_BIN_DIR=/usr/local/bin
23+
ENV PIPX_DEFAULT_PYTHON=/usr/local/bin/python
24+
2025
# renovate: depName=debian_12/bash-completion
2126
ARG BASH_COMPLETION_VERSION="1:2.11-6"
2227
# renovate: depName=debian_12/pipx
@@ -26,27 +31,17 @@ ARG SUDO_VERSION="1.9.13p3-1+deb12u1"
2631
# renovate: depName=debian_12/vim
2732
ARG VIM_VERSION="2:9.0.1378-2"
2833

34+
# Install system dependencies and override pipx with a newer version
2935
RUN apt-get update && apt-get install -y --no-install-recommends \
3036
bash-completion="${BASH_COMPLETION_VERSION}" \
3137
pipx="${PIPX_VERSION}" \
3238
sudo="${SUDO_VERSION}" \
3339
vim="${VIM_VERSION}" \
34-
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
35-
36-
# Config pipx
37-
ENV PIPX_HOME=/usr/local/pipx
38-
ENV PIPX_BIN_DIR=/usr/local/bin
39-
ENV PIPX_DEFAULT_PYTHON=/usr/local/bin/python
40-
41-
# Install pdm
42-
RUN pipx install pdm==2.16.1
43-
44-
# Install pre-commit
45-
RUN if [ "${PYTHON_VERSION}" = "3.8" ]; then \
46-
pipx install pre-commit==3.5.0; \
47-
else \
48-
pipx install pre-commit==3.7.1; \
49-
fi
40+
&& pipx install pipx==1.6.0 \
41+
&& apt-get purge -y --autoremove pipx \
42+
&& apt-get clean -y \
43+
&& rm -rf /var/lib/apt/lists/* \
44+
&& hash -r
5045

5146
# Install prerequisites
5247
RUN --mount=source=Makefile,target=Makefile \

.renovaterc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
],
3030
"matchStrings": [
3131
"pip install.* (?<depName>.*?)==(?<currentValue>.*?)[\"\n]",
32-
"pipx install (?<depName>.*?)==(?<currentValue>.*?)[;\n]"
32+
"pipx install( --force)? (?<depName>.*?)==(?<currentValue>.*?)\n"
3333
]
3434
},
3535
{

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
# Documentation target directory, will be adapted to specific folder for readthedocs.
88
PUBLIC_DIR := $(shell [ "$$READTHEDOCS" = "True" ] && echo "$${READTHEDOCS_OUTPUT}html" || echo "public")
99

10+
# Determine the Python version used by pipx.
11+
PIPX_PYTHON_VERSION := $(shell `pipx environment --value PIPX_DEFAULT_PYTHON` -c "from sys import version_info; print(f'{version_info.major}.{version_info.minor}')")
12+
1013
########################################################################################
1114
# Development Environment Management
1215
########################################################################################
@@ -53,6 +56,12 @@ dev:
5356

5457
# Install standalone tools
5558
prerequisites:
59+
pipx install --force pdm==2.16.1
60+
ifeq ($(PIPX_PYTHON_VERSION), 3.8)
61+
pipx install --force pre-commit==3.5.0
62+
else
63+
pipx install --force pre-commit==3.7.1
64+
endif
5665
pipx install --force pyproject-fmt==2.1.4
5766
pipx install --force ruff==0.5.0
5867

README.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,12 @@ If you find this helpful, please consider [sponsorship](https://github.com/spons
5757

5858
## 🔧 Prerequisites
5959

60-
Certain system-level Python applications are needed and it is recommended to use [pipx](https://pypa.github.io/pipx/) to install and run them in isolated environments. Refer to pipx's installation instructions [here](https://pypa.github.io/pipx/installation/). Once `pipx` is set up, install the necessary tools using the following commands.
60+
[pipx](https://pipx.pypa.io/) is required to manage the standalone tools used across the development lifecycle.
61+
Please refer to pipx's installation instructions [here](https://pipx.pypa.io/stable/installation/).
62+
Once pipx is set up, install the copier for project generation using the following command:
6163

6264
```bash
63-
# Copier: Template rendering for projects.
6465
pipx install copier==9.2.0
65-
# PDM: A modern Python package and dependency manager supporting the latest PEP standards.
66-
pipx install pdm==2.16.1
67-
# Pre-commit: Automates Git hooks for code quality checks.
68-
pipx install pre-commit==3.7.1
6966
```
7067

7168
## 🚀 Quickstart
@@ -76,27 +73,33 @@ pipx install pre-commit==3.7.1
7673
copier copy gh:serious-scaffold/ss-python /path/to/project
7774
```
7875

79-
2. Navigate to the project directory and initialize a git repository.
76+
1. Navigate to the project directory and initialize a git repository.
8077

8178
```bash
8279
cd /path/to/project
8380
git init
8481
```
8582

86-
3. Set up the development environment.
83+
1. Install standalone tools.
84+
85+
```bash
86+
make prerequisites
87+
```
88+
89+
1. Set up the development environment.
8790

8891
```bash
8992
make dev
9093
```
9194

92-
4. Commit the initialized project.
95+
1. Commit the initialized project.
9396

9497
```bash
9598
git add .
9699
git commit -m "Initialize from serious-scaffold."
97100
```
98101

99-
5. That's it! Feel free to focus on the coding within `src` folder.
102+
1. That's it! Feel free to focus on the coding within `src` folder.
100103

101104
## 📜 License
102105

docs/development/setup-dev-env.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@ This page shows the approach to set up development environment. To simplify the
44

55
## Prerequisites
66

7-
Several necessary tools need to be installed with the following commands:
8-
9-
```{note}
10-
Using `pipx` for management is recommended and you can find pipx's installation instructions [here](https://pypa.github.io/pipx/installation/).
11-
```
7+
[pipx](https://pipx.pypa.io/) is required to manage the standalone tools used across the development lifecycle.
8+
Please refer to pipx's installation instructions [here](https://pipx.pypa.io/stable/installation/).
9+
Once pipx is set up, install the needed standalone tools with the following command:
1210

1311
```bash
14-
# PDM: A modern Python package and dependency manager supporting the latest PEP standards.
15-
pipx install pdm==2.16.1
16-
# Pre-commit: Automates Git hooks for code quality checks.
17-
pipx install pre-commit==3.7.1
12+
make prerequisites
1813
```
1914

2015
## Setup

docs/management/init.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
## Prerequisites
44

5-
Install [copier](https://copier.readthedocs.io/) for template operations. It is recommended to install via [pipx](https://pipx.pypa.io/) with the following command:
6-
7-
```{note}
8-
Find pipx installation instruction [here](https://pipx.pypa.io/stable/installation/).
9-
```
5+
[pipx](https://pipx.pypa.io/) is required to manage the standalone tools used across the development lifecycle.
6+
Please refer to pipx's installation instructions [here](https://pipx.pypa.io/stable/installation/).
7+
Once pipx is set up, install the copier for project generation using the following command:
108

119
```bash
1210
pipx install copier==9.2.0

includes/sample.jinja

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,12 @@ If you find this helpful, please consider [sponsorship](https://github.com/spons
3333

3434
## 🔧 Prerequisites
3535

36-
Certain system-level Python applications are needed and it is recommended to use [pipx](https://pypa.github.io/pipx/) to install and run them in isolated environments. Refer to pipx's installation instructions [here](https://pypa.github.io/pipx/installation/). Once `pipx` is set up, install the necessary tools using the following commands.
36+
[pipx](https://pipx.pypa.io/) is required to manage the standalone tools used across the development lifecycle.
37+
Please refer to pipx's installation instructions [here](https://pipx.pypa.io/stable/installation/).
38+
Once pipx is set up, install the copier for project generation using the following command:
3739

3840
```bash
39-
# Copier: Template rendering for projects.
4041
pipx install copier==9.2.0
41-
# PDM: A modern Python package and dependency manager supporting the latest PEP standards.
42-
pipx install pdm==2.16.1
43-
# Pre-commit: Automates Git hooks for code quality checks.
44-
pipx install pre-commit==3.7.1
4542
```
4643

4744
## 🚀 Quickstart
@@ -52,26 +49,32 @@ pipx install pre-commit==3.7.1
5249
copier copy gh:serious-scaffold/ss-python /path/to/project
5350
```
5451

55-
2. Navigate to the project directory and initialize a git repository.
52+
1. Navigate to the project directory and initialize a git repository.
5653

5754
```bash
5855
cd /path/to/project
5956
git init
6057
```
6158

62-
3. Set up the development environment.
59+
1. Install standalone tools.
60+
61+
```bash
62+
make prerequisites
63+
```
64+
65+
1. Set up the development environment.
6366

6467
```bash
6568
make dev
6669
```
6770

68-
4. Commit the initialized project.
71+
1. Commit the initialized project.
6972

7073
```bash
7174
git add .
7275
git commit -m "Initialize from serious-scaffold."
7376
```
7477

75-
5. That's it! Feel free to focus on the coding within `src` folder.
78+
1. That's it! Feel free to focus on the coding within `src` folder.
7679

7780
[%- endmacro %]

template/.devcontainer/Dockerfile.jinja

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ ENV PYTHONDONTWRITEBYTECODE=1
1717
ENV PYTHONHASHSEED=0
1818
ENV PYTHONUNBUFFERED=1
1919

20+
# Config pipx
21+
ENV PIPX_HOME=/usr/local/pipx
22+
ENV PIPX_BIN_DIR=/usr/local/bin
23+
ENV PIPX_DEFAULT_PYTHON=/usr/local/bin/python
24+
2025
# renovate: depName=debian_12/bash-completion
2126
ARG BASH_COMPLETION_VERSION="1:2.11-6"
2227
# renovate: depName=debian_12/pipx
@@ -26,27 +31,17 @@ ARG SUDO_VERSION="1.9.13p3-1+deb12u1"
2631
# renovate: depName=debian_12/vim
2732
ARG VIM_VERSION="2:9.0.1378-2"
2833

34+
# Install system dependencies and override pipx with a newer version
2935
RUN apt-get update && apt-get install -y --no-install-recommends \
3036
bash-completion="${BASH_COMPLETION_VERSION}" \
3137
pipx="${PIPX_VERSION}" \
3238
sudo="${SUDO_VERSION}" \
3339
vim="${VIM_VERSION}" \
34-
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
35-
36-
# Config pipx
37-
ENV PIPX_HOME=/usr/local/pipx
38-
ENV PIPX_BIN_DIR=/usr/local/bin
39-
ENV PIPX_DEFAULT_PYTHON=/usr/local/bin/python
40-
41-
# Install pdm
42-
RUN pipx install pdm==2.16.1
43-
44-
# Install pre-commit
45-
RUN if [ "${PYTHON_VERSION}" = "3.8" ]; then \
46-
pipx install pre-commit==3.5.0; \
47-
else \
48-
pipx install pre-commit==3.7.1; \
49-
fi
40+
&& pipx install pipx==1.6.0 \
41+
&& apt-get purge -y --autoremove pipx \
42+
&& apt-get clean -y \
43+
&& rm -rf /var/lib/apt/lists/* \
44+
&& hash -r
5045

5146
# Install prerequisites
5247
RUN --mount=source=Makefile,target=Makefile \

template/.renovaterc.json.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
],
3333
"matchStrings": [
3434
"pip install.* (?<depName>.*?)==(?<currentValue>.*?)[\"\n]",
35-
"pipx install (?<depName>.*?)==(?<currentValue>.*?)[;\n]"
35+
"pipx install( --force)? (?<depName>.*?)==(?<currentValue>.*?)\n"
3636
]
3737
},
3838
{

template/Makefile.jinja

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
# Documentation target directory, will be adapted to specific folder for readthedocs.
1010
PUBLIC_DIR := $(shell [ "$$READTHEDOCS" = "True" ] && echo "$${READTHEDOCS_OUTPUT}html" || echo "public")
1111

12+
# Determine the Python version used by pipx.
13+
PIPX_PYTHON_VERSION := $(shell `pipx environment --value PIPX_DEFAULT_PYTHON` -c "from sys import version_info; print(f'{version_info.major}.{version_info.minor}')")
14+
1215
########################################################################################
1316
# Development Environment Management
1417
########################################################################################
@@ -55,6 +58,12 @@ dev:
5558

5659
# Install standalone tools
5760
prerequisites:
61+
pipx install --force pdm==2.16.1
62+
ifeq ($(PIPX_PYTHON_VERSION), 3.8)
63+
pipx install --force pre-commit==3.5.0
64+
else
65+
pipx install --force pre-commit==3.7.1
66+
endif
5867
pipx install --force pyproject-fmt==2.1.4
5968
pipx install --force ruff==0.5.0
6069

0 commit comments

Comments
 (0)