Skip to content

Commit 2b010df

Browse files
authored
#6: Allow to choose Poetry or uv as package manager (#14)
* Allow to choose Poetry or uv as package manager * Fix invalid rebase on merge conflict * Remove lock file only if it exists * Change lines order to preserve pyproject-uv.toml pre deletion * Add package_manager choice, exclude .github and venv from Jinja2 rendering * Fix Jinja2 conditional statements * Add missing Ruff and pylint config to pyproject-uv.toml
1 parent 1047914 commit 2b010df

File tree

7 files changed

+357
-22
lines changed

7 files changed

+357
-22
lines changed

cookiecutter.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2-
"project_name": "evrone"
3-
"linter": ["Ruff", "Flake8"]
2+
"project_name": "evrone",
3+
"linter": ["Ruff", "Flake8"],
4+
"package_manager": ["Poetry", "uv"],
5+
"_copy_without_render": [".github", "venv", ".venv"]
46
}

hooks/post_gen_project.py

+18
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,23 @@ def write_env_file_with_secret_key():
3838
env_file.write(os.linesep)
3939

4040

41+
def remove_poetry_files() -> None:
42+
os.remove("pyproject.toml")
43+
if Path("poetry.lock").exists():
44+
os.remove("poetry.lock")
45+
46+
47+
def remove_uv_files() -> None:
48+
os.remove("pyproject-uv.toml")
49+
if Path("uv.lock").exists():
50+
os.remove("uv.lock")
51+
52+
4153
if __name__ == "__main__":
4254
write_env_file_with_secret_key()
55+
56+
if "{{ cookiecutter.package_manager }}" == "Poetry":
57+
remove_uv_files()
58+
elif "{{ cookiecutter.package_manager }}" == "uv":
59+
remove_poetry_files()
60+
os.rename("pyproject-uv.toml", "pyproject.toml")

{{cookiecutter.project_name}}/Dockerfile

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,19 @@ RUN chmod +x /start.sh
1212
COPY /scripts/start-dev.sh /start-dev.sh
1313
RUN chmod +x /start-dev.sh
1414

15+
{%- if cookiecutter.package_manager == 'Poetry' %}
16+
1517
COPY poetry.lock pyproject.toml /
1618
RUN pip install poetry==1.8.2 \
1719
&& poetry config virtualenvs.create false \
1820
&& poetry install --no-dev --no-root
21+
{%- elif cookiecutter.package_manager == 'uv' %}
22+
23+
COPY uv.lock pyproject.toml /
24+
RUN curl -LsSf https://astral.sh/uv/install.sh | sh \
25+
&& uv install -r pyproject.toml
26+
{%- endif %}
1927

2028
WORKDIR /app
2129

22-
COPY app ./
30+
COPY app ./

{{cookiecutter.project_name}}/Makefile

+19-15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ docker_compose_path = "docker-compose.yml"
55
DC = docker-compose -f $(docker_compose_path)
66
DC_RUN = $(DC) run --rm
77
DC_RUN_MNG = $(DC_RUN) django python manage.py
8+
{%- if cookiecutter.package_manager == 'Poetry' %}
9+
MANAGER = poetry
10+
{%- elif cookiecutter.package_manager == 'uv' %}
11+
MANAGER = uv
12+
{%- endif %}
813

914
###################################################################################################
1015
## Build/run/stop/etc. ############################################################################
@@ -46,7 +51,7 @@ migrate: # apply db migrations
4651

4752
test:
4853
@echo 'Running tests with arguments: '$(pytest-args)
49-
$(DC_RUN) django poetry run pytest --ds=settings.test -v $(pytest-args) .
54+
$(DC_RUN) django $(MANAGER) run pytest --ds=settings.test -v $(pytest-args) .
5055

5156
test-coverage:
5257
@echo 'Running test coverage with arguments: '$(pytest-args)
@@ -56,34 +61,33 @@ test-coverage:
5661
## Code tools #####################################################################################
5762

5863
install-pre-commit:
59-
poetry run pre-commit install
64+
$(MANAGER) run pre-commit install
6065

6166
check:
6267
{%- if cookiecutter.linter == 'Flake8' %}
63-
poetry run black --check backend
64-
poetry run isort --check backend
68+
$(MANAGER) run black --check backend
69+
$(MANAGER) run isort --check backend
70+
{%- elif cookiecutter.linter == 'Ruff' %}
71+
$(MANAGER) run ruff check backend
6572
{%- endif %}
66-
{%- if cookiecutter.linter == 'Ruff' %}
67-
poetry run ruff check backend
6873

6974
format:
7075
{%- if cookiecutter.linter == 'Flake8' %}
71-
poetry run black .
72-
poetry run isort .
76+
$(MANAGER) run black .
77+
$(MANAGER) run isort .
78+
{%- elif cookiecutter.linter == 'Ruff' %}
79+
$(MANAGER) run ruff check --fix .
7380
{%- endif %}
74-
{%- if cookiecutter.linter == 'Ruff' %}
75-
poetry run ruff check --fix .
7681

7782
lint:
78-
{%- if cookiecutter.linter == 'Flake8' %}
79-
poetry run flake8 --inline-quotes '"'
83+
{{ ' $(MANAGER) run flake8 --inline-quotes \'\"\'' if cookiecutter.linter == 'Flake8' }}
8084
make check
8185
@# For some reason, mypy and pylint fails to resolve PYTHONPATH, set manually.
82-
PYTHONPATH=./app poetry run pylint app
83-
PYTHONPATH=./app poetry run mypy --namespace-packages --show-error-codes app --check-untyped-defs --ignore-missing-imports --show-traceback
86+
PYTHONPATH=./app $(MANAGER) run pylint app
87+
PYTHONPATH=./app $(MANAGER) run mypy --namespace-packages --show-error-codes app --check-untyped-defs --ignore-missing-imports --show-traceback
8488

8589
safety:
86-
poetry run safety check --policy-file=.safety-policy.yml
90+
$(MANAGER) run safety check --policy-file=.safety-policy.yml
8791

8892
check-changed-loc:
8993
chmod +x ./scripts/pr-max-diff-checker.sh

{{cookiecutter.project_name}}/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33

44
## How to start project
55
* Install [Python](https://www.python.org/downloads/).
6+
{%- if cookiecutter.package_manager == 'Poetry' %}
67
* Install [poetry](https://python-poetry.org).
8+
{%- elif cookiecutter.package_manager == 'uv' %}
9+
* Install [uv](https://docs.astral.sh/uv/getting-started/installation/).
10+
{%- endif %}
711
* Install [Docker](https://docs.docker.com/engine/install/)
812
* Install [docker-compose](https://docs.docker.com/compose/install/)
13+
{%- if cookiecutter.package_manager == 'Poetry' %}
914
* Run command `poetry install && poetry shell`
15+
{%- elif cookiecutter.package_manager == 'uv' %}
16+
* Run command `uv venv .venv && uv install -r pyproject.toml`
17+
{%- endif %}
1018
* Run command `make install-pre-commit`
1119
* Run command `make up`
1220
* Run command `make migrate`

0 commit comments

Comments
 (0)