| 1 |
--- |
| 2 |
icon: lucide/hammer |
| 3 |
--- |
| 4 |
# Development |
| 5 |
|
| 6 |
## Project Layout |
| 7 |
|
| 8 |
There are a number of files for build, test, and continuous integration in the root of the project, but in general, the |
| 9 |
project is broken up like so. |
| 10 |
|
| 11 |
``` |
| 12 |
├── docs |
| 13 |
├── pymdownx |
| 14 |
├── requirements |
| 15 |
├── tests |
| 16 |
└── tools |
| 17 |
``` |
| 18 |
|
| 19 |
Directory | Description |
| 20 |
-------------- | ----------- |
| 21 |
`docs` | This contains the source files for the documentation. |
| 22 |
`pymdownx` | This contains the source code for all the extensions. |
| 23 |
`requirements` | This contains files with lists of dependencies required dependencies for continuous integration. |
| 24 |
`tests` | This contains the various tests that are run in order to ensure code health. |
| 25 |
`tools` | This contains various tools that are necessary during development. |
| 26 |
|
| 27 |
## Coding Standards |
| 28 |
|
| 29 |
When writing code, the code should roughly conform to PEP8 and PEP257 suggestions. The PyMdown Extensions project |
| 30 |
utilizes the Flake8 linter (with some additional plugins) to ensure code conforms (give or take some of the rules). |
| 31 |
When in doubt follow the formatting hints of existing code when adding or modifying files. existing files. Listed below |
| 32 |
are the modules used: |
| 33 |
|
| 34 |
- @PyCQA/flake8 |
| 35 |
- @PyCQA/flake8-docstrings |
| 36 |
- @PyCQA/pep8-naming |
| 37 |
- @ebeweber/flake8-mutable |
| 38 |
- @gforcada/flake8-builtins |
| 39 |
|
| 40 |
Flake8 can be run directly via the command line from the root of the project. |
| 41 |
|
| 42 |
``` |
| 43 |
flake8 |
| 44 |
``` |
| 45 |
|
| 46 |
## Building and Editing Documents |
| 47 |
|
| 48 |
Documents are in Markdown (with some additional syntax) and converted to HTML via Python Markdown and this |
| 49 |
extension bundle. If you would like to build and preview the documentation, you must have these packages installed: |
| 50 |
|
| 51 |
- @zensical/zensical: the document site generator. |
| 52 |
- @Python-Markdown/markdown: the Markdown parser. |
| 53 |
- @facelessuser/pymdown-extensions: this Python Markdown extension bundle. |
| 54 |
|
| 55 |
These can be installed via: |
| 56 |
|
| 57 |
``` |
| 58 |
pip install -r requirements/docs.txt |
| 59 |
``` |
| 60 |
|
| 61 |
In order to build and preview the documents, just run the command below from the root of the project and you should be |
| 62 |
able to view the documents at `localhost:8000` in your browser. After that, you should be able to update the documents |
| 63 |
and have your browser preview update live. |
| 64 |
|
| 65 |
``` |
| 66 |
python3 -m zensical serve -f zensical.yml |
| 67 |
``` |
| 68 |
|
| 69 |
## Editing Document Theme |
| 70 |
|
| 71 |
It isn't expected that people will need to mess with the theme, but if it is needed, a little additional work is |
| 72 |
required. The documents use [Zensical][zensical] with some additional local tweaks and additions. JavaScript additions |
| 73 |
are provided in `docs/src/js` and are in es2020 syntax and are converted to es5. Stylesheets are located at |
| 74 |
`docs/src/scss` and are written in SCSS, and are converted to CSS. All conversions are done in a `Node.js` environment. |
| 75 |
In order to get up and running, ensure you have a [`Node.js`](https://nodejs.org/en/) version >= 10. Then install the |
| 76 |
required modules with: |
| 77 |
|
| 78 |
``` |
| 79 |
npm install |
| 80 |
``` |
| 81 |
|
| 82 |
After that you can begin making changes. When ready, you can run the following commands to get a live preview while you |
| 83 |
make edits, lint your changes, or build the final output. |
| 84 |
|
| 85 |
Commands | Description |
| 86 |
------------------- | ----------- |
| 87 |
`npm run build` | Build the final output which will package, minimize, and revision the scripts and stylesheets. It will also update the `zensical.yml` file to point to the new revisioned files. |
| 88 |
`npm run lint` | Run just lint on the files. |
| 89 |
`npm run clean_all` | This will clean out the generated CSS and JavaScript files. It will also cleanup the generated Zensical's site. |
| 90 |
|
| 91 |
If you need to make changes to the `zenscial.yml` file, do not update the one in project root directly, but update the |
| 92 |
one in `docs/src`. The build environment copies the one in `docs/src` to the project root and injects the revisioned |
| 93 |
script name(s) and stylesheet name(s). |
| 94 |
|
| 95 |
## Spell Checking Documents |
| 96 |
|
| 97 |
During validation, we build the docs and run a spell checker on them. The spell checker uses @facelessuser/pyspelling |
| 98 |
and [Aspell][aspell]. As it can be trickier to run Aspell under Windows, it is not expected that everyone will install |
| 99 |
and run the spell checker locally. In order to perform the spell check, it is expected you are setup to build the |
| 100 |
documents, and that you have Aspell installed in the your system path. |
| 101 |
|
| 102 |
If you wish to run the spell checker locally, the recommended way is with Tox, which is covered in ["Running Validation |
| 103 |
With Tox"](#running-validation-with-tox). |
| 104 |
|
| 105 |
You can also run the spell checker by first installing the requirements (assuming a Linux system): |
| 106 |
|
| 107 |
``` |
| 108 |
pip install -r requirements/docs.txt |
| 109 |
sudo apt-get install aspell aspell-en |
| 110 |
``` |
| 111 |
|
| 112 |
Then build the docs: |
| 113 |
|
| 114 |
``` |
| 115 |
python3 -m zensical build-f zensical.yml --clean |
| 116 |
``` |
| 117 |
|
| 118 |
And then run the spell checker: |
| 119 |
|
| 120 |
``` |
| 121 |
pyspelling |
| 122 |
``` |
| 123 |
|
| 124 |
It should print out the files with the misspelled words if any are found. If you find it prints words that are not |
| 125 |
misspelled, you can add them in the dictionary which is found in `docs/src/dictionary`. |
| 126 |
|
| 127 |
## Validation Tests |
| 128 |
|
| 129 |
In order to preserve good code health, a test suite has been put together with pytest (@pytest-dev/pytest). There are |
| 130 |
currently two kinds of tests: syntax and targeted. To run these tests, you can use the following command: |
| 131 |
|
| 132 |
If you wish to run the tests locally, the recommended way is with Tox, which is covered in ["Running Validation With |
| 133 |
Tox"](#running-validation-with-tox). |
| 134 |
|
| 135 |
You can also run the tests by first installing the requirements: |
| 136 |
|
| 137 |
``` |
| 138 |
pip install -r requirements/project.txt |
| 139 |
pip install -r requirements/extra.txt |
| 140 |
pip install -r requirements/test.txt |
| 141 |
``` |
| 142 |
|
| 143 |
And then run the tests with: |
| 144 |
|
| 145 |
``` |
| 146 |
python run_tests.py |
| 147 |
``` |
| 148 |
|
| 149 |
### Syntax |
| 150 |
|
| 151 |
Syntax tests are essentially text files containing Markdown. They are found under `tests/extensions`. `test_syntax.py` |
| 152 |
scans all the files and converts the files to HTML with the extensions and options defined in |
| 153 |
`tests/extensions/tests.yml`. They are then compared to the current stored HTML output. If the two differ, the test |
| 154 |
fails. |
| 155 |
|
| 156 |
To run **only** these tests, from the root of the project run the following command: |
| 157 |
|
| 158 |
``` |
| 159 |
python run_tests.py --test-target syntax |
| 160 |
``` |
| 161 |
|
| 162 |
You could also run them directly with: |
| 163 |
|
| 164 |
``` |
| 165 |
py.test tests/test_syntax.py |
| 166 |
``` |
| 167 |
|
| 168 |
To run a specific syntax test: |
| 169 |
|
| 170 |
``` |
| 171 |
python run_tests.py --test-target syntax --file tests/extensions/arithmatex.txt |
| 172 |
``` |
| 173 |
|
| 174 |
To accept the differences in tests due to a change(s) you made, you can run the following command: |
| 175 |
|
| 176 |
``` |
| 177 |
python run_tests.py --update |
| 178 |
``` |
| 179 |
|
| 180 |
To update and accept the differences in a single test: |
| 181 |
|
| 182 |
``` |
| 183 |
python run_tests.py --update --file tests/extensions/arithmatex.txt |
| 184 |
``` |
| 185 |
|
| 186 |
### Targeted |
| 187 |
|
| 188 |
Targeted tests are unit tests that target specific areas in the code and exercises them to ensure proper functionality. |
| 189 |
These tests are found in `test_targeted.py`. |
| 190 |
|
| 191 |
You can run **only** these tests from the root of the project with: |
| 192 |
|
| 193 |
``` |
| 194 |
python run_tests.py --test-target targeted |
| 195 |
``` |
| 196 |
|
| 197 |
You could also run them directly with: |
| 198 |
|
| 199 |
``` |
| 200 |
py.test tests/test_targeted.py |
| 201 |
``` |
| 202 |
|
| 203 |
### Running Validation With Tox |
| 204 |
|
| 205 |
Tox (@tox-dev/tox) is a great way to run the validation tests, spelling checks, and linting in virtual environments so |
| 206 |
as not to mess with your current working environment. Tox will use the specified Python version for the given |
| 207 |
environment and create a virtual environment and install all the needed requirements (minus Aspell). You could also |
| 208 |
setup your own virtual environments with the Virtualenv module without Tox, and manually do the same. |
| 209 |
|
| 210 |
First, you need to have Tox installed: |
| 211 |
|
| 212 |
``` |
| 213 |
pip install tox |
| 214 |
``` |
| 215 |
|
| 216 |
By running Tox, it will walk through all the environments and create them (assuming you have all the python versions on |
| 217 |
your machine) and run the related tests. See `tox.ini` to learn more. |
| 218 |
|
| 219 |
``` |
| 220 |
tox |
| 221 |
``` |
| 222 |
|
| 223 |
If you don't have all the Python versions needed to test all the environments, those entries will fail. You can ignore |
| 224 |
those. Spelling will also fail if you don't have the correct version of Aspell. |
| 225 |
|
| 226 |
To target a specific environment to test, you use the `-e` option to select the environment of interest. To select |
| 227 |
lint: |
| 228 |
|
| 229 |
``` |
| 230 |
tox -e lint |
| 231 |
``` |
| 232 |
|
| 233 |
To select Python 3.7 unit tests (or other versions -- change accordingly): |
| 234 |
|
| 235 |
``` |
| 236 |
tox -e py37 |
| 237 |
``` |
| 238 |
|
| 239 |
To select spelling and document building: |
| 240 |
|
| 241 |
``` |
| 242 |
tox -e documents |
| 243 |
``` |
| 244 |
|
| 245 |
## Code Coverage |
| 246 |
|
| 247 |
When running the validation tests through Tox, it is setup to track code coverage via the Coverage |
| 248 |
(@bitbucket:ned/coveragepy) module. Coverage is run on each `pyxx` environment. If you've made changes to |
| 249 |
the code, you can clear the old coverage data: |
| 250 |
|
| 251 |
``` |
| 252 |
coverage erase |
| 253 |
``` |
| 254 |
|
| 255 |
Then run each unit test environment to and coverage will be calculated. All the data from each run is merged together. |
| 256 |
HTML is output for each file in `.tox/pyXX-unittests/tmp`. You can use these to see areas that are not |
| 257 |
covered/exercised yet with testing. |
| 258 |
|
| 259 |
You can checkout `tox.ini` to see how this is accomplished. |
| 260 |
|
| 261 |
## Generating Emoji Indexes |
| 262 |
|
| 263 |
The Emoji extension has emoji indexes generated from the source of Gemoji, EmojiOne, and Twemoji. Below is the process |
| 264 |
for auto-generating these indexes. In the case of Twemoji, it will also reference EmojiOne's short name index, so you |
| 265 |
may need to do both EmojiOne and Twemoji if the support is not satisfactory. |
| 266 |
|
| 267 |
1. Ensure you have Requests (@requests/requests) installed: `pip install requests`. |
| 268 |
2. Fork the repository and checkout to your machine. |
| 269 |
3. Navigate to the root of the project. |
| 270 |
4. Call the generator script: `python tools/gen_emoji.py --gemoji`, `python tools/gen_emoji.py --emojione`, or |
| 271 |
`python tools/gen_emoji.py --twemoji`. If you already have the latest tag locally, you can specify `--no-download`. |
| 272 |
It will prompt you to select a tag to download and/or use. Please pull the latest **official** tag. Please don't |
| 273 |
pull experimental tags. This should update the indexes. |
| 274 |
5. Then you want to update the tests. |
| 275 |
6. Force the tests to update via `python run_tests.py --update`. Make sure only the emoji tests get updated. |
| 276 |
|
| 277 |
Nothing is fool proof. If they make a breaking change to the files that the script parses, or the location of the files |
| 278 |
change, the auto-update tool may need to be updated itself (hopefully this would be a rare occurrence). If such a |
| 279 |
change does occur, and you are feeling brave, a pull request would be appreciated, but in time, they will be resolved |
| 280 |
regardless. |