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

Try sphinx-pyscript #23

Draft
wants to merge 28 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9e5e801
try sphinx pyscript
chrizzFTD Sep 7, 2024
32ac61c
adding a naming example
chrizzFTD Sep 7, 2024
c25a78b
adding naming as packages in py-config
chrizzFTD Sep 7, 2024
9b38cb2
adding explicit config for naming package
chrizzFTD Sep 7, 2024
415d41e
do double quotes
chrizzFTD Sep 7, 2024
e22bd68
explicit relpath
chrizzFTD Sep 7, 2024
16971a4
config as json
chrizzFTD Sep 7, 2024
d6a3f30
remove config
chrizzFTD Sep 7, 2024
6a6e5a1
remove micropython
chrizzFTD Sep 7, 2024
d4e81e2
try out fork with new pyscript
chrizzFTD Sep 7, 2024
4516a72
Revert "try out fork with new pyscript"
chrizzFTD Sep 7, 2024
b901be3
Revert "Revert "try out fork with new pyscript""
chrizzFTD Sep 8, 2024
ab3981b
lock sphinx 7
chrizzFTD Sep 8, 2024
b6572af
package not found, try docs example
chrizzFTD Sep 8, 2024
6287a4b
add matplotlib
chrizzFTD Sep 8, 2024
66b4947
adding pyscript.toml config again
chrizzFTD Sep 8, 2024
8065a23
code snippet readability
chrizzFTD Sep 8, 2024
9b4339d
no shared env
chrizzFTD Sep 8, 2024
5d2ad44
no need for packages in pyconfig
chrizzFTD Sep 8, 2024
502df3a
trying out adding repl in names overview
chrizzFTD Sep 8, 2024
42d63c7
emworker
chrizzFTD Sep 10, 2024
1938ff6
debug
chrizzFTD Sep 10, 2024
5ced74f
Revert "debug"
chrizzFTD Sep 10, 2024
f008975
play round with usd js, draft works with alab usdz
chrizzFTD Sep 10, 2024
ff2f3ee
wasm binary
chrizzFTD Sep 10, 2024
fb793db
lab asset
chrizzFTD Sep 10, 2024
a6ef7ac
lighter print
chrizzFTD Nov 3, 2024
39716f2
remove tests
chrizzFTD Nov 3, 2024
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
178 changes: 80 additions & 98 deletions docs/source/Overview.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.. py-config::

splashscreen:
enabled: false

Overview
========

Expand All @@ -20,107 +25,84 @@ Usage
Inherit from the class to use and assign a class attribute `config` as a
mapping of {field_name: regex_pattern} to use.

Name::

>>> from naming import Name
>>> class BasicName(Name):
... config = dict(base=r'\w+')
...
>>> n = BasicName()
>>> n.get() # no name has been set on the object, convention is solved with {missing} fields
'{base}'
>>> n.values
{}
>>> n.name = 'hello_world'
>>> n
Name("hello_world")
>>> str(n) # cast to string
'hello_world'
>>> n.values
{'base': 'hello_world'}
>>> # modify name and get values from field names
>>> n.base = 'through_field_name'
>>> n.values
{'base': 'through_field_name'}
>>> n.base
'through_field_name'

Pipe::

>>> from naming import Pipe
>>> class BasicPipe(Pipe):
... config = dict(base=r'\w+')
...
>>> p = BasicPipe()
>>> p.get()
'{base}.{pipe}'
>>> p.get(version=10)
'{base}.10'
>>> p.get(output='data')
'{base}.data.{version}'
>>> p.get(output='cache', version=7, index=24)
'{base}.cache.7.24'
>>> p = BasicPipe('my_wip_data.1')
>>> p.version
'1'
>>> p.values
{'base': 'my_wip_data', 'pipe': '.1', 'version': '1'}
>>> p.get(output='exchange') # returns a new string
'my_wip_data.exchange.1'
>>> p.name
'my_wip_data.1'
>>> p.output = 'exchange' # mutates the object
>>> p.name
'my_wip_data.exchange.1'
>>> p.index = 101
>>> p.version = 7
>>> p.name
'my_wip_data.exchange.7.101'
>>> p.values
{'base': 'my_wip_data', 'pipe': '.exchange.7.101', 'output': 'exchange', 'version': '7', 'index': '101'}

File::
**Name**

>>> from naming import File
>>> class BasicFile(File):
... config = dict(base=r'\w+')
...
>>> f = BasicFile()
>>> f.get()
'{basse}.{suffix}'
>>> f.get(suffix='png')
'{base}.png'
>>> f = BasicFile('hello.world')
>>> f.values
{'base': 'hello', 'suffix': 'world'}
>>> f.suffix
'world'
>>> f.suffix = 'abc'
>>> f.name
'hello.abc'
>>> f.path
WindowsPath('hello.abc')

PipeFile::
.. py-editor::
:config: pyscript.toml

from naming import Name
class BasicName(Name):
config = dict(base=r'\w+')

n = BasicName()
print(f"{n.get()=}") # no name has been set on the object, convention is solved with {missing} fields
print(f"{n.values=}")

n.name = 'hello_world'
print(f"{n=!r}")
print(f"{str(n)=}") # cast to string

# modify name and get values from field names
n.base = 'through_field_name'
print(f"{n.values=}")
print(f"{n.base=}")


**Pipe**

.. py-editor::
:config: pyscript.toml

from naming import Pipe
class BasicPipe(Pipe):
config = dict(base=r'\w+')

p = BasicPipe()
print(f"{p.get()=}")
print(f"{p.get(version=10)=}")
print(f"{p.get(output='cache', version=7, index=24)=}")

p = BasicPipe('my_wip_data.1')
print(f"{p.values=}")
p.output = 'exchange' # mutates the object
p.index = 101
p.version = 7
print(f"{p.name=}")
print(f"{p.values=}")

**File**

.. py-editor::
:config: pyscript.toml

from naming import File
class BasicFile(File):
config = dict(base=r'\w+')

f = BasicFile()
print(f"{f.get()=}")
print(f"{f.get(suffix='png')=}")

f = BasicFile('hello.world')
print(f"{f.values=}")
f.suffix = 'abc'
print(f"{f.path=}")

**PipeFile**

.. py-editor::
:config: pyscript.toml

from naming import PipeFile
class BasicPipeFile(PipeFile):
config = dict(base=r'\w+')

p = BasicPipeFile('wipfile.7.ext')
print(f"{p.values=}")
for idx in range(10):
print(p.get(index=idx, output='render'))

>>> from naming import PipeFile
>>> class BasicPipeFile(PipeFile):
... config = dict(base=r'\w+')
...
>>> p = BasicPipeFile('wipfile.7.ext')
>>> p.values
{'base': 'wipfile', 'pipe': '.7', 'version': '7', 'suffix': 'ext'}
>>> [p.get(index=x, output='render') for x in range(10)]
['wipfile.render.7.0.ext',
'wipfile.render.7.1.ext',
'wipfile.render.7.2.ext',
'wipfile.render.7.3.ext',
'wipfile.render.7.4.ext',
'wipfile.render.7.5.ext',
'wipfile.render.7.6.ext',
'wipfile.render.7.7.ext',
'wipfile.render.7.8.ext',
'wipfile.render.7.9.ext']

.. topic:: Extending Names

Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
'sphinx.ext.viewcode',
'sphinx_autodoc_typehints',
'sphinx_copybutton',
'sphinx_pyscript',
'sphinx_togglebutton',
'sphinx_toggleprompt',
]
Expand Down
29 changes: 29 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,38 @@
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

.. py-config::

splashscreen:
enabled: false

.. include:: ../../README.md
:parser: myst_parser.sphinx_

.. py-editor::
:config: pyscript.toml

# definition
import naming
class NameFileConvention(naming.Name, naming.File):
config = dict(first=r'\w+', last=r'\w+', number=r'\d+')

# inspection
name = NameFileConvention('john doe 07.jpg')
print(name.last)
print(name.number)

# modification
print(name.get(first='jane', number=99)) # returns new name string
name.last = 'connor' # mutates current name
print(name)

# validation
try:
name.number = 'not_a_number'
except ValueError as exc:
print(f"An error occurred: {exc}")

.. toctree::
:maxdepth: 2
:caption: Contents:
Expand Down
1 change: 1 addition & 0 deletions docs/source/pyscript.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages = ["naming"]
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ packages = find:
# docs dependencies install:
# conda install --channel conda-forge pygraphviz
# python -m pip install sphinx myst-parser sphinx-toggleprompt sphinx-copybutton sphinx-togglebutton sphinx-hoverxref sphinx_autodoc_typehints sphinx_rtd_theme
docs = sphinx; myst-parser; sphinx-toggleprompt; sphinx-copybutton; sphinx-togglebutton; sphinx-hoverxref; sphinx_autodoc_typehints; sphinx_rtd_theme
docs = sphinx==7.*; myst-parser; sphinx-toggleprompt; sphinx-copybutton; sphinx-togglebutton; sphinx-hoverxref; sphinx_autodoc_typehints; sphinx_rtd_theme; sphinx-pyscript @ git+https://github.com/chrizzFTD/sphinx-pyscript.git@pyscript-rtfd
Loading