mirror of
https://github.com/Brandon-Rozek/website.git
synced 2024-11-09 10:40:34 -05:00
New blog posts
This commit is contained in:
parent
3b69b7e465
commit
9329d8a605
3 changed files with 101 additions and 0 deletions
36
content/blog/pyenvtox.md
Normal file
36
content/blog/pyenvtox.md
Normal file
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
title: "Pyenv and Tox"
|
||||
date: 2020-02-21T19:06:40-05:00
|
||||
draft: false
|
||||
tags: [ "python", "testing" ]
|
||||
---
|
||||
|
||||
Pyenv is great for managing multiple python installations and tox is great for creating virtual environments for testing. What if we can combine the two? For more detailed information visit [Frank-Mich's Blog](https://blog.frank-mich.com/recipe-testing-multiple-python-versions-with-pyenv-and-tox/).
|
||||
|
||||
First make sure [pyenv is installed](https://github.com/pyenv/pyenv-installer). In the directory with your `setup.py` tell `pyenv` which python versions you want to consider.
|
||||
```bash
|
||||
pyenv local 3.6.0 3.7.0 3.8.0
|
||||
```
|
||||
|
||||
Frank warns heavily not to specify multiple python versions with the same `major.minor` numbering. For example, `3.6.0` and `3.6.10` should not be included together.
|
||||
|
||||
Then install the `tox` package.
|
||||
```bash
|
||||
pip install tox
|
||||
```
|
||||
|
||||
I made the mistake of making a virtual environment and then installing tox. That gets rid of the python version information we specified before.
|
||||
|
||||
Now specify a `tox.ini` with a structure similar to below..
|
||||
```ini
|
||||
[tox]
|
||||
envlist =
|
||||
py36
|
||||
py37
|
||||
py38
|
||||
|
||||
[testenv]
|
||||
commands =
|
||||
python3 -m unittest discover tests
|
||||
```
|
||||
|
33
content/blog/pythonsetupdevelop.md
Normal file
33
content/blog/pythonsetupdevelop.md
Normal file
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
title: "Python setup.py develop"
|
||||
date: 2020-02-21T22:42:55-05:00
|
||||
draft: false
|
||||
tags: [ "python" ]
|
||||
---
|
||||
|
||||
I've found it to be incredibly helpful to emulate having a library installed on my system rather than depending on my local directory path to pick up my file edits. To do this in a python project where you've defined a `setup.py`, you can specify the command `develop`.
|
||||
|
||||
First uninstall whatever version of your `library` you have.
|
||||
```bash
|
||||
pip uninstall library
|
||||
```
|
||||
|
||||
Then in your folder with the `setup.py` run the following command
|
||||
```bash
|
||||
python setup.py develop
|
||||
```
|
||||
|
||||
This will then create a symlink from your site-packages directory to the directory in which your code lives.
|
||||
|
||||
Once you're ready to install it formally,
|
||||
```bash
|
||||
pip uninstall library
|
||||
pip install .
|
||||
```
|
||||
|
||||
Distribute it,
|
||||
```bash
|
||||
pip wheel .
|
||||
```
|
||||
|
||||
|
32
content/blog/tox.md
Normal file
32
content/blog/tox.md
Normal file
|
@ -0,0 +1,32 @@
|
|||
---
|
||||
title: "Tox"
|
||||
date: 2020-02-21T22:34:19-05:00
|
||||
draft: false
|
||||
tags: [ "python", "testing" ]
|
||||
---
|
||||
|
||||
[Tox](https://tox.readthedocs.io/en/latest/) is a great project where you can automate your testing using virtual environments.
|
||||
|
||||
First install tox
|
||||
```bash
|
||||
pip install tox
|
||||
```
|
||||
|
||||
I like to write my tests in Python's native [`unittest`](https://docs.python.org/3/library/unittest.html) format. Tests should be stored in a `tests` directory.
|
||||
|
||||
I then combine it with the `coverage` library to tell me how much of my code that my test cases cover. To quickly insert my personal opinion, I never aim for 100% test coverage since there's typically overhead in maintaining that.
|
||||
|
||||
This all gets described in a `tox.ini` file. This file should live in the same directory as your `setup.py`
|
||||
|
||||
```ini
|
||||
[tox]
|
||||
envlist =
|
||||
py38
|
||||
|
||||
[testenv]
|
||||
deps = coverage
|
||||
commands =
|
||||
coverage run --source=tests,library -m unittest discover tests
|
||||
coverage report -m
|
||||
```
|
||||
|
Loading…
Reference in a new issue