Skip to content

Commit 1f19eb7

Browse files
committed
Update packaging
1 parent 259716d commit 1f19eb7

File tree

10 files changed

+234
-229
lines changed

10 files changed

+234
-229
lines changed

.github/workflows/ci.yml

+9-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
lint-command:
18-
- "bandit dynamic_filenames.py"
18+
- "bandit ."
1919
- "black --check --diff ."
2020
- "flake8 ."
2121
- "isort --check-only --diff ."
@@ -25,10 +25,10 @@ jobs:
2525
- uses: actions/checkout@v4
2626
- uses: actions/setup-python@v5
2727
with:
28-
python-version: "3.10"
28+
python-version: "3.x"
2929
cache: 'pip'
30-
cache-dependency-path: 'requirements.txt'
31-
- run: python -m pip install -r requirements.txt
30+
cache-dependency-path: 'pyproject.toml'
31+
- run: python -m pip install -e .[lint]
3232
- run: ${{ matrix.lint-command }}
3333

3434
readme:
@@ -37,10 +37,10 @@ jobs:
3737
- uses: actions/checkout@v4
3838
- uses: actions/setup-python@v5
3939
with:
40-
python-version: "3.10"
40+
python-version: "3.x"
4141
- name: Install Python dependencies
42-
run: python -m pip install --upgrade pip setuptools wheel twine readme-renderer
43-
- run: python setup.py sdist bdist_wheel
42+
run: python -m pip install --upgrade pip build wheel twine readme-renderer
43+
- run: python -m build --sdist --wheel
4444
- run: python -m twine check dist/*
4545
- uses: actions/upload-artifact@v4
4646
with:
@@ -68,13 +68,11 @@ jobs:
6868
uses: actions/setup-python@v5
6969
with:
7070
python-version: ${{ matrix.python-version }}
71-
- name: Upgrade Python setuptools
72-
run: python -m pip install --upgrade pip setuptools wheel codecov
73-
- run: python setup.py develop
71+
- run: python -m pip install .[test]
7472
- name: Install Django ${{ matrix.django-version }}
7573
run: python -m pip install "django~=${{ matrix.django-version }}.0"
7674
- name: Run tests
77-
run: python setup.py test
75+
run: python -m pytest
7876
- run: codecov
7977

8078
analyze:

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
with:
1414
python-version: "3.10"
1515
- name: Install Python dependencies
16-
run: python -m pip install --upgrade pip setuptools wheel twine
16+
run: python -m pip install --upgrade pip build wheel twine
1717
- name: Build dist packages
18-
run: python setup.py sdist bdist_wheel
18+
run: python -m build --sdist --wheel
1919
- name: Upload packages
2020
run: python -m twine upload dist/*
2121
env:

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,6 @@ venv.bak/
102102

103103
# mypy
104104
.mypy_cache/
105+
106+
# setuptools_scm
107+
_version.py

README.md

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Django Dynamic Filenames
2+
3+
Write advanced filename patterns using the [Format String
4+
Syntax](https://docs.python.org/3/library/string.html#format-string-syntax).
5+
6+
## Getting Started
7+
8+
### Installation
9+
10+
``` bash
11+
pip install django-dynamic-filenames
12+
```
13+
14+
### Samples
15+
16+
Basic example:
17+
18+
``` python
19+
from django.db import models
20+
from dynamic_filenames import FilePattern
21+
22+
upload_to_pattern = FilePattern(
23+
filename_pattern='{app_label:.25}/{model_name:.30}/{uuid:base32}{ext}'
24+
)
25+
26+
class FileModel(models.Model):
27+
my_file = models.FileField(upload_to=upload_to_pattern)
28+
```
29+
30+
Auto slug example:
31+
32+
## Features
33+
34+
### Field names
35+
36+
`ext`
37+
38+
: File extension including the dot.
39+
40+
`name`
41+
42+
: Filename excluding the folders.
43+
44+
`model_name`
45+
46+
: Name of the Django model.
47+
48+
`app_label`
49+
50+
: App label of the Django model.
51+
52+
`instance`
53+
54+
: Instance of the model before it has been saved. You may not have a
55+
primary key at this point.
56+
57+
`uuid`
58+
59+
: UUID version 4 that supports multiple type specifiers. The UUID will
60+
be the same should you use it twice in the same string, but
61+
different on each invocation of the `upload_to` callable.
62+
63+
The type specifiers allow you to format the UUID in different ways,
64+
e.g. `{uuid:x}` will give you a with a hexadecimal UUID.
65+
66+
The supported type specifiers are:
67+
68+
`s`
69+
70+
: String representation of a UUID including dashes.
71+
72+
`i`
73+
74+
: Integer representation of a UUID. Like to `UUID.int`.
75+
76+
`x`
77+
78+
: Hexadecimal (Base16) representation of a UUID. Like to
79+
`UUID.hex`.
80+
81+
`X`
82+
83+
: Upper case hexadecimal representation of a UUID. Like to
84+
`UUID.hex`.
85+
86+
`base32`
87+
88+
: Base32 representation of a UUID without padding.
89+
90+
`base64`
91+
92+
: Base64 representation of a UUID without padding.
93+
94+
:::: warning
95+
::: title
96+
Warning
97+
:::
98+
99+
Not all file systems support Base64 file names.
100+
::::
101+
102+
All type specifiers also support precisions to cut the string, e.g.
103+
`{{uuid:.2base32}}` would only return the first 2 characters of a
104+
Base32 encoded UUID.
105+
106+
### Type specifiers
107+
108+
You can also use a special slug type specifier, that slugifies strings.
109+
110+
Example:
111+
112+
``` python
113+
from django.db import models
114+
from dynamic_filenames import FilePattern
115+
116+
upload_to_pattern = FilePattern(
117+
filename_pattern='{app_label:.25}/{model_name:.30}/{instance.title:.40slug}{ext}'
118+
)
119+
120+
class FileModel(models.Model):
121+
title = models.CharField(max_length=100)
122+
my_file = models.FileField(upload_to=upload_to_pattern)
123+
```
124+
125+
Slug type specifiers also support precisions to cut the string. In the
126+
example above the slug of the instance title will be cut at 40
127+
characters.

README.rst

-118
This file was deleted.

dynamic_filenames.py renamed to dynamic_filenames/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""Write advanced filename patterns using the Format String Syntax."""
12
import base64
23
import os
34
import re
@@ -6,6 +7,11 @@
67

78
from django.utils.text import slugify
89

10+
from . import _version # noqa
11+
12+
__version__ = _version.__version__
13+
VERSION = _version.VERSION_TUPLE
14+
915

1016
class SlugFormatter(Formatter):
1117
format_spec_pattern = re.compile(r"(\.\d+)?([\d\w]+)?")

0 commit comments

Comments
 (0)