Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanarijit committed Nov 22, 2023
1 parent 28112ed commit 480428f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
# For example, pypy2 and pypy3
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

env:
OS: ${{ matrix.os }}
Expand Down
44 changes: 20 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
expandvars
==========
# expandvars

Expand system variables Unix style

[![PyPI version](https://img.shields.io/pypi/v/expandvars.svg)](https://pypi.org/project/expandvars)
[![codecov](https://codecov.io/gh/sayanarijit/expandvars/branch/master/graph/badge.svg)](https://codecov.io/gh/sayanarijit/expandvars)

## Inspiration

Inspiration
-----------
This module is inspired by [GNU bash's variable expansion features](https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html). It can be used as an alternative to Python's [os.path.expandvars](https://docs.python.org/3/library/os.path.html#os.path.expandvars) function.

A good use case is reading config files with the flexibility of reading values from environment variables using advanced features like returning a default value if some variable is not defined.
Expand All @@ -25,22 +24,21 @@ my_nested_variable = "${!NESTED}"
> NOTE: Although this module copies most of the common behaviours of bash,
> it doesn't follow bash strictly. For example, it doesn't work with arrays.

Installation
------------
## Installation

### Pip

```
pip install expandvars
```

### Conda

```
conda install -c conda-forge expandvars
```

Usage
-----
## Usage

```python
from expandvars import expandvars
Expand All @@ -49,14 +47,11 @@ print(expandvars("$PATH:${HOME:?}/bin:${SOME_UNDEFINED_PATH:-/default/path}"))
# /bin:/sbin:/usr/bin:/usr/sbin:/home/you/bin:/default/path
```

## Examples

Examples
--------
For now, [refer to the test cases](https://github.com/sayanarijit/expandvars/blob/master/tests) to see how it behaves.


TIPs
----
## TIPs

### nounset=True

Expand Down Expand Up @@ -95,28 +90,29 @@ print(expand("%PATH:$HOME/bin:%{SOME_UNDEFINED_PATH:-/default/path}", environ={"
# /example:$HOME/bin:/default/path
```

Contributing
------------
To contribute, setup environment following way:
## Contributing

First you need to [install poetry](https://python-poetry.org/docs/#installation).
To contribute, setup environment following way:

Then

```bash
# Clone repo
git clone https://github.com/sayanarijit/expandvars && cd expandvars

# Install poetry dependencies
poetry install
# Setup virtualenv
python -m venv .venv
source ./.venv/bin/activate

# Install as editable including test dependencies
pip install -e ".[tests]"
```

- Follow [general git guidelines](https://git-scm.com/book/en/v2/Distributed-Git-Contributing-to-a-Project).
- Keep it simple. Run `poetry run black` to auto format the code.
- Test your changes locally by running `poetry run pytest` (pass `--cov --cov-report html` for browsable coverage report).
- Keep it simple. Run `black .` to auto format the code.
- Test your changes locally by running `pytest` (pass `--cov --cov-report html` for browsable coverage report).
- If you are familiar with [tox](https://tox.readthedocs.io), you may want to use it for testing in different python versions.

Alternatives
------------
## Alternatives

- [environs](https://github.com/sloria/environs) - simplified environment variable parsing.
2 changes: 0 additions & 2 deletions poetry.toml

This file was deleted.

7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
dynamic = ["version"]
name = 'expandvars'
version = '0.12.0'
description = 'Expand system variables Unix style'
keywords = [
'expand',
Expand Down Expand Up @@ -37,11 +37,14 @@ requires-python = ">=3"
"Homepage" = "https://github.com/sayanarijit/expandvars"

[project.optional-dependencies]
tests = ['tox', 'pytest', 'pytest-cov', 'toml']
tests = ['tox', 'pytest', 'pytest-cov', 'black']

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.version]
path = "expandvars.py"

[tool.pytest]
addopts = '--cov --cov-report=html --cov-fail-under=100'
8 changes: 0 additions & 8 deletions tests/test_expandvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@

import expandvars

def test_version():
import toml
pyproject = toml.load("pyproject.toml")
poetry_version = pyproject["project"]["version"]
assert expandvars.__version__ == f"v{poetry_version}"


@patch.dict(env, {}, clear=True)
def test_expandvars_constant():
Expand Down Expand Up @@ -355,5 +349,3 @@ def test_expand_var_symbol(var_symbol):
)
== "test,$HOME"
)


7 changes: 4 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[tox]
envlist = py36,py37,py38,py39,py310,py311
envlist = py36,py37,py38,py39,py310,py311,py312

[testenv]
extras = tests
whitelist_externals =
black
pytest
commands =
poetry run black --diff .
poetry run pytest --cov --cov-report=html --cov-fail-under=100
black --diff .
pytest --cov --cov-report=html --cov-fail-under=100

0 comments on commit 480428f

Please sign in to comment.