Skip to content

Commit ce8bc62

Browse files
lwasserZeitsperre
andcommitted
Fix: edits from Trevor @Zeitsperre
Co-authored-by: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com>
1 parent ce25857 commit ce8bc62

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

tutorials/1-installable-code.md

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,15 @@ Notice a few things about the above layout:
9494

9595
1. Your package code lives within a `src/packagename` directory. We suggest that you use `src` (short for **source code**) directory as it [ensures that you are running tests on the installed version of your code](https://www.pyopensci.org/python-package-guide/package-structure-code/python-package-structure.html#the-src-layout-and-testing).
9696
1. Within the `src` directory you have a package directory called `pyospackage`. Use the name of your package for that directory name. This will be the name for importing your package in Python code once installed.
97-
1. In your package directory, you have an `__init__.py` file and all of your Python modules. You will learn more about the __init__.py file below.
97+
1. In your package directory, you have an `__init__.py` file and all of your Python modules. You will learn more about the `__init__.py` file below.
9898
1. The `pyproject.toml` file lives at the root directory of your package.
9999
1. The name of the root directory for the package is **pyospackage** which is the name of the package. This is not a requirement but you will often see that the GitHub / GitLab repo and the root directory name are the same as the package name.
100100

101101
### What is an `__init__.py` file?
102102

103103
The `__init__.py` file tells Python that a directory
104104
should be treated as a Python package. As such, a directory with an `__init__.py` file can be imported
105-
directly into Python. The __init__.py file does not need
106-
to contain any code in order for Python to recognize it; it can be empty.
105+
directly into Python. The `__init__.py` file does not need to contain any code in order for Python to recognize it; it can be empty.
107106

108107
For example, following the file structure example above which has an `__init__.py` file within it, you can run:
109108

@@ -146,18 +145,16 @@ Neither 'setup.py' nor 'pyproject.toml' found.
146145

147146
## Time to create your Python package!
148147

149-
Now that you understand the basics of the Python package directory
150-
structure, and associated key files (`__init__.py` and `pyproject.toml`),
151-
it's time to create your Python package! Below you will create a directory
152-
structure similar to the structure described above.
148+
Now that you understand the basics of the Python package directory structure, and associated key files (`__init__.py` and `pyproject.toml`), it's time to create your Python package!
149+
Below you will create a directory structure similar to the structure described above.
153150

154151
If you don’t wish to create each of the files and directories below, you
155152
can always [fork and clone and customize the pyOpenSci example package.](https://github.com/pyOpenSci/pyosPackage)
156153

157154
## Step 1: Set Up the Package Directory Structure
158155

159-
Below you create the basic directory structure required
160-
for your Python package. Note that there are instructions for creating the files and directories using shell. However you can also create files and directories in your preferred file directory tool (e.g. Finder on MAC or File Explorer on Windows or even a tool such as VS Code or Spyder) if you wish.
156+
Below you create the basic directory structure required for your Python package.
157+
Note that there are instructions for creating the files and directories using shell. However you can also create files and directories in your preferred file directory tool (e.g. Finder on macOS or File Explorer on Windows or even a tool such as VS Code or Spyder) if you wish.
161158

162159
### Create your package's project directory structure
163160
* Create a new project directory for your package. Choose a name for your package, preferably in lowercase and without spaces. For this tutorial we'll use `pyospackage`.
@@ -203,21 +200,17 @@ pyospackage/ # This is your project directory
203200

204201
## Step 2: Add code to your package
205202

206-
Within the `pyospackage` subdirectory, add 1 or more Python modules
207-
(.py files) containing the code that you want your package to access and run.
208-
If you don't have code already and are just learning how to
209-
create a Python
210-
package, then create an empty `add_numbers.py` file.
203+
Within the `pyospackage` subdirectory, add one (1) or more Python modules (.py files) containing the code that you want your package to access and run.
204+
If you don't have code already and are just learning how to create a Python package, then create an empty `add_numbers.py` file.
211205

212206
:::{admonition} Python modules and the `__init__.py` file
213207
:class: tip
214208

215209
When you see the word module, we are referring to a `.py` file containing Python
216210
code.
217211

218-
The `__init__.py` allows Python to recognize that a directory contains at least one
219-
module that may be imported and used in your code. A package can have multiple
220-
modules.
212+
The `__init__.py` allows Python to recognize that a directory contains at least one (1) module that may be imported and used in your code.
213+
A package can have multiple modules.
221214

222215
[Learn more about Python packages and modules in the Python documentation.](https://docs.python.org/3/tutorial/modules.html#packages )
223216

@@ -238,12 +231,12 @@ pyospackage/
238231

239232
If you are following along and making a Python package from scratch then you can add the code below to your `add_numbers.py` module. The function below adds two integers together and returns the result. Notice that the code below has a few features that we will review in future tutorials:
240233

241-
1. It has a [numpy-style docstring ](https://www.pyopensci.org/python-package-guide/documentation/write-user-documentation/document-your-code-api-docstrings.html#three-python-docstring-formats-and-why-we-like-numpy-style)
234+
1. It has a [numpy-style docstring](https://www.pyopensci.org/python-package-guide/documentation/write-user-documentation/document-your-code-api-docstrings.html#three-python-docstring-formats-and-why-we-like-numpy-style)
242235
2. It uses [typing](https://www.pyopensci.org/python-package-guide/documentation/write-user-documentation/document-your-code-api-docstrings.html#adding-type-hints-to-your-docstrings)
243236

244-
If you aren’t familiar with docstrings or typing yet, that is ok. We will get
245-
to it later in our tutorial series. Or, you can review the pyOpenSci [packaging guide](https://www.pyopensci.org/python-package-guide/documentation/write-user-documentation/document-your-code-api-docstrings.html)
246-
for an overview.
237+
Python can support many different docstrings formats depending on the documentation build system you wish to use. The most popular supported formats for documenting Python objects are [NumPy Style Docstring](https://numpydoc.readthedocs.io/en/latest/format.html), [Google Style Docstring](https://google.github.io/styleguide/pyguide.html), [ReStructuredText Style Docstring](https://peps.python.org/pep-0287/), and the [Epytext Style Docstrings](https://epydoc.sourceforge.net/epytext.html). **pyOpensci recommends using the NumPy Docstring convention.**
238+
239+
If you aren’t familiar with docstrings or typing yet, that is ok. We will get to it later in our tutorial series. Or, you can review the pyOpenSci [packaging guide](https://www.pyopensci.org/python-package-guide/documentation/write-user-documentation/document-your-code-api-docstrings.html) for an overview.
247240

248241
```python
249242
def add_num(a: int, b: int) -> int:
@@ -284,9 +277,8 @@ are welcome to copy the file we have in our [example pyospackage GitHub reposito
284277

285278
`[this-is-a-table]`.
286279

287-
Tables can contain variables within them defined by an variable name and
288-
an `=` sign. For
289-
instance, a `build-system` table most often holds 2 variables:
280+
Tables can contain variables within them defined by an variable name and an `=` sign.
281+
For instance, a `build-system` table most often holds two (2) variables:
290282

291283
1. `requires = `, which tells a build tool what tools it needs to install prior to building your package. In this case
292284
[hatchling](https://pypi.org/project/hatchling/)

0 commit comments

Comments
 (0)