Skip to content

Commit

Permalink
Update documentation on imports. Related to issue #2257.
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreQuentel committed Dec 3, 2023
1 parent 75eb387 commit 5383e2d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 8 additions & 4 deletions www/doc/en/import.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ import re
To import modules or packages, Brython uses the same mechanism as CPython : to
resolve "import X", the program looks for a file in several places :

- a module __X__ in the standard distribution
- a file __X.py__ in the root directory
- a file __\_\_init\_\_.py__ in directory __X__
- a module __X__ in the standard library
- a file __X.py__ in the script directory
- a file __\_\_init\_\_.py__ in the subdirectory __X__ of the script directory
- a file __X.py__ in the directory __site-packages__ of the standard
library
- a file __\_\_init.py\_\___ in the directory __site-packages/X__ of the
standard library

Since the browser has no direct access to the file system, looking for a file
must be done by an Ajax call, which returns an error message if there is no
Expand Down Expand Up @@ -93,7 +97,7 @@ brython-cli make_modules
Note that this program parses the Brython code in all the scripts, modules
and HTML pages of the directory and its sub-directories. The CPython version
used must be compliant with this Brython code : for instance if there are
`match / case` in the Brython code, CPython 3.10+ is required, otherwise you
`match / case` in the Brython code, CPython 3.10+ is required, otherwise you
would get syntax errors.

You can then replace all the occurrences of
Expand Down
10 changes: 7 additions & 3 deletions www/doc/fr/import.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ plusieurs emplacements :

- un module __X__ dans la bibliothèque standard
- un fichier __X.py__ dans le répertoire courant
- un fichier __\_\_init\_\_.py__ dans le répertoire X

- un fichier __\_\_init\_\_.py__ dans le sous-répertoire __X__ du répertoire
courant
- un fichier __X.py__ dans le répertoire __site-packages__ de la bibliothèque
standard
- un fichier __\_\_init.py\_\___ dans le répertoire __site-packages/X__ de la
bibliothèque standard

En outre, si une page HTML comporte plusieurs scripts Brython, ceux qui sont
déjà exécutés peuvent être importés par leur `id`:
Expand Down Expand Up @@ -102,7 +106,7 @@ A noter que ce programme analyse le code Brython contenu dans tous les scripts,
modules et pages HTML qui se trouvent dans le répertoire et ses
sous-répertoires. La version de CPython utilisée doit donc être compatible
avec le code Brython : par exemple si ce code inclut des `match / case`, il
faut au minimum CPython 3.10, sinon le programme détectera des erreurs de
faut au minimum CPython 3.10, sinon le programme détectera des erreurs de
syntaxe.

Vous pouvez ensuite remplacer toutes les occurrences de
Expand Down

0 comments on commit 5383e2d

Please sign in to comment.