Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ lint: ## Run Python linter

.PHONY: test
test: ## Run the tests
poetry run pytest tests
poetry run pytest -n auto tests

.PHONY: install
install: ## Install the dependencies excluding dev.
Expand All @@ -31,7 +31,7 @@ megalint: ## Run the mega-linter.
oxsecurity/megalinter:v9

.PHONY: update-template-packages
update-template-packages: ## Update the project using the initial copier template.
update-template-packages: ## Refresh package-manager template files and lockfiles.
cd scripts/package_manager_helper && ./update_template_packages.sh && cd ../..

.PHONY: clean
Expand Down
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ template.

This template includes a number of features to help you get started developing your Python project quickly:

- Python package/environment management with [Poetry](https://python-poetry.org/)
or [Pipenv](https://pipenv.pypa.io/en/latest/)
- Python package/environment management with [Poetry](https://python-poetry.org/),
[Pipenv](https://pipenv.pypa.io/en/latest/), or [uv](https://docs.astral.sh/uv/)
- Python Linting/Formatting with:
- [Ruff](https://github.com/astral-sh/ruff) - An all-in-one alternative to tools such as flake8, isort, pydocstyle,
pyupgrade, autoflake etc.
Expand Down Expand Up @@ -102,7 +102,8 @@ To get started:

#### Prerequisites

1. **Python 3.10+**: We recommend using [pyenv](https://github.com/pyenv/pyenv) for managing Python versions.
1. **Python 3.10+**: We recommend using [pyenv](https://github.com/pyenv/pyenv) or
[uv](https://docs.astral.sh/uv/) for managing Python versions.
2. **[Pip](https://pip.pypa.io/en/stable/installation/) or [Pipx](https://pipx.pypa.io/stable/)**
3. **[Copier](https://github.com/copier-org/copier)**: Install Copier using pip or pipx.

Expand Down Expand Up @@ -239,10 +240,11 @@ make copier-update
```

Copier will ask you all questions again, but default values will be those you answered last time. Just hit Enter to
accept those defaults, or change them if needed or you can use `poetry run copier update --force` instead to avoid
answering the questions again.
accept those defaults, or change them if needed or you can use your chosen package manager to run
`copier update --force` instead to avoid answering the questions again.

For more see [Copier docs](https://copier.readthedocs.io/en/stable/updating/) and `poetry run copier --help-all`.
For more see [Copier docs](https://copier.readthedocs.io/en/stable/updating/) and your package manager's
`copier --help-all` wrapper command.
</details>

## Structure
Expand Down Expand Up @@ -277,16 +279,17 @@ The structure of the templated repo is as follows:
├── .gitignore # Specifies intentionally untracked files to ignore when using Git, like build outputs and temporary files.
├── .mega-linter.yml # Configuration file for MegaLinter, specifying the linters and code analysers to be used.
├── .pylintrc # Configuration file for Pylint.
├── .python-version # Specifies the Python version to be used with pyenv.
├── .python-version # Specifies the Python version for the project. This can be used with pyenv or pinned via uv.
├── CODE_OF_CONDUCT.md # A code of conduct for the project, outlining the standards of behaviour for contributors.
├── CONTRIBUTING.md # Guidelines for contributing to the project, including information on how to raise issues and submit pull requests.
├── LICENSE # The license under which the project is made available. (Public Repos Only)
├── Makefile # A script used with the make build automation tool, containing commands to automate common tasks.
├── PIRR.md # Private Internal Reasoning Record (PIRR) for the repository, documenting the reasoning for the private/internal status of the repository. (Private/Internal Repos Only)
├── poetry.lock # Lock file for Poetry, pinning exact versions of dependencies to ensure consistent builds. (Exists if poetry is selected as the package manager)
├── pyproject.toml # Central project configuration file for Python, used by Poetry package manager and tools like Ruff, black etc.
├── pyproject.toml # Central project configuration file for Python, used by Poetry or uv and tooling like Ruff, black etc.
├── Pipfile # Used by pipenv package manager to specify dependencies and their versions. (Exists if pipenv is selected as the package manager)
├── Pipfile.lock # Lock file for Poetry, pinning exact versions of dependencies to ensure consistent builds. (Exists if pipenv is selected as the package manager)
├── Pipfile.lock # Lock file for Pipenv, pinning exact versions of dependencies to ensure consistent builds. (Exists if pipenv is selected as the package manager)
├── uv.lock # Lock file for uv, pinning exact versions of dependencies to ensure consistent builds. (Exists if uv is selected as the package manager)
├── README.md # The main README file providing an overview of the project, setup instructions, and other essential information.
└── SECURITY.md # A security policy for the project, providing information on how to report security vulnerabilities.
```
Expand All @@ -307,7 +310,7 @@ prefer. See the [Alternatives Software/Tools][alternative-software-tools] sectio
manage (install/update) them
for you.*
- *Poetry also creates a virtual environment for your project and manages the dependencies in that environment.*
- *When running manually you can choose to use `pipenv` instead of `poetry` via the `package_manager` selection
- *When running manually you can choose to use `pipenv` or `uv` instead of `poetry` via the `package_manager` selection
question.*

*2. What is Ruff and why use Ruff?*
Expand Down Expand Up @@ -431,6 +434,14 @@ There are many alternatives to the tools used in this template, and you may pref

:TODO: Add instructions for development

### Maintainer Commands

Use `make update-template-packages` when you need to refresh the package-manager-specific template files under
`project_template/` after changing the dependency sets or package-manager template configuration.

This command regenerates the managed package files for Poetry, Pipenv, and uv, including the lockfiles copied into the
template. It requires the relevant package-manager CLIs to be installed locally: `poetry`, `pipenv`, and `uv`.

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
Expand Down
27 changes: 25 additions & 2 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ package_manager:
choices:
- poetry
- pipenv
- uv

confirm_uv_prerelease:
type: bool
help: "uv is still pre-v1, so some project-management behaviour may change in future releases. Do you want to use uv for this project?"
default: true
when: "{{ package_manager == 'uv' }}"
validator: >-
{% if package_manager == 'uv' and not confirm_uv_prerelease %}
You must confirm the use of uv to continue because uv is not v1 yet.
{% endif %}

set_up_git_repo:
type: bool
Expand Down Expand Up @@ -176,7 +187,7 @@ poetry_copier:
default: "{{ package_manager == 'poetry' and enable_copier_updates }}"
when: false

not_poetry_copier:
poetry_no_copier:
type: bool
help: "Not prompted. This is computed for re-use."
default: "{{ package_manager == 'poetry' and not enable_copier_updates }}"
Expand All @@ -188,8 +199,20 @@ pipenv_copier:
default: "{{ package_manager == 'pipenv' and enable_copier_updates }}"
when: false

not_pipenv_copier:
pipenv_no_copier:
type: bool
help: "Not prompted. This is computed for re-use."
default: "{{ package_manager == 'pipenv' and not enable_copier_updates }}"
when: false

uv_copier:
type: bool
help: "Not prompted. This is computed for re-use."
default: "{{ package_manager == 'uv' and enable_copier_updates }}"
when: false

uv_no_copier:
type: bool
help: "Not prompted. This is computed for re-use."
default: "{{ package_manager == 'uv' and not enable_copier_updates }}"
when: false
12 changes: 12 additions & 0 deletions macros.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,17 @@
https://python-poetry.org/
{%- elif package_manager == "pipenv" -%}
https://pipenv.pypa.io/en/latest/
{%- elif package_manager == "uv" -%}
https://docs.astral.sh/uv/
{%- endif -%}
{%- endmacro -%}

{%- macro package_manager_name() -%}
{%- if package_manager == "poetry" -%}
Poetry
{%- elif package_manager == "pipenv" -%}
Pipenv
{%- elif package_manager == "uv" -%}
uv
{%- endif -%}
{%- endmacro -%}
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions project_template/.github/workflows/ci.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ jobs:
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
with:
python-version-file: .python-version
{%- if package_manager != 'uv' %}
cache: {{ package_manager }}
{%- endif %}
Comment thread
MebinAbraham marked this conversation as resolved.
{%- if package_manager == 'pipenv' %}

- name: Install Pipenv
run: pipx install pipenv==2023.12.1
{%- elif package_manager == 'uv' %}

- name: Install uv
run: pipx install uv==0.11.26
{%- endif %}

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion project_template/.gitignore.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ target/
profile_default/
ipython_config.py

# pyenv
# Python version managers
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
Expand Down
4 changes: 4 additions & 0 deletions project_template/Makefile.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ install: ## Install the dependencies excluding dev.
poetry install --only main
{%- elif package_manager == "pipenv" -%}
pipenv install
{%- elif package_manager == "uv" -%}
uv sync --no-dev
{%- endif %}

.PHONY: install-dev
Expand All @@ -52,6 +54,8 @@ install-dev: ## Install the dependencies including dev.
poetry install
{%- elif package_manager == "pipenv" -%}
pipenv install --dev
{%- elif package_manager == "uv" -%}
uv sync
{%- endif %}

.PHONY: megalint
Expand Down
22 changes: 17 additions & 5 deletions project_template/README.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ To get a local copy up and running, follow these simple steps.

Ensure you have the following installed:

1. **Python**: Version specified in `.python-version`. We recommend using [pyenv](https://github.com/pyenv/pyenv) for
managing Python versions.
2. **[{{ package_manager | title }}]({{ macros.package_manager_url() }})**: This is used to manage package dependencies and virtual
1. **Python**: Version specified in `.python-version`.
{%- if package_manager == "uv" %}
We recommend using [uv](https://docs.astral.sh/uv/) to install and pin the project Python version.
{%- else %}
We recommend using [pyenv](https://github.com/pyenv/pyenv) for managing Python versions.
{%- endif %}
2. **[{{ macros.package_manager_name() }}]({{ macros.package_manager_url() }})**: This is used to manage package dependencies and virtual
environments.
3. **[Docker](https://docs.docker.com/engine/install/)**
4. **Operation System**: Ubuntu/MacOS
Expand All @@ -60,8 +64,16 @@ Ensure you have the following installed:

2. Install dependencies

[{{ package_manager | title }}]({{ macros.package_manager_url() }}) is used to manage dependencies in this project. For more information, read
the [{{ package_manager | title }} documentation]({{ macros.package_manager_url() }}).
[{{ macros.package_manager_name() }}]({{ macros.package_manager_url() }}) is used to manage dependencies in this project. For more information, read
the [{{ macros.package_manager_name() }} documentation]({{ macros.package_manager_url() }}).

{%- if package_manager == "uv" %}
To install the Python version pinned for this project, run:

```bash
uv python install
```
{%- endif %}

To install all dependencies, including development dependencies, run:

Expand Down
8 changes: 8 additions & 0 deletions project_template/copier_scripts/cleanup_conditional_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ if [[ "${REPO_VISIBILITY}" == "public" ]]; then
else
rm -f LICENSE .github/workflows/codeql.yml
fi

if [[ "${PACKAGE_MANAGER}" == "poetry" ]]; then
rm -f Pipfile Pipfile.lock uv.lock
elif [[ "${PACKAGE_MANAGER}" == "pipenv" ]]; then
rm -f poetry.lock uv.lock
elif [[ "${PACKAGE_MANAGER}" == "uv" ]]; then
rm -f Pipfile Pipfile.lock poetry.lock
fi
10 changes: 8 additions & 2 deletions project_template/copier_scripts/setup_package_manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
set -euo pipefail

if [[ "$PACKAGE_MANAGER" == "poetry" ]]; then
rm -f Pipfile Pipfile.lock
rm -f Pipfile Pipfile.lock uv.lock

# Add content of linter-configs.toml into pyproject.toml at the end of the file
echo "" >>pyproject.toml
cat copier_scripts/linter-configs.toml >>pyproject.toml

elif [[ "$PACKAGE_MANAGER" == "pipenv" ]]; then
rm -f poetry.lock pyproject.toml
rm -f poetry.lock uv.lock pyproject.toml

# Add content of linter-configs.toml into pyproject.toml
cat copier_scripts/linter-configs.toml >pyproject.toml
elif [[ "$PACKAGE_MANAGER" == "uv" ]]; then
rm -f Pipfile Pipfile.lock poetry.lock

# Add content of linter-configs.toml into pyproject.toml at the end of the file
echo "" >>pyproject.toml
cat copier_scripts/linter-configs.toml >>pyproject.toml
fi
Loading
Loading