Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pyproject.toml and build #518

Merged
merged 13 commits into from
Sep 30, 2024
45 changes: 41 additions & 4 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,49 @@ See the [root readme](../README.md) for more information.

## Dependencies

The `requirements.txt` file is generated by pip-compile and should not be modified manually.
To update the requirements file, run:
The `requirements.txt` file is generated by pip compile and should not be modified manually.
Dependencies are specified in [pyproject.toml](./pyproject.toml).
To update the requirements file,
use the provided shell script.
First install [uv](https://github.com/astral-sh/uv) (recommended),
or alternatively `pip-tools` using [pipx](https://github.com/pypa/pipx).
Then run:

```shell
pipx install pip-tools
pip-compile setup.py
./compile-requirements.sh
# See help
./compile-requirements.sh -h
```

## Development

uv is the recommended way to handle virtual environments for development.

Create a venv and install all dependencies:

```shell
uv sync --all-extras
```

You can then run commands directly with the venv using `uv run`,
or activate the venv manually first.
The uv default venv location is `.venv`.

```shell
source .venv/bin/activate
# or Windows
.venv\Scripts\activate
```

## Release

Use the provided shell script.
Note that you need to have a venv with the extra dependencies installed active when running the script.

```shell
./release.sh
# See help
./release.sh -h
```

## Code formatting and linting
Expand Down
14 changes: 10 additions & 4 deletions python/compile-requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ source "$DIR/../common.sh"

USAGE="Usage: $0 [OPTIONS] [MESSAGE]

Re-compile requirements files using pip-compile.
Re-compile requirements files using pip compile.

OPTIONS: All options are optional
-h | --help
Expand Down Expand Up @@ -61,15 +61,21 @@ done

cd "$DIR"

if [ -z "$(command -v pip-compile)" ]; then
print_error_and_exit "pip-tools is not installed. Run 'pip install pip-tools'"
if [ -n "$(command -v uv)" ]; then
COMPILE_CMD="uv pip compile"
elif [ -n "$(command -v pip-compile)" ]; then
print_yellow "uv is the recommended tool for running pip compile: https://github.com/astral-sh/uv"
COMPILE_CMD="pip-compile"
else
print_error_and_exit "pip tools are not installed. Use uv, or install 'pip-tools' with pipx."
fi

# Remove old file to force upgrade of all dependencies
rm -f requirements.txt

print_magenta "Compiling requirements.txt"
pip-compile --output-file=requirements.txt --strip-extras setup.py
$COMPILE_CMD --output-file=requirements.txt pyproject.toml
$COMPILE_CMD --output-file=requirements-dev.txt --all-extras pyproject.toml

if [ "$COMMIT_CHANGES" = true ]; then
git add requirements.txt
Expand Down
44 changes: 44 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
[project]
name = "nitor-vault"
version = "0.54"
description = "Vault for storing locally encrypted data in S3 using KMS keys"
readme = "README.md"
requires-python = ">=3.8"
authors = [
{ name = "Pasi Niemi", email = "[email protected]" }
]
license = { text = "Apache 2.0" }
dependencies = [
"argcomplete",
"cryptography",
"future",
"requests",
"threadlocal-aws",
"pypiwin32; platform_system=='Windows'",
"win-unicode-console; platform_system=='Windows'",
"wmi; platform_system=='Windows'"
]

[project.urls]
Repository = "http://github.com/NitorCreations/vault"
Download = "https://github.com/NitorCreations/vault/tarball/0.54"

[project.scripts]
vault = "n_vault.cli:main"

[project.optional-dependencies]
test = [
"coverage",
"coveralls",
]
build = [
"build",
"setuptools",
"twine",
"wheel",
]

[build-system]
requires = ["setuptools", "wheel", "build"]
build-backend = "setuptools.build_meta"

[tool.black]
# https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-via-a-file
line-length = 120
Expand Down
14 changes: 8 additions & 6 deletions python/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ source "$DIR/../common.sh"
init_options() {
DRYRUN=false
VERSION=$(grep '^VERSION' n_vault/__init__.py | cut -d\" -f 2)
echo "Current version: $VERSION"
MAJOR=${VERSION//.*/}
MINOR=${VERSION##*.}
while [ $# -gt 0 ]; do
Expand Down Expand Up @@ -84,17 +85,18 @@ init_options "$@"

print_magenta "Updating version number..."
"${SED_COMMAND[@]}" "s/^VERSION = .*/VERSION = \"$NEW_VERSION\"/g" n_vault/__init__.py
"${SED_COMMAND[@]}" "s/^version = .*/version = $NEW_VERSION/g" setup.cfg
# update tarball url version
"${SED_COMMAND[@]}" "s/$VERSION/$NEW_VERSION/g" setup.cfg
git commit -m "$MESSAGE" n_vault/__init__.py setup.cfg
"${SED_COMMAND[@]}" "s/^version = .*/version = \"$NEW_VERSION\"/g" pyproject.toml
"${SED_COMMAND[@]}" "s|https://github.com/NitorCreations/vault/tarball/[^\"]*|https://github.com/NitorCreations/vault/tarball/$NEW_VERSION|g" pyproject.toml

run_command git commit -m "$MESSAGE" n_vault/__init__.py pyproject.toml
# TODO: should use annotated tags for releases: convert old tags and add `-a` here
git tag "$NEW_VERSION" -m "$MESSAGE"
run_command git tag "$NEW_VERSION" -m "$MESSAGE"
run_command git push origin "$NEW_VERSION"

print_magenta "Building package..."
check_and_set_python
rm -rf dist
$PYTHON setup.py sdist bdist_wheel
$PYTHON -m build --sdist --wheel
print_magenta "Uploading package..."
twine check dist/*
run_command twine upload dist/*
107 changes: 107 additions & 0 deletions python/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# This file was autogenerated by uv via the following command:
# uv pip compile --output-file=requirements-dev.txt --all-extras pyproject.toml
argcomplete==3.5.0
# via nitor-vault (pyproject.toml)
boto3==1.35.25
# via threadlocal-aws
botocore==1.35.25
# via
# boto3
# s3transfer
build==1.2.2
# via nitor-vault (pyproject.toml)
certifi==2024.8.30
# via requests
cffi==1.17.1
# via cryptography
charset-normalizer==3.3.2
# via requests
coverage==7.6.1
# via
# nitor-vault (pyproject.toml)
# coveralls
coveralls==4.0.1
# via nitor-vault (pyproject.toml)
cryptography==43.0.1
# via nitor-vault (pyproject.toml)
docopt==0.6.2
# via coveralls
docutils==0.21.2
# via readme-renderer
future==1.0.0
# via nitor-vault (pyproject.toml)
idna==3.10
# via requests
importlib-metadata==8.5.0
# via twine
jaraco-classes==3.4.0
# via keyring
jaraco-context==6.0.1
# via keyring
jaraco-functools==4.0.2
# via keyring
jmespath==1.0.1
# via
# boto3
# botocore
keyring==25.4.1
# via twine
markdown-it-py==3.0.0
# via rich
mdurl==0.1.2
# via markdown-it-py
more-itertools==10.5.0
# via
# jaraco-classes
# jaraco-functools
nh3==0.2.18
# via readme-renderer
packaging==24.1
# via build
pkginfo==1.10.0
# via twine
pycparser==2.22
# via cffi
pygments==2.18.0
# via
# readme-renderer
# rich
pyproject-hooks==1.1.0
# via build
python-dateutil==2.9.0.post0
# via botocore
readme-renderer==44.0
# via twine
requests==2.32.3
# via
# nitor-vault (pyproject.toml)
# coveralls
# requests-toolbelt
# threadlocal-aws
# twine
requests-toolbelt==1.0.0
# via twine
rfc3986==2.0.0
# via twine
rich==13.8.1
# via twine
s3transfer==0.10.2
# via boto3
setuptools==75.1.0
# via nitor-vault (pyproject.toml)
six==1.16.0
# via python-dateutil
threadlocal-aws==0.11
# via nitor-vault (pyproject.toml)
twine==5.1.1
# via nitor-vault (pyproject.toml)
urllib3==2.2.3
# via
# botocore
# requests
# threadlocal-aws
# twine
wheel==0.44.0
# via nitor-vault (pyproject.toml)
zipp==3.20.2
# via importlib-metadata
24 changes: 10 additions & 14 deletions python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --output-file=requirements.txt --strip-extras setup.py
#
# This file was autogenerated by uv via the following command:
# uv pip compile --output-file=requirements.txt pyproject.toml
argcomplete==3.5.0
# via nitor-vault (setup.py)
boto3==1.34.140
# via nitor-vault (pyproject.toml)
boto3==1.35.25
# via threadlocal-aws
botocore==1.34.140
botocore==1.35.25
# via
# boto3
# s3transfer
Expand All @@ -19,9 +15,9 @@ cffi==1.17.1
charset-normalizer==3.3.2
# via requests
cryptography==43.0.1
# via nitor-vault (setup.py)
# via nitor-vault (pyproject.toml)
future==1.0.0
# via nitor-vault (setup.py)
# via nitor-vault (pyproject.toml)
idna==3.10
# via requests
jmespath==1.0.1
Expand All @@ -34,15 +30,15 @@ python-dateutil==2.9.0.post0
# via botocore
requests==2.32.3
# via
# nitor-vault (setup.py)
# nitor-vault (pyproject.toml)
# threadlocal-aws
s3transfer==0.10.2
# via boto3
six==1.16.0
# via python-dateutil
threadlocal-aws==0.11
# via nitor-vault (setup.py)
urllib3==2.2.2
# via nitor-vault (pyproject.toml)
urllib3==2.2.3
# via
# botocore
# requests
Expand Down
64 changes: 0 additions & 64 deletions python/setup.cfg

This file was deleted.

Loading