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

use declarative metadata #442

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ matrix:
env: NOX_SESSION=check
- python: 3.7
env: NOX_SESSION=docs
- python: 3.7
env: NOX_SESSION=check_dist

- python: 3.6
env: NOX_SESSION=test-3.6
Expand Down
4 changes: 0 additions & 4 deletions MANIFEST.in

This file was deleted.

38 changes: 38 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import pathlib
import re
import tarfile
import zipfile

import nox

nox.options.stop_on_first_error = True
Expand Down Expand Up @@ -48,3 +53,36 @@ def docs(session):
def test(session):
session.install("-r", "test-requirements.txt")
session.run("python", "-m", "pytest", *session.posargs)


@nox.session(reuse_venv=True)
def check_dist(session):
output = session.run("python", "setup.py", "sdist", "bdist_wheel", silent=True)
assert (
re.search(r"(?m)^copying httpx/py\.typed -> httpx-[^/]+/httpx$", output)
is not None
)
assert (
re.search(
r"(?m)^copying build/lib/httpx/py\.typed -> "
r"build/bdist\.[^/]+/wheel/httpx$",
output,
)
is not None
)
assert re.search(r"(?m)^adding 'httpx/py\.typed'$", output) is not None

def tgz_has_py_typed(p: pathlib.Path) -> bool:
with tarfile.open(p) as sdist:
return any(
re.match(r"httpx-[^/]+/httpx/py\.typed", member.name)
for member in sdist
)

def whl_has_py_typed(p: pathlib.Path) -> bool:
with zipfile.ZipFile(p) as whl:
return whl.getinfo("httpx/py.typed").file_size == 0

dist_dir = pathlib.Path("dist")
assert [tgz_has_py_typed(sdist) for sdist in dist_dir.glob("**/*.tar.gz")] == [True]
assert [whl_has_py_typed(whl) for whl in dist_dir.glob("**/*.whl")] == [True]
46 changes: 46 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
[metadata]
name = httpx
version = attr: src.get_version
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imho this should be a file (httpx/version.txt) and we use importlib_resources in __version__ to grab it

url = https://github.com/encode/httpx
license = BSD
Copy link
Member Author

@graingert graingert Oct 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly you don't need license = if there's a trove available

There's no trove classifier for BSD-3-Clause

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
license = BSD
license = BSD-3-Clause

description = The next generation HTTP client.
Copy link
Member Author

@graingert graingert Oct 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated from httpx.__version__.__description__ because this key doesn't support attr: if people are ok with me adding importlib_resources I'll change it to a file:

long_description = file: README.md, file: CHANGELOG.md
graingert marked this conversation as resolved.
Show resolved Hide resolved
long_description_content_type = text/markdown
author = Tom Christie
author_email = tom@tomchristie.com
classifiers =
Development Status :: 3 - Alpha
Environment :: Web Environment
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This license is wrong. This package is licensed under the BSD 3 clause

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
License :: OSI Approved :: BSD License

Operating System :: OS Independent
Topic :: Internet :: WWW/HTTP
Framework :: AsyncIO
Framework :: Trio
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8

[options]
python_requires = >=3.6
packages = find:
zip_safe = False
graingert marked this conversation as resolved.
Show resolved Hide resolved
install_requires =
certifi
chardet==3.*
h11==0.8.*
h2==3.*
hstspreload>=2019.8.27
idna==2.*
rfc3986==1.*

[options.packages.find]
include =
httpx
httpx.*

[options.package_data]
httpx =
py.typed

[bdist_wheel]
universal = 1

Expand Down
75 changes: 1 addition & 74 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,76 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import re
from pathlib import Path

from setuptools import setup
graingert marked this conversation as resolved.
Show resolved Hide resolved


def get_version(package):
"""
Return package version as listed in `__version__` in `init.py`.
"""
version = Path(package, "__version__.py").read_text()
return re.search("__version__ = ['\"]([^'\"]+)['\"]", version).group(1)


def get_long_description():
"""
Return the README.
"""
long_description = ""
with open("README.md", encoding="utf8") as f:
long_description += f.read()
long_description += "\n\n"
with open("CHANGELOG.md", encoding="utf8") as f:
long_description += f.read()
return long_description


def get_packages(package):
"""
Return root package and all sub-packages.
"""
return [str(path.parent) for path in Path(package).glob("**/__init__.py")]


setup(
name="httpx",
python_requires=">=3.6",
version=get_version("httpx"),
url="https://github.com/encode/httpx",
license="BSD",
description="The next generation HTTP client.",
long_description=get_long_description(),
long_description_content_type="text/markdown",
author="Tom Christie",
author_email="tom@tomchristie.com",
package_data={"httpx": ["py.typed"]},
packages=get_packages("httpx"),
include_package_data=True,
zip_safe=False,
install_requires=[
"certifi",
"chardet==3.*",
"h11==0.8.*",
"h2==3.*",
"hstspreload>=2019.8.27",
"idna==2.*",
"rfc3986==1.*",
],
classifiers=[
"Development Status :: 3 - Alpha",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Topic :: Internet :: WWW/HTTP",
"Framework :: AsyncIO",
"Framework :: Trio",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
)
setup()
9 changes: 9 additions & 0 deletions src.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pathlib
import re

PACKAGE = "httpx"


def get_version(package=PACKAGE):
version = pathlib.Path(package, "__version__.py").read_text()
return re.search("__version__ = ['\"]([^'\"]+)['\"]", version).group(1)
Comment on lines +1 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this part into httpx/httpx/__version__.py

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because you can't import httpx until after setup

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly this one edge-case has me not wanting to merge this. :(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setup.py already does not import http.__version__.__version__ because of this limitation. It's not an edge case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant having this file to accomplish only this one task.