Skip to content

Commit b66e8e7

Browse files
committed
Allow to choose Poetry or uv as package manager
1 parent 1ff16c9 commit b66e8e7

File tree

5 files changed

+324
-13
lines changed

5 files changed

+324
-13
lines changed

hooks/post_gen_project.py

+16
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,21 @@ 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+
os.remove("poetry.lock")
44+
45+
46+
def remove_uv_files() -> None:
47+
os.remove("pyproject-uv.toml")
48+
os.remove("uv.lock")
49+
50+
4151
if __name__ == "__main__":
4252
write_env_file_with_secret_key()
53+
54+
if "{{ cookiecutter.package_manager }}" == "Poetry":
55+
remove_uv_files()
56+
elif "{{ cookiecutter.package_manager }}" == "uv":
57+
os.rename("pyproject-uv.toml", "pyproject.toml")
58+
remove_poetry_files()

{{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' %}
1516
COPY poetry.lock pyproject.toml /
1617
RUN pip install poetry==1.8.2 \
1718
&& poetry config virtualenvs.create false \
1819
&& poetry install --no-dev --no-root
20+
{%- endif %}
21+
22+
{%- if cookiecutter.package_manager == 'uv' %}
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

+25-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ 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+
{%- if cookiecutter.package_manager == 'uv' %}
11+
MANAGER = uv
812

913
###################################################################################################
1014
## Build/run/stop/etc. ############################################################################
@@ -46,7 +50,7 @@ migrate: # apply db migrations
4650

4751
test:
4852
@echo 'Running tests with arguments: '$(pytest-args)
49-
$(DC_RUN) django poetry run pytest --ds=settings.test -v $(pytest-args) .
53+
$(DC_RUN) django $(MANAGER) run pytest --ds=settings.test -v $(pytest-args) .
5054

5155
test-coverage:
5256
@echo 'Running test coverage with arguments: '$(pytest-args)
@@ -56,34 +60,43 @@ test-coverage:
5660
## Code tools #####################################################################################
5761

5862
install-pre-commit:
59-
poetry run pre-commit install
63+
$(MANAGER) run pre-commit install
6064

6165
check:
6266
{%- if cookiecutter.linter == 'Flake8' %}
63-
poetry run black --check backend
64-
poetry run isort --check backend
67+
$(MANAGER) run black --check backend
68+
$(MANAGER) run isort --check backend
6569
{%- endif %}
6670
{%- if cookiecutter.linter == 'Ruff' %}
67-
poetry run ruff check backend
71+
$(MANAGER) run ruff check backend
6872

6973
format:
7074
{%- if cookiecutter.linter == 'Flake8' %}
71-
poetry run black .
72-
poetry run isort .
75+
$(MANAGER) run black .
76+
$(MANAGER) run isort .
7377
{%- endif %}
7478
{%- if cookiecutter.linter == 'Ruff' %}
75-
poetry run ruff check --fix .
79+
$(MANAGER) run ruff check --fix .
7680

7781
lint:
7882
{%- if cookiecutter.linter == 'Flake8' %}
79-
poetry run flake8 --inline-quotes '"'
83+
$(MANAGER) run flake8 --inline-quotes '"'
8084
make check
85+
86+
format:
87+
$(MANAGER) run black .
88+
$(MANAGER) run isort .
89+
90+
lint:
91+
$(MANAGER) run black --check backend
92+
$(MANAGER) run isort --check backend
93+
$(MANAGER) run flake8 --inline-quotes '"'
8194
@# 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
95+
PYTHONPATH=./app $(MANAGER) run pylint app
96+
PYTHONPATH=./app $(MANAGER) run mypy --namespace-packages --show-error-codes app --check-untyped-defs --ignore-missing-imports --show-traceback
8497

8598
safety:
86-
poetry run safety check --policy-file=.safety-policy.yml
99+
$(MANAGER) run safety check --policy-file=.safety-policy.yml
87100

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

{{cookiecutter.project_name}}/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
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+
{%- if cookiecutter.package_manager == 'uv' %}
9+
* Install [uv](https://docs.astral.sh/uv/getting-started/installation/).
710
* Install [Docker](https://docs.docker.com/engine/install/)
811
* Install [docker-compose](https://docs.docker.com/compose/install/)
12+
{%- if cookiecutter.package_manager == 'Poetry' %}
913
* Run command `poetry install && poetry shell`
14+
{%- if cookiecutter.package_manager == 'uv' %}
15+
* Run command `uv venv .venv && uv install -r pyproject.toml`
1016
* Run command `make install-pre-commit`
1117
* Run command `make up`
1218
* Run command `make migrate`

0 commit comments

Comments
 (0)