Skip to content
Merged

V2 #6

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

Python template with some awesome tools to quickstart a Python project with the industry best practices.
It includes automatic generation of API documentation, tests using PyTest, code coverage,
ruff linting to enforce standardized Python coding, virtual environments using Poetry, workflow automation using Poe the Poet,
ruff linting to enforce standardized Python coding, virtual environments using UV, workflow automation using Taskipy,
code formatting using black and a space optimized Dockerfile to kickstart your project and run tests using the power of Docker containers.

You only need to install [Cookiecutter](https://cookiecutter.readthedocs.io/en/1.7.2/usage.html)!
Expand Down Expand Up @@ -91,15 +91,15 @@ This Project depends on the following projects.
cookiecutter https://github.com/nullhack/python-project-template
# move into your newly created project folder
```
2. Install Poe the Poet and Poetry
2. Install UV and Taskipy
```sh
pip install --user --upgrade poethepoet poetry
pip install --user --upgrade uv taskipy
```
3. Let Poe do it's magic
3. Let Taskipy do it's magic
```sh
poe install-dev
poe test
poe run
uv pip install .[dev]
uv task test
uv task run
```

<p align="right">(<a href="#top">back to top</a>)</p>
Expand Down Expand Up @@ -162,6 +162,7 @@ This project was heavily based on some great references.
* [Best practices for Python projects in 2021](https://mitelman.engineering/blog/python-best-practice/automating-python-best-practices-for-a-new-project/)
* [5 Pytest Best Practices for Writing Great Python Tests](https://www.nerdwallet.com/blog/engineering/5-pytest-best-practices/)
* [Best-README-Template](https://github.com/othneildrew/Best-README-Template)
* [Beyond Hypermodern: Python is easy now](https://rdrn.me/postmodern-python/)

<p align="right">(<a href="#top">back to top</a>)</p>

Expand Down
32 changes: 12 additions & 20 deletions {{cookiecutter.project_slug}}/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@
ARG BUILDPLATFORM=linux/amd64
ARG BUILDTAG=3-alpine

FROM --platform=$BUILDPLATFORM python:$BUILDTAG as test
FROM --platform=$BUILDPLATFORM python:3-alpine as test

WORKDIR /home/user/app

ENV PATH=$PATH:/home/user/.local/bin

RUN pip install --no-cache poetry poethepoet
RUN poetry config --no-cache
COPY pyproject.toml .
COPY poetry.lock .
RUN poetry install --no-root
RUN apk add --no-cache build-base linux-headers
RUN pip install --no-cache uv taskipy

COPY ./ ./
RUN poetry install

RUN pip install -e '.[dev]'

ARG TESTBUILD=True
ENV TESTBUILD=$TESTBUILD
RUN if [ "$TESTBUILD" = 'True' ]; then poe lint; fi
RUN if [ "$TESTBUILD" = 'True' ]; then poe test; fi
RUN if [ "$TESTBUILD" = 'True' ]; then task lint; fi
RUN if [ "$TESTBUILD" = 'True' ]; then task test; fi

RUN poetry build --format=wheel
RUN poetry export --only main -f requirements.txt --without-hashes --output requirements.txt
RUN uv build --wheel --out-dir dist

ENTRYPOINT ["poe", "-q"]
CMD ["test"]
CMD ["task", "test"]

FROM --platform=$BUILDPLATFORM python:$BUILDTAG as prod
FROM --platform=$BUILDPLATFORM python:3-alpine as prod

RUN addgroup --system user && adduser --system user --ingroup user
USER user

WORKDIR /home/user/app

COPY --chown=user:user --from=test /home/user/app/requirements.txt requirements.txt
COPY --chown=user:user --from=test /home/user/app/dist dist

USER root
RUN pip install --no-cache -r requirements.txt dist/*.whl
USER user
RUN pip install --no-cache dist/*.whl

ENTRYPOINT ["python", "-m", "{{cookiecutter.package_name}}.{{cookiecutter.module_name}}"]
CMD ["python", "-m", "{{cookiecutter.package_name}}.{{cookiecutter.module_name}}"]

36 changes: 18 additions & 18 deletions {{cookiecutter.project_slug}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ To run this project locally, you will need to install the prerequisites and foll
### Prerequisites

This Project depends on the following projects.
* Poetry
* UV
```sh
pip install --user --upgrade poetry
pip install --user --upgrade uv
```

* Poe the Poet
* Taskipy
```sh
pip install --user --upgrade poethepoet
pip install --user --upgrade taskipy
```

### Installation
Expand All @@ -93,17 +93,17 @@ This Project depends on the following projects.
git clone https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}
cd {{cookiecutter.project_slug}}
```
2. Install Poe the Poet and Poetry
2. Install UV and taskipy
```sh
pip install --user --upgrade poethepoet poetry
pip install --user --upgrade uv taskipy
```
3. Install requirements for development
```sh
poe install-dev
uv pip install '.[dev]'
```
4. Run tests
```sh
poe test
uv run task test
```

<p align="right">(<a href="#top">back to top</a>)</p>
Expand All @@ -117,34 +117,34 @@ Some useful examples of how this project can be used:

* Install requirements
```sh
poe install-dev
uv run task '.[dev]'
```

* Run tests
```sh
poe test
uv run task test
```

* Run the project
```sh
poe run
uv run main.py
```

* Generate API documentation
```sh
poe doc
uv run task doc-html
```

* Build a docker image for tests
```sh
poe docker-build --target test --build-tag 3.10-alpine
docker run -ti --rm {{cookiecutter.package_name}}:test-3.10-alpine
docker build --target test -t {{cookiecutter.package_name}}:test
docker run -ti --rm {{cookiecutter.package_name}}:test
```

* Build a docker image to run the root files only without running any test
```sh
poe docker-build --target prod --build-tag 3.10-alpine --no-test
docker run -ti --rm {{cookiecutter.package_name}}:prod-3.10-alpine
docker build --target prod -t {{cookiecutter.package_name}}:prod
docker run -ti --rm {{cookiecutter.package_name}}:prod
```


Expand All @@ -160,7 +160,7 @@ _For more examples, please refer to the [Documentation](https://{{cookiecutter.g
- [x] Add tests
- [x] Add code coverage
- [x] Improve documentation
- [ ] Include more tests
- [ ] Watch for new best standards

See the [open issues](https://github.com/{{cookiecutter.github_username}}/{{cookiecutter.project_slug}}/issues) for a full list of proposed features (and known issues).

Expand Down Expand Up @@ -198,7 +198,7 @@ Project Link: [https://github.com/{{cookiecutter.github_username}}/{{cookiecutte
<!-- ACKNOWLEDGMENTS -->
## Acknowledgments

This project was created using cookiecutter and NullHack's python-project-template:
This project was created using cookiecutter and Nullhack's python-project-template:

* [NullHack's python-project-template](https://github.com/nullhack/python-project-template/)

Expand Down
1 change: 0 additions & 1 deletion {{cookiecutter.project_slug}}/docs/docs/tests.md

This file was deleted.

1 change: 0 additions & 1 deletion {{cookiecutter.project_slug}}/docs/mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ nav:
- ... | glob=readme.md
- reference.md
- ... | regex=scenarios/.+.md
- tests.md
19 changes: 19 additions & 0 deletions {{cookiecutter.project_slug}}/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Test main file."""

import logging

logger = logging.Logger(__name__)
sh = logging.StreamHandler()
sh.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
sh.setFormatter(formatter)
logger.addHandler(sh)


def main() -> None:
"""Just a main function."""
logger.info("Hello from python-project-uv!")


if __name__ == "__main__":
main()
Loading