mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
Move __doc__ crate to crates/doc (#6234)
* Add `__doc__` crate * Base auto-generate ci * Add dummy files * Update docs * Set codegen-units to 1 for doc db * Mark `*.inc.rs` as auto generated * Disable doctest * Reset docs
This commit is contained in:
1 parent
9ce85862ce
commit
db1adaa2c2
15 files changed
+9702
-33
No files matched your search
@@ -5,3 +5,4 @@ vm/src/stdlib/ast/gen.rs linguist-generated -merge
|
||||
Lib/*.py text working-tree-encoding=UTF-8 eol=LF
|
||||
**/*.rs text working-tree-encoding=UTF-8 eol=LF
|
||||
*.pck binary
|
||||
crates/rustpython_doc_db/src/*.inc.rs linguist-generated=true
|
||||
@@ -113,7 +113,7 @@ jobs:
|
||||
RUST_BACKTRACE: full
|
||||
name: Run rust tests
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: ${{ contains(matrix.os, 'windows') && 45 || 30 }}
|
||||
timeout-minutes: ${{ contains(matrix.os, 'windows') && 45 || 35 }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [macos-latest, ubuntu-latest, windows-latest]
|
||||
@@ -239,7 +239,7 @@ jobs:
|
||||
RUST_BACKTRACE: full
|
||||
name: Run snippets and cpython tests
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: ${{ contains(matrix.os, 'windows') && 45 || 30 }}
|
||||
timeout-minutes: ${{ contains(matrix.os, 'windows') && 45 || 35 }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [macos-latest, ubuntu-latest, windows-latest]
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
name: Update doc DB
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
python-version:
|
||||
description: Target python version to generate doc db for
|
||||
type: string
|
||||
default: "3.13.9"
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
working-directory: ./crates/rustpython-doc
|
||||
|
||||
jobs:
|
||||
generate:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- windows-latest
|
||||
- macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
sparse-checkout: |
|
||||
crates/rustpython-doc
|
||||
|
||||
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
|
||||
with:
|
||||
python-version: ${{ inputs.python-version }}
|
||||
|
||||
- name: Generate docs
|
||||
run: python ./generate.py
|
||||
|
||||
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: doc-db-${{ inputs.python-version }}-${{ matrix.os }}
|
||||
path: "crates/rustpython-doc/generated/*.json"
|
||||
if-no-files-found: error
|
||||
retention-days: 7
|
||||
overwrite: true
|
||||
|
||||
merge:
|
||||
runs-on: ubuntu-latest
|
||||
needs: generate
|
||||
steps:
|
||||
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
sparse-checkout: |
|
||||
crates/rustpython-doc
|
||||
|
||||
- name: Download generated doc DBs
|
||||
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
|
||||
with:
|
||||
pattern: "doc-db-${{ inputs.python-version }}-**"
|
||||
path: crates/rustpython-doc/generated/
|
||||
merge-multiple: true
|
||||
|
||||
- name: Transform JSON
|
||||
run: |
|
||||
# Merge all artifacts
|
||||
jq -s "add" --sort-keys generated/*.json > generated/merged.json
|
||||
|
||||
# Format merged json for the phf macro
|
||||
jq -r 'to_entries[] | " \(.key | @json) => \(.value | @json),"' generated/merged.json > generated/raw_entries.txt
|
||||
|
||||
OUTPUT_FILE='src/data.inc.rs'
|
||||
|
||||
echo -n '' > $OUTPUT_FILE
|
||||
|
||||
echo '// This file was auto-generated by `.github/workflows/update-doc-db.yml`.' >> $OUTPUT_FILE
|
||||
echo "// CPython version: ${{ inputs.python-version }}" >> $OUTPUT_FILE
|
||||
echo '// spell-checker: disable' >> $OUTPUT_FILE
|
||||
|
||||
echo '' >> $OUTPUT_FILE
|
||||
|
||||
echo "pub static DB: phf::Map<&'static str, &'static str> = phf::phf_map! {" >> $OUTPUT_FILE
|
||||
cat generated/raw_entries.txt >> $OUTPUT_FILE
|
||||
echo '};' >> $OUTPUT_FILE
|
||||
|
||||
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
|
||||
with:
|
||||
name: doc-db-${{ inputs.python-version }}
|
||||
path: "crates/rustpython-doc/src/data.inc.rs"
|
||||
if-no-files-found: error
|
||||
retention-days: 7
|
||||
overwrite: true
|
||||
Generated
+60
-13
@@ -893,6 +893,12 @@ version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
||||
|
||||
[[package]]
|
||||
name = "fd-lock"
|
||||
version = "4.0.4"
|
||||
@@ -1825,8 +1831,18 @@ version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd6780a80ae0c52cc120a26a1a42c1ae51b247a253e4e06113d23d2c2edd078"
|
||||
dependencies = [
|
||||
"phf_macros",
|
||||
"phf_shared",
|
||||
"phf_macros 0.11.3",
|
||||
"phf_shared 0.11.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf"
|
||||
dependencies = [
|
||||
"phf_macros 0.13.1",
|
||||
"phf_shared 0.13.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1835,8 +1851,8 @@ version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aef8048c789fa5e851558d709946d6d79a8ff88c0440c587967f8e94bfb1216a"
|
||||
dependencies = [
|
||||
"phf_generator",
|
||||
"phf_shared",
|
||||
"phf_generator 0.11.3",
|
||||
"phf_shared 0.11.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1845,18 +1861,41 @@ version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
|
||||
dependencies = [
|
||||
"phf_shared",
|
||||
"phf_shared 0.11.3",
|
||||
"rand 0.8.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_generator"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "135ace3a761e564ec88c03a77317a7c6b80bb7f7135ef2544dbe054243b89737"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"phf_shared 0.13.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_macros"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216"
|
||||
dependencies = [
|
||||
"phf_generator",
|
||||
"phf_shared",
|
||||
"phf_generator 0.11.3",
|
||||
"phf_shared 0.11.3",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_macros"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "812f032b54b1e759ccd5f8b6677695d5268c588701effba24601f6932f8269ef"
|
||||
dependencies = [
|
||||
"phf_generator 0.13.1",
|
||||
"phf_shared 0.13.1",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
@@ -1871,6 +1910,15 @@ dependencies = [
|
||||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf_shared"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266"
|
||||
dependencies = [
|
||||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.32"
|
||||
@@ -2489,10 +2537,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustpython-doc"
|
||||
version = "0.3.0"
|
||||
source = "git+https://github.com/RustPython/__doc__?tag=0.3.0#8b62ce5d796d68a091969c9fa5406276cb483f79"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"phf 0.13.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2587,7 +2634,7 @@ dependencies = [
|
||||
"page_size",
|
||||
"parking_lot",
|
||||
"paste",
|
||||
"phf",
|
||||
"phf 0.11.3",
|
||||
"pymath",
|
||||
"rand_core 0.9.3",
|
||||
"rustix",
|
||||
@@ -3368,7 +3415,7 @@ version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d1673eca9782c84de5f81b82e4109dcfb3611c8ba0d52930ec4a9478f547b2dd"
|
||||
dependencies = [
|
||||
"phf",
|
||||
"phf 0.11.3",
|
||||
"unicode_names2_generator 1.3.0",
|
||||
]
|
||||
|
||||
@@ -3378,7 +3425,7 @@ version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d189085656ca1203291e965444e7f6a2723fbdd1dd9f34f8482e79bafd8338a0"
|
||||
dependencies = [
|
||||
"phf",
|
||||
"phf 0.11.3",
|
||||
"unicode_names2_generator 2.0.0",
|
||||
]
|
||||
|
||||
|
||||
+7
-1
@@ -73,6 +73,10 @@ opt-level = 3
|
||||
# https://github.com/rust-lang/rust/issues/92869
|
||||
# lto = "thin"
|
||||
|
||||
# Doesn't change often
|
||||
[profile.release.package.rustpython-doc]
|
||||
codegen-units = 1
|
||||
|
||||
[profile.bench]
|
||||
lto = "thin"
|
||||
codegen-units = 1
|
||||
@@ -132,6 +136,7 @@ members = [
|
||||
"derive-impl",
|
||||
"wtf8",
|
||||
"wasm/lib",
|
||||
"crates/*",
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
@@ -156,13 +161,14 @@ rustpython-pylib = { path = "pylib", version = "0.4.0" }
|
||||
rustpython-stdlib = { path = "stdlib", default-features = false, version = "0.4.0" }
|
||||
rustpython-sre_engine = { path = "vm/sre_engine", version = "0.4.0" }
|
||||
rustpython-wtf8 = { path = "wtf8", version = "0.4.0" }
|
||||
rustpython-doc = { git = "https://github.com/RustPython/__doc__", tag = "0.3.0", version = "0.3.0" }
|
||||
rustpython-doc = { path = "crates/doc", version = "0.4.0" }
|
||||
|
||||
ruff_python_parser = { git = "https://github.com/astral-sh/ruff.git", tag = "0.14.1" }
|
||||
ruff_python_ast = { git = "https://github.com/astral-sh/ruff.git", tag = "0.14.1" }
|
||||
ruff_text_size = { git = "https://github.com/astral-sh/ruff.git", tag = "0.14.1" }
|
||||
ruff_source_file = { git = "https://github.com/astral-sh/ruff.git", tag = "0.14.1" }
|
||||
|
||||
phf = { version = "0.13.1", default-features = false, features = ["macros"]}
|
||||
ahash = "0.8.12"
|
||||
ascii = "1.1"
|
||||
bitflags = "2.9.4"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
generated/
|
||||
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "rustpython-doc"
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
repository.workspace = true
|
||||
license-file = "LICENSE"
|
||||
|
||||
[dependencies]
|
||||
phf = { workspace = true }
|
||||
|
||||
[lib]
|
||||
doctest = false # Crashes when true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -0,0 +1,277 @@
|
||||
A. HISTORY OF THE SOFTWARE
|
||||
==========================
|
||||
|
||||
Python was created in the early 1990s by Guido van Rossum at Stichting
|
||||
Mathematisch Centrum (CWI, see https://www.cwi.nl) in the Netherlands
|
||||
as a successor of a language called ABC. Guido remains Python's
|
||||
principal author, although it includes many contributions from others.
|
||||
|
||||
In 1995, Guido continued his work on Python at the Corporation for
|
||||
National Research Initiatives (CNRI, see https://www.cnri.reston.va.us)
|
||||
in Reston, Virginia where he released several versions of the
|
||||
software.
|
||||
|
||||
In May 2000, Guido and the Python core development team moved to
|
||||
BeOpen.com to form the BeOpen PythonLabs team. In October of the same
|
||||
year, the PythonLabs team moved to Digital Creations, which became
|
||||
Zope Corporation. In 2001, the Python Software Foundation (PSF, see
|
||||
https://www.python.org/psf/) was formed, a non-profit organization
|
||||
created specifically to own Python-related Intellectual Property.
|
||||
Zope Corporation was a sponsoring member of the PSF.
|
||||
|
||||
All Python releases are Open Source (see https://opensource.org for
|
||||
the Open Source Definition). Historically, most, but not all, Python
|
||||
releases have also been GPL-compatible; the table below summarizes
|
||||
the various releases.
|
||||
|
||||
Release Derived Year Owner GPL-
|
||||
from compatible? (1)
|
||||
|
||||
0.9.0 thru 1.2 1991-1995 CWI yes
|
||||
1.3 thru 1.5.2 1.2 1995-1999 CNRI yes
|
||||
1.6 1.5.2 2000 CNRI no
|
||||
2.0 1.6 2000 BeOpen.com no
|
||||
1.6.1 1.6 2001 CNRI yes (2)
|
||||
2.1 2.0+1.6.1 2001 PSF no
|
||||
2.0.1 2.0+1.6.1 2001 PSF yes
|
||||
2.1.1 2.1+2.0.1 2001 PSF yes
|
||||
2.1.2 2.1.1 2002 PSF yes
|
||||
2.1.3 2.1.2 2002 PSF yes
|
||||
2.2 and above 2.1.1 2001-now PSF yes
|
||||
|
||||
Footnotes:
|
||||
|
||||
(1) GPL-compatible doesn't mean that we're distributing Python under
|
||||
the GPL. All Python licenses, unlike the GPL, let you distribute
|
||||
a modified version without making your changes open source. The
|
||||
GPL-compatible licenses make it possible to combine Python with
|
||||
other software that is released under the GPL; the others don't.
|
||||
|
||||
(2) According to Richard Stallman, 1.6.1 is not GPL-compatible,
|
||||
because its license has a choice of law clause. According to
|
||||
CNRI, however, Stallman's lawyer has told CNRI's lawyer that 1.6.1
|
||||
is "not incompatible" with the GPL.
|
||||
|
||||
Thanks to the many outside volunteers who have worked under Guido's
|
||||
direction to make these releases possible.
|
||||
|
||||
|
||||
B. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON
|
||||
===============================================================
|
||||
|
||||
Python software and documentation are licensed under the
|
||||
Python Software Foundation License Version 2.
|
||||
|
||||
Starting with Python 3.8.6, examples, recipes, and other code in
|
||||
the documentation are dual licensed under the PSF License Version 2
|
||||
and the Zero-Clause BSD license.
|
||||
|
||||
Some software incorporated into Python is under different licenses.
|
||||
The licenses are listed with code falling under that license.
|
||||
|
||||
|
||||
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
|
||||
--------------------------------------------
|
||||
|
||||
1. This LICENSE AGREEMENT is between the Python Software Foundation
|
||||
("PSF"), and the Individual or Organization ("Licensee") accessing and
|
||||
otherwise using this software ("Python") in source or binary form and
|
||||
its associated documentation.
|
||||
|
||||
2. Subject to the terms and conditions of this License Agreement, PSF hereby
|
||||
grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
|
||||
analyze, test, perform and/or display publicly, prepare derivative works,
|
||||
distribute, and otherwise use Python alone or in any derivative version,
|
||||
provided, however, that PSF's License Agreement and PSF's notice of copyright,
|
||||
i.e., "Copyright (c) 2001 Python Software Foundation; All Rights Reserved"
|
||||
are retained in Python alone or in any derivative version prepared by Licensee.
|
||||
|
||||
3. In the event Licensee prepares a derivative work that is based on
|
||||
or incorporates Python or any part thereof, and wants to make
|
||||
the derivative work available to others as provided herein, then
|
||||
Licensee hereby agrees to include in any such work a brief summary of
|
||||
the changes made to Python.
|
||||
|
||||
4. PSF is making Python available to Licensee on an "AS IS"
|
||||
basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
||||
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
|
||||
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
|
||||
INFRINGE ANY THIRD PARTY RIGHTS.
|
||||
|
||||
5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
|
||||
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
|
||||
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
|
||||
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
|
||||
|
||||
6. This License Agreement will automatically terminate upon a material
|
||||
breach of its terms and conditions.
|
||||
|
||||
7. Nothing in this License Agreement shall be deemed to create any
|
||||
relationship of agency, partnership, or joint venture between PSF and
|
||||
Licensee. This License Agreement does not grant permission to use PSF
|
||||
trademarks or trade name in a trademark sense to endorse or promote
|
||||
products or services of Licensee, or any third party.
|
||||
|
||||
8. By copying, installing or otherwise using Python, Licensee
|
||||
agrees to be bound by the terms and conditions of this License
|
||||
Agreement.
|
||||
|
||||
|
||||
BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0
|
||||
-------------------------------------------
|
||||
|
||||
BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1
|
||||
|
||||
1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an
|
||||
office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the
|
||||
Individual or Organization ("Licensee") accessing and otherwise using
|
||||
this software in source or binary form and its associated
|
||||
documentation ("the Software").
|
||||
|
||||
2. Subject to the terms and conditions of this BeOpen Python License
|
||||
Agreement, BeOpen hereby grants Licensee a non-exclusive,
|
||||
royalty-free, world-wide license to reproduce, analyze, test, perform
|
||||
and/or display publicly, prepare derivative works, distribute, and
|
||||
otherwise use the Software alone or in any derivative version,
|
||||
provided, however, that the BeOpen Python License is retained in the
|
||||
Software, alone or in any derivative version prepared by Licensee.
|
||||
|
||||
3. BeOpen is making the Software available to Licensee on an "AS IS"
|
||||
basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
||||
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND
|
||||
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT
|
||||
INFRINGE ANY THIRD PARTY RIGHTS.
|
||||
|
||||
4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE
|
||||
SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS
|
||||
AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY
|
||||
DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
|
||||
|
||||
5. This License Agreement will automatically terminate upon a material
|
||||
breach of its terms and conditions.
|
||||
|
||||
6. This License Agreement shall be governed by and interpreted in all
|
||||
respects by the law of the State of California, excluding conflict of
|
||||
law provisions. Nothing in this License Agreement shall be deemed to
|
||||
create any relationship of agency, partnership, or joint venture
|
||||
between BeOpen and Licensee. This License Agreement does not grant
|
||||
permission to use BeOpen trademarks or trade names in a trademark
|
||||
sense to endorse or promote products or services of Licensee, or any
|
||||
third party. As an exception, the "BeOpen Python" logos available at
|
||||
http://www.pythonlabs.com/logos.html may be used according to the
|
||||
permissions granted on that web page.
|
||||
|
||||
7. By copying, installing or otherwise using the software, Licensee
|
||||
agrees to be bound by the terms and conditions of this License
|
||||
Agreement.
|
||||
|
||||
|
||||
CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1
|
||||
---------------------------------------
|
||||
|
||||
1. This LICENSE AGREEMENT is between the Corporation for National
|
||||
Research Initiatives, having an office at 1895 Preston White Drive,
|
||||
Reston, VA 20191 ("CNRI"), and the Individual or Organization
|
||||
("Licensee") accessing and otherwise using Python 1.6.1 software in
|
||||
source or binary form and its associated documentation.
|
||||
|
||||
2. Subject to the terms and conditions of this License Agreement, CNRI
|
||||
hereby grants Licensee a nonexclusive, royalty-free, world-wide
|
||||
license to reproduce, analyze, test, perform and/or display publicly,
|
||||
prepare derivative works, distribute, and otherwise use Python 1.6.1
|
||||
alone or in any derivative version, provided, however, that CNRI's
|
||||
License Agreement and CNRI's notice of copyright, i.e., "Copyright (c)
|
||||
1995-2001 Corporation for National Research Initiatives; All Rights
|
||||
Reserved" are retained in Python 1.6.1 alone or in any derivative
|
||||
version prepared by Licensee. Alternately, in lieu of CNRI's License
|
||||
Agreement, Licensee may substitute the following text (omitting the
|
||||
quotes): "Python 1.6.1 is made available subject to the terms and
|
||||
conditions in CNRI's License Agreement. This Agreement together with
|
||||
Python 1.6.1 may be located on the internet using the following
|
||||
unique, persistent identifier (known as a handle): 1895.22/1013. This
|
||||
Agreement may also be obtained from a proxy server on the internet
|
||||
using the following URL: http://hdl.handle.net/1895.22/1013".
|
||||
|
||||
3. In the event Licensee prepares a derivative work that is based on
|
||||
or incorporates Python 1.6.1 or any part thereof, and wants to make
|
||||
the derivative work available to others as provided herein, then
|
||||
Licensee hereby agrees to include in any such work a brief summary of
|
||||
the changes made to Python 1.6.1.
|
||||
|
||||
4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS"
|
||||
basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
||||
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND
|
||||
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
|
||||
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT
|
||||
INFRINGE ANY THIRD PARTY RIGHTS.
|
||||
|
||||
5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
|
||||
1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
|
||||
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1,
|
||||
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
|
||||
|
||||
6. This License Agreement will automatically terminate upon a material
|
||||
breach of its terms and conditions.
|
||||
|
||||
7. This License Agreement shall be governed by the federal
|
||||
intellectual property law of the United States, including without
|
||||
limitation the federal copyright law, and, to the extent such
|
||||
U.S. federal law does not apply, by the law of the Commonwealth of
|
||||
Virginia, excluding Virginia's conflict of law provisions.
|
||||
Notwithstanding the foregoing, with regard to derivative works based
|
||||
on Python 1.6.1 that incorporate non-separable material that was
|
||||
previously distributed under the GNU General Public License (GPL), the
|
||||
law of the Commonwealth of Virginia shall govern this License
|
||||
Agreement only as to issues arising under or with respect to
|
||||
Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this
|
||||
License Agreement shall be deemed to create any relationship of
|
||||
agency, partnership, or joint venture between CNRI and Licensee. This
|
||||
License Agreement does not grant permission to use CNRI trademarks or
|
||||
trade name in a trademark sense to endorse or promote products or
|
||||
services of Licensee, or any third party.
|
||||
|
||||
8. By clicking on the "ACCEPT" button where indicated, or by copying,
|
||||
installing or otherwise using Python 1.6.1, Licensee agrees to be
|
||||
bound by the terms and conditions of this License Agreement.
|
||||
|
||||
ACCEPT
|
||||
|
||||
|
||||
CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2
|
||||
--------------------------------------------------
|
||||
|
||||
Copyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam,
|
||||
The Netherlands. All rights reserved.
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee is hereby granted,
|
||||
provided that the above copyright notice appear in all copies and that
|
||||
both that copyright notice and this permission notice appear in
|
||||
supporting documentation, and that the name of Stichting Mathematisch
|
||||
Centrum or CWI not be used in advertising or publicity pertaining to
|
||||
distribution of the software without specific, written prior
|
||||
permission.
|
||||
|
||||
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
|
||||
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
|
||||
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
ZERO-CLAUSE BSD LICENSE FOR CODE IN THE PYTHON DOCUMENTATION
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
@@ -0,0 +1,214 @@
|
||||
#!/usr/bin/env python
|
||||
import argparse
|
||||
import inspect
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import platform
|
||||
import pydoc
|
||||
import re
|
||||
import sys
|
||||
import types
|
||||
import typing
|
||||
import warnings
|
||||
from importlib.machinery import EXTENSION_SUFFIXES, ExtensionFileLoader
|
||||
|
||||
if typing.TYPE_CHECKING:
|
||||
from collections.abc import Iterable
|
||||
|
||||
OUTPUT_FILE = pathlib.Path(__file__).parent / "generated" / f"{sys.platform}.json"
|
||||
OUTPUT_FILE.parent.mkdir(exist_ok=True)
|
||||
|
||||
UNICODE_ESCAPE = re.compile(r"\\u([0-9]+)")
|
||||
|
||||
IGNORED_MODULES = {"this", "antigravity"}
|
||||
IGNORED_ATTRS = {
|
||||
"__annotations__",
|
||||
"__class__",
|
||||
"__dict__",
|
||||
"__dir__",
|
||||
"__doc__",
|
||||
"__file__",
|
||||
"__name__",
|
||||
"__qualname__",
|
||||
}
|
||||
|
||||
|
||||
type Parts = tuple[str, ...]
|
||||
|
||||
|
||||
class DocEntry(typing.NamedTuple):
|
||||
parts: Parts
|
||||
raw_doc: str | None
|
||||
|
||||
@property
|
||||
def key(self) -> str:
|
||||
return ".".join(self.parts)
|
||||
|
||||
@property
|
||||
def doc(self) -> str:
|
||||
assert self.raw_doc is not None
|
||||
|
||||
return re.sub(UNICODE_ESCAPE, r"\\u{\1}", inspect.cleandoc(self.raw_doc))
|
||||
|
||||
|
||||
def is_c_extension(module: types.ModuleType) -> bool:
|
||||
"""
|
||||
Check whether a module was written in C.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
|
||||
Notes
|
||||
-----
|
||||
Adapted from: https://stackoverflow.com/a/39304199
|
||||
"""
|
||||
loader = getattr(module, "__loader__", None)
|
||||
if isinstance(loader, ExtensionFileLoader):
|
||||
return True
|
||||
|
||||
try:
|
||||
inspect.getsource(module)
|
||||
except (OSError, TypeError):
|
||||
return True
|
||||
|
||||
try:
|
||||
module_filename = inspect.getfile(module)
|
||||
except TypeError:
|
||||
return True
|
||||
|
||||
module_filetype = os.path.splitext(module_filename)[1]
|
||||
return module_filetype in EXTENSION_SUFFIXES
|
||||
|
||||
|
||||
def is_child_of(obj: typing.Any, module: types.ModuleType) -> bool:
|
||||
"""
|
||||
Whether or not an object is a child of a module.
|
||||
|
||||
Returns
|
||||
-------
|
||||
bool
|
||||
"""
|
||||
return inspect.getmodule(obj) is module
|
||||
|
||||
|
||||
def iter_modules() -> "Iterable[types.ModuleType]":
|
||||
"""
|
||||
Yields
|
||||
------
|
||||
:class:`types.Module`
|
||||
Python modules.
|
||||
"""
|
||||
for module_name in sys.stdlib_module_names - IGNORED_MODULES:
|
||||
try:
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
||||
module = __import__(module_name)
|
||||
except ImportError:
|
||||
warnings.warn(f"Could not import {module_name}", category=ImportWarning)
|
||||
continue
|
||||
|
||||
yield module
|
||||
|
||||
|
||||
def iter_c_modules() -> "Iterable[types.ModuleType]":
|
||||
"""
|
||||
Yields
|
||||
------
|
||||
:class:`types.Module`
|
||||
Modules that are written in C. (not pure python)
|
||||
"""
|
||||
yield from filter(is_c_extension, iter_modules())
|
||||
|
||||
|
||||
def traverse(
|
||||
obj: typing.Any, module: types.ModuleType, parts: Parts = ()
|
||||
) -> "typing.Iterable[DocEntry]":
|
||||
if inspect.ismodule(obj):
|
||||
parts += (obj.__name__,)
|
||||
|
||||
if any(f(obj) for f in (inspect.ismodule, inspect.isclass, inspect.isbuiltin)):
|
||||
yield DocEntry(parts, pydoc._getowndoc(obj))
|
||||
|
||||
for name, attr in inspect.getmembers(obj):
|
||||
if name in IGNORED_ATTRS:
|
||||
continue
|
||||
|
||||
if attr == obj:
|
||||
continue
|
||||
|
||||
if (module is obj) and (not is_child_of(attr, module)):
|
||||
continue
|
||||
|
||||
# Don't recurse into modules imported by our module. i.e. `ipaddress.py` imports `re` don't traverse `re`
|
||||
if (not inspect.ismodule(obj)) and inspect.ismodule(attr):
|
||||
continue
|
||||
|
||||
new_parts = parts + (name,)
|
||||
|
||||
attr_typ = type(attr)
|
||||
is_type_or_builtin = any(attr_typ is x for x in (type, type(__builtins__)))
|
||||
|
||||
if is_type_or_builtin:
|
||||
yield from traverse(attr, module, new_parts)
|
||||
continue
|
||||
|
||||
is_callable = (
|
||||
callable(attr)
|
||||
or not issubclass(attr_typ, type)
|
||||
or attr_typ.__name__ in ("getset_descriptor", "member_descriptor")
|
||||
)
|
||||
|
||||
is_func = any(
|
||||
f(attr)
|
||||
for f in (inspect.isfunction, inspect.ismethod, inspect.ismethoddescriptor)
|
||||
)
|
||||
|
||||
if is_callable or is_func:
|
||||
yield DocEntry(new_parts, pydoc._getowndoc(attr))
|
||||
|
||||
|
||||
def find_doc_entries() -> "Iterable[DocEntry]":
|
||||
yield from (
|
||||
doc_entry
|
||||
for module in iter_c_modules()
|
||||
for doc_entry in traverse(module, module)
|
||||
)
|
||||
yield from (doc_entry for doc_entry in traverse(__builtins__, __builtins__))
|
||||
|
||||
builtin_types = [
|
||||
type(None),
|
||||
type(bytearray().__iter__()),
|
||||
type(bytes().__iter__()),
|
||||
type(dict().__iter__()),
|
||||
type(dict().items()),
|
||||
type(dict().items().__iter__()),
|
||||
type(dict().values()),
|
||||
type(dict().values().__iter__()),
|
||||
type(lambda: ...),
|
||||
type(list().__iter__()),
|
||||
type(memoryview(b"").__iter__()),
|
||||
type(range(0).__iter__()),
|
||||
type(set().__iter__()),
|
||||
type(str().__iter__()),
|
||||
type(tuple().__iter__()),
|
||||
]
|
||||
for typ in builtin_types:
|
||||
parts = ("builtins", typ.__name__)
|
||||
yield DocEntry(parts, pydoc._getowndoc(typ))
|
||||
yield from traverse(typ, __builtins__, parts)
|
||||
|
||||
|
||||
def main():
|
||||
docs = {
|
||||
entry.key: entry.doc
|
||||
for entry in find_doc_entries()
|
||||
if entry.raw_doc is not None
|
||||
}
|
||||
dumped = json.dumps(docs, sort_keys=True, indent=4)
|
||||
OUTPUT_FILE.write_text(dumped)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,12 @@
|
||||
include!("./data.inc.rs");
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::DB;
|
||||
|
||||
#[test]
|
||||
fn test_db() {
|
||||
let doc = DB.get("array._array_reconstructor");
|
||||
assert!(doc.is_some());
|
||||
}
|
||||
}
|
||||
@@ -23,4 +23,4 @@ syn-ext = { version = "0.5.0", features = ["full"] }
|
||||
textwrap = { version = "0.16.1", default-features = false }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
workspace = true
|
||||
@@ -23,7 +23,6 @@ mod pytraverse;
|
||||
use error::Diagnostic;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::ToTokens;
|
||||
use rustpython_doc as doc;
|
||||
use syn::{DeriveInput, Item};
|
||||
use syn_ext::types::PunctuatedNestedMeta;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::util::{
|
||||
};
|
||||
use proc_macro2::{Delimiter, Group, Span, TokenStream, TokenTree};
|
||||
use quote::{ToTokens, quote, quote_spanned};
|
||||
use rustpython_doc::DB;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::str::FromStr;
|
||||
use syn::{Attribute, Ident, Item, Result, parse_quote, spanned::Spanned};
|
||||
@@ -315,10 +316,8 @@ fn generate_class_def(
|
||||
) -> Result<TokenStream> {
|
||||
let doc = attrs.doc().or_else(|| {
|
||||
let module_name = module_name.unwrap_or("builtins");
|
||||
crate::doc::Database::shared()
|
||||
.try_module_item(module_name, name)
|
||||
.ok()
|
||||
.flatten()
|
||||
DB.get(&format!("{module_name}.{name}"))
|
||||
.copied()
|
||||
.map(str::to_owned)
|
||||
});
|
||||
let doc = if let Some(doc) = doc {
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::util::{
|
||||
};
|
||||
use proc_macro2::{Delimiter, Group, TokenStream, TokenTree};
|
||||
use quote::{ToTokens, quote, quote_spanned};
|
||||
use rustpython_doc::DB;
|
||||
use std::{collections::HashSet, str::FromStr};
|
||||
use syn::{Attribute, Ident, Item, Result, parse_quote, spanned::Spanned};
|
||||
use syn_ext::ext::*;
|
||||
@@ -100,13 +101,7 @@ pub fn impl_pymodule(attr: PunctuatedNestedMeta, module_item: Item) -> Result<To
|
||||
let module_name = context.name.as_str();
|
||||
let function_items = context.function_items.validate()?;
|
||||
let attribute_items = context.attribute_items.validate()?;
|
||||
let doc = doc.or_else(|| {
|
||||
crate::doc::Database::shared()
|
||||
.try_path(module_name)
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(str::to_owned)
|
||||
});
|
||||
let doc = doc.or_else(|| DB.get(module_name).copied().map(str::to_owned));
|
||||
let doc = if let Some(doc) = doc {
|
||||
quote!(Some(#doc))
|
||||
} else {
|
||||
@@ -463,11 +458,10 @@ impl ModuleItem for FunctionItem {
|
||||
let sig_doc = text_signature(func.sig(), &py_name);
|
||||
|
||||
let module = args.module_name();
|
||||
// TODO: doc must exist at least one of code or CPython
|
||||
let doc = args.attrs.doc().or_else(|| {
|
||||
crate::doc::Database::shared()
|
||||
.try_module_item(module, &py_name)
|
||||
.ok() // TODO: doc must exist at least one of code or CPython
|
||||
.flatten()
|
||||
DB.get(&format!("{module}.{py_name}"))
|
||||
.copied()
|
||||
.map(str::to_owned)
|
||||
});
|
||||
let doc = if let Some(doc) = doc {
|
||||
|
||||
Reference in new issue
Block a user