-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add setup.py #2025
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
Closed
Add setup.py #2025
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2ac544e
Add setup.py
7e305e3
Add .git to .flake8 excludes because it matched my branch's name 😂
c4c7291
Remove unnecessary imports
ambv 9c8df53
Simplify setup.py
ambv c09306d
After Guido's review: don't spawn subprocess on `import typeshed`, mo…
ambv 703933f
Moved repo-related functionality out of typeshed/__init__.py
ambv 1744a1f
Document how to use typeshed
ambv 7493a19
`s/__location__/get_dir()/` and word editing
ambv d8a5d25
Add missing "of"
ambv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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", "")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../stdlib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../third_party |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK