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

Format code with Black #843

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include ChangeLog CODE_OF_CONDUCT.md CONTRIBUTING.rst CREDITS LICENSE README.rst
include Makefile tox.ini
include Makefile pyproject.toml tox.ini

graft factory

Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SETUP_PY=setup.py

# Use current python binary instead of system default.
COVERAGE = python $(shell which coverage)
BLACK = black
FLAKE8 = flake8
ISORT = isort
CTAGS = ctags
Expand Down Expand Up @@ -70,9 +71,10 @@ example-test:



# Note: we run the linter in two runs, because our __init__.py files has specific warnings we want to exclude
# DOC: Perform code quality tasks
lint:
$(BLACK) --target-version py36 --check --diff .
# Note: we run the linter in two runs, because our __init__.py files has specific warnings we want to exclude
$(FLAKE8) --exclude $(PACKAGE)/__init__.py $(EXAMPLES_DIR) $(PACKAGE) $(SETUP_PY) $(TESTS_DIR)
$(FLAKE8) --ignore F401 $(PACKAGE)/__init__.py
$(ISORT) --check-only --diff $(EXAMPLES_DIR) $(PACKAGE) $(SETUP_PY) $(TESTS_DIR)
Expand Down
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ factory_boy
:target: https://pypi.org/project/factory-boy/
:alt: License

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
:alt: Code style using Black

factory_boy is a fixtures replacement based on thoughtbot's `factory_bot <https://github.com/thoughtbot/factory_bot>`_.

As a fixtures replacement tool, it aims to replace static, hard to maintain fixtures
Expand Down
53 changes: 26 additions & 27 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,62 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.dirname(os.path.abspath('.')))
sys.path.insert(0, os.path.dirname(os.path.abspath(".")))


# -- Project information -----------------------------------------------------

project = 'Factory Boy'
copyright = '2011-2015, Raphaël Barrois, Mark Sandstrom'
author = 'adfasf'
project = "Factory Boy"
copyright = "2011-2015, Raphaël Barrois, Mark Sandstrom"
author = "adfasf"

# The full version, including alpha/beta/rc tags
release = factory.__version__
# The short X.Y version.
version = '.'.join(release.split('.')[:2])
version = ".".join(release.split(".")[:2])

# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.extlinks',
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
"sphinx.ext.autodoc",
"sphinx.ext.extlinks",
"sphinx.ext.intersphinx",
"sphinx.ext.viewcode",
]

extlinks = {
'issue': ('https://github.com/FactoryBoy/factory_boy/issues/%s', 'issue #'),
'pr': ('https://github.com/FactoryBoy/factory_boy/pull/%s', 'pull request #'),
"issue": ("https://github.com/FactoryBoy/factory_boy/issues/%s", "issue #"),
"pr": ("https://github.com/FactoryBoy/factory_boy/pull/%s", "pull request #"),
}

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
exclude_patterns = ["_build"]


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

if 'READTHEDOCS_VERSION' in os.environ:
if "READTHEDOCS_VERSION" in os.environ:
# Use the readthedocs version string in preference to our known version.
html_title = "{} {} documentation".format(
project, os.environ['READTHEDOCS_VERSION'])
html_title = "{} {} documentation".format(project, os.environ["READTHEDOCS_VERSION"])

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]


# -- linkcheck ---------------------------------------------------------------
Expand All @@ -79,19 +78,19 @@

# -- intersphinx -------------------------------------------------------------
intersphinx_mapping = {
'https://docs.python.org/': None,
'django': (
'https://docs.djangoproject.com/en/dev/',
'https://docs.djangoproject.com/en/dev/_objects/',
"https://docs.python.org/": None,
"django": (
"https://docs.djangoproject.com/en/dev/",
"https://docs.djangoproject.com/en/dev/_objects/",
),
'sqlalchemy': (
'https://docs.sqlalchemy.org/en/latest/',
'https://docs.sqlalchemy.org/en/latest/objects.inv',
"sqlalchemy": (
"https://docs.sqlalchemy.org/en/latest/",
"https://docs.sqlalchemy.org/en/latest/objects.inv",
),
}


# -- spelling ---------------------------------------------------------------
spelling_exclude_patterns = [
'credits.rst',
"credits.rst",
]
72 changes: 36 additions & 36 deletions examples/django_demo/django_demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'kh)1s3@93ju6f6$qx!758f6h^(_3d0brqzoxubo@xsn3*%2wgu'
SECRET_KEY = "kh)1s3@93ju6f6$qx!758f6h^(_3d0brqzoxubo@xsn3*%2wgu"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand All @@ -31,53 +31,53 @@
# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'generic_foreignkey'
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"generic_foreignkey",
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = 'django_demo.urls'
ROOT_URLCONF = "django_demo.urls"

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]

WSGI_APPLICATION = 'django_demo.wsgi.application'
WSGI_APPLICATION = "django_demo.wsgi.application"


# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}

Expand All @@ -87,26 +87,26 @@

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/

LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"

TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"

USE_I18N = True

Expand All @@ -118,4 +118,4 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/

STATIC_URL = '/static/'
STATIC_URL = "/static/"
2 changes: 1 addition & 1 deletion examples/django_demo/django_demo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
from django.contrib import admin

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r"^admin/", admin.site.urls),
]
2 changes: 1 addition & 1 deletion examples/django_demo/generic_foreignkey/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class GenericForeignKeyConfig(AppConfig):
name = 'generic_foreignkey'
name = "generic_foreignkey"
11 changes: 5 additions & 6 deletions examples/django_demo/generic_foreignkey/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@


class UserFactory(factory.django.DjangoModelFactory):
first_name = 'Adam'
first_name = "Adam"

class Meta:
model = User


class GroupFactory(factory.django.DjangoModelFactory):
name = 'group'
name = "group"

class Meta:
model = Group


class TaggedItemFactory(factory.django.DjangoModelFactory):
object_id = factory.SelfAttribute('content_object.id')
content_type = factory.LazyAttribute(
lambda o: ContentType.objects.get_for_model(o.content_object))
object_id = factory.SelfAttribute("content_object.id")
content_type = factory.LazyAttribute(lambda o: ContentType.objects.get_for_model(o.content_object))

class Meta:
exclude = ['content_object']
exclude = ["content_object"]
abstract = True


Expand Down
24 changes: 16 additions & 8 deletions examples/django_demo/generic_foreignkey/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('contenttypes', '0002_remove_content_type_name'),
("contenttypes", "0002_remove_content_type_name"),
]

operations = [
migrations.CreateModel(
name='TaggedItem',
name="TaggedItem",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tag', models.SlugField()),
('object_id', models.PositiveIntegerField()),
(
'content_type',
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("tag", models.SlugField()),
("object_id", models.PositiveIntegerField()),
(
"content_type",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to='contenttypes.ContentType'
)
to="contenttypes.ContentType",
),
),
],
),
Expand Down
3 changes: 2 additions & 1 deletion examples/django_demo/generic_foreignkey/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

class TaggedItem(models.Model):
"""Example GenericForeignKey model from django docs"""

tag = models.SlugField()
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
content_object = GenericForeignKey("content_type", "object_id")

def __str__(self):
return self.tag