Skip to content

Commit

Permalink
Adds pyproject.toml (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
kingbuzzman authored Aug 11, 2024
1 parent b7fa5d6 commit 1bfc1f0
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 180 deletions.
3 changes: 0 additions & 3 deletions .black

This file was deleted.

3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ charset = utf-8
# Docstrings and comments use max_line_length = 79
[*.py]
max_line_length = 119

[*.yml]
indent_size = 2
73 changes: 60 additions & 13 deletions .github/workflows/_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,65 @@ jobs:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
- name: Install the linters
run: |
pip install --upgrade setuptools
python setup.py install_linters
- name: Generate matrix from setup.py
id: set-matrix
pip install --upgrade setuptools toml
pip install $(python -c 'import toml; conf = toml.load(open("pyproject.toml")); print(" ".join(conf["project"]["optional-dependencies"]["lint"]))')
- name: Generate matrix
run: |
python -c "from setup import GITHUB_MATRIX; print(GITHUB_MATRIX)" > matrix.json
echo "matrix=$(<matrix.json)" >> $GITHUB_OUTPUT
python -c '
import toml
import itertools
import json
import os
DJANGO_VERSIONS = []
PYTHON_VERSIONS = []
EXCLUDE_MATRIX = (["3.8", "3.9"], ["5.0.*", "5.1.*", "main"])
def is_number(s):
try:
float(s)
return True
except ValueError:
return False
with open("pyproject.toml") as f:
conf = toml.load(f)
for classifier in conf["project"]["classifiers"]:
if "Framework :: Django ::" in classifier:
version = classifier.split("::")[-1].strip()
if "." in version and is_number(version):
DJANGO_VERSIONS.append(version)
elif "Programming Language :: Python ::" in classifier:
version = classifier.split("::")[-1].strip()
if "." in version and is_number(version):
PYTHON_VERSIONS.append(version)
matrix = {
"python-version": PYTHON_VERSIONS,
"django-version": [f"{v}.*" for v in DJANGO_VERSIONS] + ["main"],
"exclude": [{"django-version": d, "python-version": p} for p, d in itertools.product(*EXCLUDE_MATRIX)],
}
with open(os.getenv("GITHUB_ENV"), "a") as env_file:
pretty = " ".join(DJANGO_VERSIONS)
env_file.write(f"django={pretty}\n")
pretty = " ".join(PYTHON_VERSIONS)
env_file.write(f"python={pretty}\n")
env_file.write(f"matrix={json.dumps(matrix)}\n")
'
- name: Check version EOF
id: set-matrix
run: |
python -c "import json
echo "matrix=$matrix" >> $GITHUB_OUTPUT
python -c "
import os
import json
from urllib.request import Request, urlopen
from datetime import date, datetime, timedelta
from setup import DJANGO_VERSIONS, PYTHON_VERSIONS
DJANGO_VERSIONS = os.getenv('django').split()
PYTHON_VERSIONS = os.getenv('python').split()
today = date.today()
WARNING_DAYS = timedelta(days=90)
version_by_product = {
Expand All @@ -47,8 +93,8 @@ jobs:
}
for product, supported_versions in version_by_product.items():
url = f'https://endoflife.date/api/{product}.json'
with urlopen(Request(url)) as httpresponse:
data = json.loads(httpresponse.read())
with urlopen(Request(url)) as response:
data = json.loads(response.read())
for detail in data:
version = detail['cycle']
eol = detail['eol']
Expand All @@ -60,13 +106,14 @@ jobs:
if eol_date < today:
print(f'::error ::{product} v{version}: EOL was {eol}')
elif eol_date - today < WARNING_DAYS:
print(f'::warning ::{product} v{version}: EOL is coming up on the {eol}')"
print(f'::warning ::{product} v{version}: EOL is coming up on the {eol}')
"
- name: iSort check
if: always()
run: isort --check .
- name: Black check
if: always()
run: black --config .black --check .
run: black --check .
- name: Flake8 check
if: always()
run: flake8 .
Expand Down Expand Up @@ -136,7 +183,7 @@ jobs:
- name: Clean up temporary artifacts
uses: geekyeggo/delete-artifact@v5
with:
name: coverage_*
name: coverage_*
- name: Combine coverage.py
run: |
coverage combine $(find downloaded_artifacts/ -type f | xargs)
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Developing

.. code-block:: shell
docker run --rm -it -v .:/app -v django-squash-pip-cache:/root/.cache/pip -e PYTHONDONTWRITEBYTECODE=1 python:3.12 bash -c "cd app; pip install -e .[test,lint]; echo \"alias linters=\\\"echo '> isort'; isort .; echo '> black'; black --config .black .; echo '> ruff'; ruff check .;echo '> flake8'; flake8 .; echo '> rst-lint'; rst-lint README.rst docs/*\\\"\" >> ~/.bash_profile; printf '\n\n\nrun **pytest** to run tests, **linters** to run linters\n\n'; exec bash --init-file ~/.bash_profile"
docker run --rm -it -v .:/app -v django-squash-pip-cache:/root/.cache/pip -e PYTHONDONTWRITEBYTECODE=1 python:3.12 bash -c "cd app; pip install -e .[test,lint]; echo \"alias linters=\\\"echo '> isort'; isort .; echo '> black'; black .; echo '> ruff'; ruff check .;echo '> flake8'; flake8 .; echo '> rst-lint'; rst-lint README.rst docs/*\\\"\" >> ~/.bash_profile; printf '\n\n\nrun **pytest** to run tests, **linters** to run linters\n\n'; exec bash --init-file ~/.bash_profile"
Alternatively, you can also create a virtual environment and run

Expand All @@ -87,7 +87,7 @@ Alternatively, you can also create a virtual environment and run
.. code-block:: shell
isort .
black --config .black .
black .
flake8 .
ruff check .
rst-lint .
Expand Down
2 changes: 1 addition & 1 deletion django_squash/db/migrations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ def is_code_in_site_packages(module_name):
site_packages_path_ = site_packages_path()
try:
loader = importlib.util.find_spec(module_name)
return site_packages_path_ in loader.origin
except ImportError:
return False
return loader.origin.startswith(site_packages_path_)


@functools.lru_cache(maxsize=1)
Expand Down
134 changes: 134 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "django_squash"
version = "0.0.11"
description = "A migration squasher that doesn't care how Humpty Dumpty was put together."
readme = "README.rst"
keywords = ["django", "migration", "squashing", "squash"]
authors = [
{name = "Javier Buzzi", email = "[email protected]"},
]
license = {text = "MIT"}
classifiers = [
# See https://pypi.org/pypi?%3Aaction=list_classifiers
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.0",
"Framework :: Django :: 5.1",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Utilities",
"License :: OSI Approved :: MIT License",
]
dependencies = [
"django >=3.2",
]
requires-python = ">=3.8"

[project.optional-dependencies]
lint = [
"black",
"flake8-pyproject",
"flake8-tidy-imports",
"isort",
"pygments",
"restructuredtext-lint",
"ruff"
]
test = [
"black",
"build",
"ipdb",
"libcst",
"psycopg2-binary",
"pytest-cov",
"pytest-django"
]

[project.urls]
homepage = "https://github.com/kingbuzzman/django-squash"

[tool.setuptools.packages.find]
exclude = ["tests*", "docs*"]

[tool.setuptools]
zip-safe = true
platforms = ["any"]

[tool.black]
line-length = 119
exclude = "venv/"

[tool.flake8]
max-line-length = 119
exclude = ["*/migrations_*/*", "venv/*", "build/*"]
ban-relative-imports = true

[tool.isort]
combine_as_imports = true
line_length = 119
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
skip_glob = ["venv/**"]

[tool.coverage.run]
source = ["django_squash"]

[tool.coverage.report]
omit = ["*/migrations_*/*"]
show_missing = true
fail_under = 95

[tool.pypi]
repository = "https://upload.pypi.org/legacy/"
username = "kingbuzzman"

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "settings"
pythonpath = "tests"
addopts = "--pdbcls=IPython.terminal.debugger:TerminalPdb"
python_files = ["test_*.py", "*_tests.py"]

# Custom markers for pytest
markers = [
"temporary_migration_module",
"temporary_migration_module2",
"temporary_migration_module3",
"slow: marks tests as slow"
]

filterwarnings = [
"error",

# Internal warning to tell the user that the writer.py file has changed, and may not be compatible.
"ignore:Django migrations writer file has changed and may not be compatible with django-squash",

# Warning: django.utils.deprecation.RemovedInDjango50Warning: The USE_L10N setting is deprecated. Starting with Django 5.0, localized formatting of data will always be enabled. For example Django will display numbers and dates using the format of the current locale.
# Don't specify the exact warning (django.utils.deprecation.RemovedInDjango50Warning) as not all version of Django know it and pytest will fail
"ignore:The USE_L10N setting is deprecated:",

# Warning: cgi is only being used by Django 3.2
"ignore:'cgi' is deprecated and slated for removal in Python 3.13",

# Django 3.2 throws a warning about the USE_I18N setting being deprecated
"ignore:datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects .*"
]
55 changes: 0 additions & 55 deletions setup.cfg

This file was deleted.

Loading

0 comments on commit 1bfc1f0

Please sign in to comment.