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

docs: refresh ZODB wiki tutorial #3751

Merged
merged 9 commits into from
Feb 8, 2024
Merged
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
8 changes: 4 additions & 4 deletions docs/tutorials/wiki/authorization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ Add dependencies
~~~~~~~~~~~~~~~~

Just like in :ref:`wiki_defining_views`, we need a new dependency.
We need to add the `bcrypt <https://pypi.org/project/bcrypt/>`_ package to our tutorial package's ``setup.py`` file by assigning this dependency to the ``requires`` parameter in the ``setup()`` function.
We need to add the `bcrypt <https://pypi.org/project/bcrypt/>`_ package to our tutorial package's ``pyproject.toml`` file by assigning this dependency to the ``dependencies`` stanza.

Open ``setup.py`` and edit it to look like the following:
Open ``pyproject.toml`` and edit it to look like the following:

.. literalinclude:: src/authorization/setup.py
:lines: 11-30
.. literalinclude:: src/authorization/pyproject.toml
:lines: 20-33
:lineno-match:
:emphasize-lines: 2
:language: python
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/wiki/basiclayout.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Even if empty, this marks a directory as a Python package.
We use ``__init__.py`` both as a marker, indicating the directory in which it is contained is a package, and to contain application configuration code.

When you run the application using the ``pserve`` command using the ``development.ini`` generated configuration file, the application configuration points at a :term:`Setuptools` :term:`entry point` described as ``egg:tutorial``.
In our application, because the application's ``setup.py`` file says so, this entry point happens to be the ``main`` function within the file named ``__init__.py``.
In our application, because the application's ``pyproject.toml`` file says so, this entry point happens to be the ``main`` function within the file named ``__init__.py``.

Open ``tutorial/__init__.py``.
It should already contain the following:
Expand Down
14 changes: 7 additions & 7 deletions docs/tutorials/wiki/definingviews.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ We will define several :term:`view callable` functions, then wire them into :app
See also the chapter :ref:`resources_chapter` for a complete description of resources and the chapter :ref:`traversal_chapter` for the technical details of how traversal works in Pyramid.


Declaring Dependencies in Our ``setup.py`` File
===============================================
Declaring Dependencies in Our ``pyproject.toml`` File
=====================================================

The view code in our application will depend on a package which is not a dependency of the original "tutorial" application.
The original "tutorial" application was generated by the cookiecutter.
It does not know about our custom application requirements.

We need to add a dependency on the ``docutils`` package to our ``tutorial`` package's ``setup.py`` file by assigning this dependency to the ``requires`` parameter in the ``setup()`` function.
We need to add a dependency on the ``docutils`` package to our ``tutorial`` package's ``pyproject.toml`` file by assigning this dependency to its ``dependencies`` stanza.

Open ``setup.py`` and edit it to look like the following:
Open ``pyproject.toml`` and edit it to look like the following:

.. literalinclude:: src/views/setup.py
:lines: 11-29
.. literalinclude:: src/views/pyproject.toml
:lines: 20-32
:lineno-match:
:emphasize-lines: 2
:language: python
Expand All @@ -54,7 +54,7 @@ Running ``pip install -e .``

Since a new software dependency was added, you need to run ``pip install -e .`` again inside the root of the ``tutorial`` package to obtain and register the newly added dependency distribution.

Make sure your current working directory is the root of the project (the directory in which ``setup.py`` lives) and execute the following command.
Make sure your current working directory is the root of the project (the directory in which ``pyproject.toml`` lives) and execute the following command.

On Unix:

Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/wiki/design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Overall

We choose to use :term:`reStructuredText` markup in the wiki text.
Conversion from reStructuredText to HTML is provided by the widely used ``docutils`` Python module.
We will add this module in the dependency list on the project ``setup.py`` file.
We will add this module in the dependency list on the project's ``pyproject.toml`` file.


Models
Expand Down
43 changes: 30 additions & 13 deletions docs/tutorials/wiki/distributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,50 @@
Distributing Your Application
=============================

Once your application works properly, you can create a :term:`distribution` from it by using the ``setup.py sdist`` command.
The following commands assume your current working directory contains the ``tutorial`` package and the ``setup.py`` file.
.. note::

This is an optional step.
It is not required nor expected that every application is built to be distributed to a package index.
However, even when building personal projects, defining it as a distributable artifact can provide many advantages when it comes to optimizing your build for a Docker image or other "production" hardened environments that should not mirror your local development environment exactly.

Once your application works properly, you can create a "sdist" or "wheel" from
it by using a PEP517-compliant client tool. The following commands assume your
current working directory contains the ``tutorial`` package and the
``pyproject.toml`` file.

On Unix:

.. code-block:: bash

$VENV/bin/python setup.py sdist
$VENV/bin/pip install build
$VENV/bin/python -m build

On Windows:

.. code-block:: doscon

%VENV%\Scripts\python setup.py sdist
%VENV%\Scripts\pip install build
%VENV%\Scripts\python -m build

The output of such a command will be something like:

.. code-block:: text

running sdist
# more output
creating dist
Creating tar archive
removing 'tutorial-0.0' (and everything under it)
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools)
* Getting build dependencies for sdist...
...
removing build/bdist.linux-x86_64/wheel
Successfully built tutorial-0.0.tar.gz and tutorial-0.0-py3-none-any.whl

This command creates a subdirectory named ``dist``.
Inside that is a tarball named ``tutorial-0.0.tar.gz``, which is the :term:`distribution` of your application.
You can send this file to your friends to show them your cool new application.
They should be able to install it by pointing the ``pip install`` command directly at it.
Or you can upload it to `PyPI <https://pypi.org/>`_ and share it with the rest of the world, where it can be downloaded via ``pip install`` remotely like any other package people download from PyPI.
Inside that is a tarball named ``tutorial-0.0.tar.gz`` (the source :term:`distribution` of your application), as well ass ``tutorial-0.0-py3-none-any.whl`` (the binary :term:`distribution`).
You can send these files to your friends to show them your cool new application.
They should be able to install the app by pointing the ``pip install`` command directly at one of them.
These artifacts are also uploadable to `PyPI <https://pypi.org/>`_, or another package index, using a tool like ``twine``.

Note that the config files, such as ``production.ini`` are not part of the distribution.
These files are considered to be defined by the "user" of your application and not part of the application itself.
If you'd like to help a user out, consider defining a new CLI script similar to ``initialize_tutorial_db`` that can render a config file for them!

Please learn more about distributing an application from the `Python Packaging User Guide <https://packaging.python.org/en/latest/tutorials/packaging-projects/>`_.
29 changes: 19 additions & 10 deletions docs/tutorials/wiki/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,12 @@ The console will show ``pip`` checking for packages and installing missing packa

Successfully installed BTrees-4.7.2 Chameleon-3.8.1 Mako-1.1.3 MarkupSafe-1.1.1 PasteDeploy-2.1.1 Pygments-2.7.3 WebTest-2.0.35 ZConfig-3.5.0 ZEO-5.2.2 ZODB-5.6.0 attrs-20.3.0 beautifulsoup4-4.9.3 cffi-1.14.4 coverage-5.3.1 hupper-1.10.2 iniconfig-1.1.1 packaging-20.8 persistent-4.6.4 plaster-1.0 plaster-pastedeploy-0.7 pluggy-0.13.1 py-1.10.0 pycparser-2.20 pyparsing-2.4.7 pyramid-1.10.5 pyramid-chameleon-0.3 pyramid-debugtoolbar-4.9 pyramid-mako-1.1.0 pyramid-retry-2.1.1 pyramid-tm-2.4 pyramid-zodbconn-0.8.1 pytest-6.2.1 pytest-cov-2.10.1 repoze.lru-0.7 six-1.15.0 soupsieve-2.1 toml-0.10.2 transaction-3.0.1 translationstring-1.4 tutorial venusian-3.0.0 waitress-1.4.4 webob-1.8.6 zc.lockfile-2.0 zdaemon-4.3 zodbpickle-2.0.0 zodburi-2.4.0 zope.deprecation-4.4.0 zope.interface-5.2.0

Testing requirements are defined in our project's ``setup.py`` file, in the ``tests_require`` and ``extras_require`` stanzas.
Testing requirements are defined in our project's ``pyproject.toml`` file, in the ``project:optional-dependencies`` stanza:

.. literalinclude:: src/installation/setup.py
.. literalinclude:: src/installation/pyproject.toml
:language: python
:lineno-match:
:lines: 24-28

.. literalinclude:: src/installation/setup.py
:language: python
:lineno-match:
:lines: 48-50
:lines: 33-38


.. _running_tests:
Expand Down Expand Up @@ -295,10 +290,24 @@ Test and coverage cookiecutter defaults
---------------------------------------

The Pyramid cookiecutter includes configuration defaults for ``pytest`` and test coverage.
These configuration files are ``pytest.ini`` and ``.coveragerc``, located at the root of your package.
The configuration for ``pytest`` is in the ``pyroject.toml`` file in the ``tool.pytest.ini_options`` stanza.
Coverage is checked using the ``pytest--cov`` plugin, a wrapper around the `Coverage <https://coverage.readthedocs.io/en/latest/index.html>`_ tool.
Options affecting coverage are defined in the ``[tool.coverage.run]`` stanza of ``pyproject.toml``.

``pytest`` follows :ref:`conventions for Python test discovery <pytest:test discovery>`.
The configuration defaults from the cookiecutter tell ``pytest`` where to find the module on which we want to run tests and coverage.
The configuration defaults from the cookiecutter tell ``pytest`` where to find the module on which we want to run tests:

.. literalinclude:: src/installation/pyproject.toml
:language: python
:lineno-match:
:lines: 51-56

The ``tool.coverage.run`` stanza defines the code for which we want to collect and report coverage:

.. literalinclude:: src/installation/pyproject.toml
:language: python
:lineno-match:
:lines: 46-49

.. seealso:: See ``pytest``'s documentation for :ref:`pytest:usage` or invoke ``pytest -h`` to see its full set of options.

Expand Down
2 changes: 0 additions & 2 deletions docs/tutorials/wiki/src/authorization/.coveragerc

This file was deleted.

4 changes: 0 additions & 4 deletions docs/tutorials/wiki/src/authorization/CHANGES.txt

This file was deleted.

2 changes: 1 addition & 1 deletion docs/tutorials/wiki/src/authorization/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include *.txt *.ini *.cfg *.rst
include *.txt *.ini *.cfg *.md *.toml
recursive-include tutorial *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml *.jinja2
recursive-include tests *
recursive-exclude * __pycache__
Expand Down
40 changes: 40 additions & 0 deletions docs/tutorials/wiki/src/authorization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# tutorial

## Getting Started

- Change directory into your newly created project if not already there. Your
current directory should be the same as this `README.md` file and `pyproject.toml`.

```
cd tutorial
```

- Create a Python virtual environment, if not already created.

```
python3 -m venv env
```

- Upgrade packaging tools, if necessary.

```
env/bin/pip install --upgrade pip
```

- Install the project in editable mode with its testing requirements.

```
env/bin/pip install -e ".[testing]"
```

- Run your project's tests.

```
env/bin/pytest
```

- Run your project.

```
env/bin/pserve development.ini
```
30 changes: 0 additions & 30 deletions docs/tutorials/wiki/src/authorization/README.txt

This file was deleted.

58 changes: 58 additions & 0 deletions docs/tutorials/wiki/src/authorization/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
version = "0.0"
name = "tutorial"
authors = []
description = "tutorial"
readme = "README.md"
keywords = ["web", "pyramid", "pylons"]
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Framework :: Pyramid",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
]
requires-python = ">=3.8"
dependencies = [
"bcrypt",
"docutils",
"plaster_pastedeploy",
"pyramid",
"pyramid_chameleon",
"pyramid_debugtoolbar",
"waitress",
"pyramid_retry",
"pyramid_tm",
"pyramid_zodbconn",
"transaction",
"ZODB",
]

[project.optional-dependencies]
testing = [
"WebTest",
"pytest",
"pytest-cov",
]

[project.entry-points."paste.app_factory"]
main = "tutorial:main"

[tool.setuptools.packages.find]
exclude = ["tests"]

[tool.coverage.run]
source = [
"tutorial",
]

[tool.pytest.ini_options]
addopts = "--strict-markers"
testpaths = [
"tutorial",
"tests",
]
6 changes: 0 additions & 6 deletions docs/tutorials/wiki/src/authorization/pytest.ini

This file was deleted.

59 changes: 0 additions & 59 deletions docs/tutorials/wiki/src/authorization/setup.py

This file was deleted.

Loading