Skip to content

Commit f093056

Browse files
authored
Feature/GitHub action Python formatting/linting #3 (#14)
* linting stage for the github action workflow * linting stage for the github action workflow * more complete gitignore * formatting all python code with black * restricting to ubuntu * black and isort ran locally * fixing compatibility in examples * format/linting before pushing * removed dead code * sorting imports on 007 * removing docformatter * removing pycodestyle * adding the args options to the github action * removed py3.10 as an option * disabling docformatter * disabling pycodestyle * trying again to disable pycodestyle * trying something new * Revert "trying something new" This reverts commit 6e0f6c3. * getting rid of the magical action * folding the actions together * allowing end of file to be a blank line * end of file blank line rule for flake8 * reverted python files to the upstream main state * ran black locally * ran isort locally * ran autoflake locally * reformatting via black * missing import for load_model * flake8 will ignore the line length for now * f-string unneeded * reverted changes to the init files in sdkit module * installed dev requirements * running isort
1 parent cb49807 commit f093056

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1492
-836
lines changed

Diff for: .flake8

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
max-line-length = 120
3+
extend-ignore = E203, E402, E722, W391
4+
per-file-ignores = __init__.py:F401

Diff for: .github/workflows/py-lint.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Python Linting
2+
3+
on:
4+
push:
5+
branches:
6+
- "!main"
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
linting:
13+
name: Python Linting
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
fail-fast: true
17+
matrix:
18+
# apparently only ubuntu latest is available to run a contenairised job
19+
os: [ubuntu-latest]
20+
python-version: ["3.9"]
21+
architecture: ["x64"]
22+
23+
steps:
24+
#----------------------------------------------
25+
# check-out repo
26+
#----------------------------------------------
27+
- name: Check out code
28+
uses: actions/checkout@v3
29+
30+
#----------------------------------------------
31+
# set-up python
32+
#----------------------------------------------
33+
- name: Set up Python ${{ matrix.python-version }}
34+
uses: actions/setup-python@v4
35+
with:
36+
python-version: ${{ matrix.python-version }}
37+
38+
#----------------------------------------------
39+
# Formatting & Linting
40+
#----------------------------------------------
41+
- name: Format and lint the code
42+
run: |
43+
pip install black isort autoflake flake8
44+
black tests scripts sdkit examples --line-length 120 --include="\.py"
45+
isort tests scripts sdkit examples --profile black
46+
autoflake --in-place --remove-all-unused-imports --remove-unused-variables --recursive .
47+
flake8 tests scripts sdkit examples --max-line-length 120 --extend-ignore=E203,E402,E501,E722,W391 --per-file-ignores=__init__.py:F401
48+
49+
#----------------------------------------------
50+
# Committing all changes
51+
#----------------------------------------------
52+
- name: Commit changes
53+
uses: EndBug/add-and-commit@v4
54+
with:
55+
author_name: ${{ github.actor }}
56+
author_email: ${{ github.actor }}@users.noreply.github.com
57+
message: "Code formatted and linted"
58+
add: "."
59+
branch: ${{ github.ref }}

Diff for: .gitignore

+160-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,160 @@
1-
__pycache__
2-
sdkit.egg-info
3-
dist
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
#.idea/

Diff for: examples/001-generate-model_file_on_disk.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import sdkit
2-
from sdkit.models import load_model
32
from sdkit.generate import generate_images
4-
from sdkit.utils import save_images, log
3+
from sdkit.models import load_model
4+
from sdkit.utils import log, save_images
55

66
context = sdkit.Context()
77

88
# set the path to the model file on the disk (.ckpt or .safetensors file)
9-
context.model_paths['stable-diffusion'] = 'D:\\path\\to\\512-base-ema.ckpt'
10-
load_model(context, 'stable-diffusion')
9+
context.model_paths["stable-diffusion"] = "D:\\path\\to\\512-base-ema.ckpt"
10+
load_model(context, "stable-diffusion")
1111

1212
# generate the image
13-
images = generate_images(context, prompt='Photograph of an astronaut riding a horse', seed=42, width=512, height=512)
13+
images = generate_images(context, prompt="Photograph of an astronaut riding a horse", seed=42, width=512, height=512)
1414

1515
# save the image
16-
save_images(images, dir_path='.')
16+
save_images(images, dir_path=".")
1717

1818
log.info("Generated images!")

Diff for: examples/002-generate-download_known_model.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import sdkit
2-
from sdkit.models import load_model, download_model, resolve_downloaded_model_path
32
from sdkit.generate import generate_images
4-
from sdkit.utils import save_images, log
3+
from sdkit.models import download_model, load_model, resolve_downloaded_model_path
4+
from sdkit.utils import log, save_images
55

66
context = sdkit.Context()
77

88
# download the model (skips if already downloaded, resumes if downloaded partially)
9-
download_model(model_type='stable-diffusion', model_id='1.5-pruned-emaonly')
9+
download_model(model_type="stable-diffusion", model_id="1.5-pruned-emaonly")
1010

1111
# set the path to the auto-downloaded model
12-
context.model_paths['stable-diffusion'] = resolve_downloaded_model_path(context, 'stable-diffusion', '1.5-pruned-emaonly')
13-
load_model(context, 'stable-diffusion')
12+
context.model_paths["stable-diffusion"] = resolve_downloaded_model_path(
13+
context, "stable-diffusion", "1.5-pruned-emaonly"
14+
)
15+
load_model(context, "stable-diffusion")
1416

1517
# generate the image
16-
images = generate_images(context, prompt='Photograph of an astronaut riding a horse', seed=42, width=512, height=512)
18+
images = generate_images(context, prompt="Photograph of an astronaut riding a horse", seed=42, width=512, height=512)
1719

1820
# save the image
19-
save_images(images, dir_path='D:\\path\\to\\images\\directory')
21+
save_images(images, dir_path="D:\\path\\to\\images\\directory")
2022

2123
log.info("Generated images!")
+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from sdkit.models import download_models
22

33
# download all three models (skips if already downloaded, resumes if downloaded partially)
4-
download_models(models={
5-
'stable-diffusion': ['1.4', '1.5-pruned-emaonly'],
6-
'gfpgan': '1.3',
7-
})
4+
download_models(
5+
models={
6+
"stable-diffusion": ["1.4", "1.5-pruned-emaonly"],
7+
"gfpgan": "1.3",
8+
}
9+
)

Diff for: examples/003-generate-custom_model.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import sdkit
2-
from sdkit.models import load_model
32
from sdkit.generate import generate_images
4-
from sdkit.utils import save_images, log
3+
from sdkit.models import load_model
4+
from sdkit.utils import log, save_images
55

66
context = sdkit.Context()
77

88
# set the path to the custom model file on the disk
9-
context.model_paths['stable-diffusion'] = 'D:\\path\\to\\cmodelUpgradeStableD.safetensors'
10-
context.model_configs['stable-diffusion'] = 'D:\\path\\to\\Cmodelsafetensor.yaml'
9+
context.model_paths["stable-diffusion"] = "D:\\path\\to\\cmodelUpgradeStableD.safetensors"
10+
context.model_configs["stable-diffusion"] = "D:\\path\\to\\Cmodelsafetensor.yaml"
1111
# the yaml config file is required if it's an unknown model to use.
1212
# it is not necessary for known models present in the models_db.
1313

14-
load_model(context, 'stable-diffusion')
14+
load_model(context, "stable-diffusion")
1515

1616
# generate the image
17-
images = generate_images(context, prompt='Photograph of an astronaut riding a horse', seed=42, width=512, height=512)
17+
images = generate_images(context, prompt="Photograph of an astronaut riding a horse", seed=42, width=512, height=512)
1818

1919
# save the image
20-
save_images(images, dir_path='D:\\path\\to\\images\\directory')
20+
save_images(images, dir_path="D:\\path\\to\\images\\directory")
2121

2222
log.info("Generated images!")

Diff for: examples/004-generate-custom_vae.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import sdkit
2-
from sdkit.models import load_model
32
from sdkit.generate import generate_images
4-
from sdkit.utils import save_images, log
3+
from sdkit.models import load_model
4+
from sdkit.utils import log, save_images
55

66
context = sdkit.Context()
77

88
# set the path to the model and VAE file on the disk
9-
context.model_paths['stable-diffusion'] = 'D:\\path\\to\\model.ckpt'
10-
context.model_paths['vae'] = 'D:\\path\\to\\vae.ckpt'
11-
load_model(context, 'stable-diffusion')
12-
load_model(context, 'vae')
9+
context.model_paths["stable-diffusion"] = "D:\\path\\to\\model.ckpt"
10+
context.model_paths["vae"] = "D:\\path\\to\\vae.ckpt"
11+
load_model(context, "stable-diffusion")
12+
load_model(context, "vae")
1313

1414
# generate the image
1515
images = generate_images(context, prompt="Photograph of an astronaut riding a horse", seed=42, width=512, height=512)
1616

1717
# save the image
18-
save_images(images, dir_path='D:\\path\\to\\images\\directory')
18+
save_images(images, dir_path="D:\\path\\to\\images\\directory")
1919

20-
log.info('Generated images with a custom VAE!')
20+
log.info("Generated images with a custom VAE!")

Diff for: examples/005-generate-custom_hypernetwork.py

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
import sdkit
2-
from sdkit.models import load_model
32
from sdkit.generate import generate_images
4-
from sdkit.utils import save_images, log
3+
from sdkit.models import load_model
4+
from sdkit.utils import log, save_images
55

66
context = sdkit.Context()
77

88
# set the path to the model and hypernetwork file on the disk
9-
context.model_paths['stable-diffusion'] = 'D:\\path\\to\\model.ckpt'
10-
context.model_paths['hypernetwork'] = 'D:\\path\\to\\hypernetwork.pt'
11-
load_model(context, 'stable-diffusion')
12-
load_model(context, 'hypernetwork')
9+
context.model_paths["stable-diffusion"] = "D:\\path\\to\\model.ckpt"
10+
context.model_paths["hypernetwork"] = "D:\\path\\to\\hypernetwork.pt"
11+
load_model(context, "stable-diffusion")
12+
load_model(context, "hypernetwork")
1313

1414
# generate the image, hypernetwork_strength at 0.3
15-
images = generate_images(context, prompt="Photograph of an astronaut riding a horse", seed=42, width=512, height=512, hypernetwork_strength=0.3)
15+
images = generate_images(
16+
context,
17+
prompt="Photograph of an astronaut riding a horse",
18+
seed=42,
19+
width=512,
20+
height=512,
21+
hypernetwork_strength=0.3,
22+
)
1623

1724
# save the image
18-
save_images(images, dir_path='D:\\path\\to\\images\\directory')
25+
save_images(images, dir_path="D:\\path\\to\\images\\directory")
1926

20-
log.info('Generated images with a custom VAE!')
27+
log.info("Generated images with a custom VAE!")

0 commit comments

Comments
 (0)