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

✨ Migrate package installation to pyproject.toml (PEP 621) #54

Merged
merged 11 commits into from
Dec 12, 2022
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ If you want to test:

.. code-block:: bash
$ pip install -r requirements.txt
$ pytest
$ pip install .[dev]
$ inv test
3 changes: 1 addition & 2 deletions multipart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
__author__ = 'Andrew Dunham'
__license__ = 'Apache'
__copyright__ = "Copyright (c) 2012-2013, Andrew Dunham"
__version__ = "0.0.5"

# We get the version from a sub-file that can be automatically generated.
from ._version import __version__

from .multipart import (
FormParser,
Expand Down
1 change: 0 additions & 1 deletion multipart/_version.py

This file was deleted.

65 changes: 65 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "python-multipart"
dynamic = ["version"]
description = "A streaming multipart parser for Python"
readme = "README.rst"
license = "Apache-2.0"
requires-python = ">=3.7"
authors = [
{ name = "Andrew Dunham", email = "[email protected]" },
]
classifiers = [
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Topic :: Software Development :: Libraries :: Python Modules',
]
dependencies = []

[project.optional-dependencies]
dev = [
"atomicwrites==1.2.1",
"attrs==19.2.0",
"coverage==6.5.0",
"more-itertools==4.3.0",
"pbr==4.3.0",
"pluggy==1.0.0",
"py==1.11.0",
"pytest==7.2.0",
"pytest-cov==4.0.0",
"PyYAML==5.1",
"invoke==1.7.3",
"pytest-timeout==2.1.0",
"hatch",
]

[project.urls]
Homepage = "https://github.com/andrew-d/python-multipart"
Documentation = "https://andrew-d.github.io/python-multipart/"
Changelog = "https://github.com/andrew-d/python-multipart/tags"
Source = "https://github.com/andrew-d/python-multipart"

[tool.hatch.version]
path = "multipart/__init__.py"

[tool.hatch.build.targets.wheel]
packages = [
"multipart",
]
[tool.hatch.build.targets.sdist]
include = [
"/multipart",
]
Ambro17 marked this conversation as resolved.
Show resolved Hide resolved
51 changes: 0 additions & 51 deletions setup.py

This file was deleted.

20 changes: 12 additions & 8 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from invoke import task, run


version_file = os.path.join('multipart', '_version.py')
version_file = os.path.join('multipart', '__init__.py')
version_regex = re.compile(r'((?:\d+)\.(?:\d+)\.(?:\d+))')

# Get around Python 2.X's lack of 'nonlocal' keyword
Expand All @@ -14,7 +14,7 @@ class g:


@task
def test(all=False):
def test(ctx, all=False):
test_cmd = [
'pytest', # Test command
'--cov-report term-missing', # Print only uncovered lines to stdout
Expand All @@ -37,9 +37,9 @@ def test(all=False):


@task
def bump(type):
def bump(ctx, type):
# Read and parse version.
with open(version_file, 'rb') as f:
with open(version_file, 'r') as f:
file_data = f.read().replace('\r\n', '\n')

m = version_regex.search(file_data)
Expand Down Expand Up @@ -68,17 +68,21 @@ def bump(type):
new_ver = ".".join(str(x) for x in ver_nums)
new_data = before + new_ver + after

with open(version_file, 'wb') as f:
with open(version_file, 'w') as f:
f.write(new_data)

# Print information.
print(f"Bumped version from: {version} --> {new_ver}")


@task(pre=['test'])
def deploy():
@task(pre=[test])
def deploy(ctx):
if not g.test_success:
print("Tests must pass before deploying!", file=sys.stderr)
return

run('python setup.py sdist upload')
# # Build source distribution and wheel
run('hatch build')
#
# # Upload distributions from last step to pypi
run('hatch publish')