Skip to content
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: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ ignore = F401, F403, F405, F811, E127, E128, E301, E302, E305, E501, E701, E704,
# A nice future improvement would be to provide separate .flake8
# configurations for Python 2 and Python 3 files.
builtins = StandardError,apply,basestring,buffer,cmp,coerce,execfile,file,intern,long,raw_input,reduce,reload,unichr,unicode,xrange
exclude = .venv*,@*
exclude = .git,.venv*,@*
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include *.rst *.md LICENSE
recursive-include typeshed *.py
recursive-include typeshed/stdlib *.pyi
recursive-include typeshed/third_party *.pyi
Copy link
Member

Choose a reason for hiding this comment

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

Can't the latter two be combined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those directories are symlinks and I couldn't get it to work with just one line. Globbing inside those directories works fine though.

Copy link
Member

Choose a reason for hiding this comment

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

OK

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ coding style used in typeshed.

### stdlib

This contains stubs for modules the Python standard library -- which
includes pure Python modules, dynamically loaded extension modules,
hard-linked extension modules, and the builtins.
This contains stubs for modules of the Python standard library -- which includes
pure Python modules, dynamically loaded extension modules, hard-linked extension
modules, and the builtins.

### third_party

Expand Down
39 changes: 39 additions & 0 deletions _typeshed_repo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Utilities for setup.py to understand the state of the repository."""

import os
import subprocess

from typeshed import __location__


def is_git_repo(dir):
# type: () -> bool
return os.path.exists(os.path.join(dir, ".git"))


def is_dirty():
# type: () -> bool
base = os.path.dirname(__location__)
if not is_git_repo(base):
return False

try:
out = subprocess.check_output(["git", "status", "--porcelain"], cwd=base)
return bool(out.strip())

except (subprocess.CalledProcessError, OSError):
return False


def get_revision():
# type: () -> str
base = os.path.dirname(__location__)
if not is_git_repo(base):
return ""

try:
out = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=base)
return out.strip().decode("utf8")

except (subprocess.CalledProcessError, OSError):
return ""
61 changes: 61 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from __future__ import print_function

import codecs
import os
import sys
from setuptools import setup

import typeshed
try:
import _typeshed_repo
except ImportError:
_revision = ""
_is_dirty = False
else:
_revision = _typeshed_repo.get_revision()
_is_dirty = _typeshed_repo.is_dirty()


VERSION = typeshed.__version__
PROJECT_URL = "https://github.com/python/typeshed/"
ISSUES_URL = PROJECT_URL + "issues/"
SOURCE_URL = PROJECT_URL
if _revision:
SOURCE_URL += "commit/" + _revision


def get_long_description():
current_dir = os.path.dirname(__file__)
readme_md = os.path.join(current_dir, "README.md")
with codecs.open(readme_md, encoding="utf8") as ld_file:
return ld_file.read()


setup(
name="typeshed",
version=VERSION,
description="Collection of library stubs for Python, with static types",
long_description=get_long_description(),
long_description_content_type="text/markdown",
license="MIT",
url=PROJECT_URL,
packages=["typeshed"],
include_package_data=True, # from MANIFEST.in
project_urls={"Bug Tracker": ISSUES_URL, "Source Code": SOURCE_URL},
install_requires=[],
classifiers=[
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: Quality Assurance",
],
python_requires=">=2.7",
zip_safe=True,
)


if _is_dirty:
print()
print("WARNING: there are uncommitted changes.", file=sys.stderr)
67 changes: 67 additions & 0 deletions typeshed/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
"""A collection of type annotations for the standard library and others.

The type annotations in question are stored in so-called "stub files". They're
Python-like files with the .pyi file extension. See PEP 484 for more details.

Typeshed is organized in the following directory structure:

typeshed
├── __init__.py
├── stdlib
│ ├── 2
│ ├── 2and3
│ ├── 3
│ ├── 3.3
│ ├── 3.4
│ └── ...
└── third_party
├── 2
├── 2and3
├── 3
└── ...

The `stdlib` directory contains stubs for modules of the Python standard library.
This includes pure Python modules, dynamically loaded extension modules,
hard-linked extension modules, and the builtins. Modules that are not shipped
with Python but have a type description in Python go into `third_party`.

Modules with types that behave the same regardless of the Python version used
are stored in `2and3` directories. Specific versions like `3.6` describe
modules which are not available in previous versions. `3` is a generic
directory storing type informartion for any Python 3 version. Stub files often
contain sections which declare compatibility with only a particular subset of
Python 3 versions. Those sections are marked using `if sys.version_info`
checks. See PEP 484 for more details.

To get the absolute location of the base typeshed directory in your project,
use the following:

>>> import typeshed
>>> typeshed.get_dir()
'/path/to/typeshed/'

`get_dir()` works also for zipped archives. In this case it points to
a temporary directory where typeshed was unpacked.
"""

from os.path import dirname, realpath


__all__ = ['__version__', 'get_dir']
__version__ = "18.4.0"


def get_dir():
# type: () -> str
"""Return the absolute path to the location of typeshed as a string.

Works also for zipped archives. In this case it points to a temporary
directory where typeshed was unpacked.
"""
try:
import pkg_resources
except ImportError:
return realpath(dirname(dirname(__file__)))
else:
return realpath(pkg_resources.resource_filename("typeshed", ""))
1 change: 1 addition & 0 deletions typeshed/stdlib
1 change: 1 addition & 0 deletions typeshed/third_party