Skip to content

Commit

Permalink
Merge pull request #78 from pedrocamargo/master
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldhawk authored Jul 18, 2024
2 parents e023e7b + 49cacab commit 3abf967
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 432 deletions.
71 changes: 52 additions & 19 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,69 @@
name: Tests

on: [push]
on: [pull_request]

jobs:
build:
linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set Python environment
uses: actions/setup-python@v5
with:
python-version: 3.11
architecture: x64

- name: Install dependencies
run: pip install -e .[dev]

- name: Linting
run: |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Check code format with Black
run: black --check us

testing:
needs: linting
runs-on: ubuntu-latest
strategy:
max-parallel: 4
max-parallel: 6
matrix:
python-version: [3.8, 3.9, "3.10", 3.11, 3.12]

python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install pipenv
uses: dschep/install-pipenv-action@v1
- name: Install dependencies
run: |
pipenv install --dev --skip-lock --python `which python`
- name: Linting and formatting
if: ${{ matrix.python-version == '3.11' }}
run: |
# stop the build if there are Python syntax errors or undefined names
pipenv run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
pipenv run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# check formatting
pipenv run black --check us
pip install -e .[dev]
- name: Test with pytest
run: |
pipenv run pytest
pytest .
building:
needs: linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set Python environment
uses: actions/setup-python@v5
with:
python-version: 3.11
architecture: x64

- name: Install dependencies
run: |
pip install setuptools build wheel
- name: Builds package
run: |
python -m build . -w -n
- uses: actions/upload-artifact@v4
with:
name: wheels
path: ./dist/*.whl
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.env

# Compilation and caching
build/
dist/
.cache/
.mypy_cache/
.pytest_cache/
Expand Down
19 changes: 0 additions & 19 deletions Pipfile

This file was deleted.

352 changes: 0 additions & 352 deletions Pipfile.lock

This file was deleted.

4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ Running Tests
GitHub Actions are set up to automatically run unit tests against any new
commits to the repo. To run these tests yourself: ::

pipenv install --dev
pipenv run pytest
pip install -e .[dev]
pytest .


Changelog
Expand Down
35 changes: 35 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[build-system]
requires = ["setuptools"]

[project]
name = "us"
description = "US state meta information and other fun stuff"
readme = "README.rst"
urls.Homepage = "https://github.com/unitedstates/python-us/"
urls."Issue tracker" = "https://github.com/unitedstates/python-us/issues"
requires-python = ">=3.7"
dynamic = ["version"]
authors = [{ name = "Jeremy Carbaugh", email = "[email protected]" }]
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"
]
license = { file = "LICENSE"}

dependencies = ['jellyfish']

[project.optional-dependencies]
dev = ['flake8', 'black', 'pytest', 'pytz']


[tool.setuptools.dynamic]
version = { attr = "us.version.__version__" }

[tool.black]
line-length = 120
target-version = ['py39', 'py310', 'py311', 'py312']
include = '\.pyi?$'
27 changes: 0 additions & 27 deletions setup.py

This file was deleted.

1 change: 1 addition & 0 deletions us/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
OBSOLETE, # noqa
) # noqa
from .unitedstatesofamerica import * # noqa
from .version import __version__ as version
9 changes: 2 additions & 7 deletions us/cli/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ def main():
import argparse

parser = argparse.ArgumentParser(description="Lookup state information")
parser.add_argument(
"query", metavar="QUERY", nargs=1, help="name, abbreviation, or FIPS code"
)
parser.add_argument("query", metavar="QUERY", nargs=1, help="name, abbreviation, or FIPS code")

args = parser.parse_args()

Expand All @@ -23,10 +21,7 @@ def main():
region = "territory" if data.pop("is_territory") else "state"

sys.stdout.write("\n")
sys.stdout.write(
"*** The great %s of %s (%s) ***\n\n"
% (region, data.pop("name"), data.pop("abbr"))
)
sys.stdout.write("*** The great %s of %s (%s) ***\n\n" % (region, data.pop("name"), data.pop("abbr")))

sys.stdout.write(" FIPS code: %s\n" % data.pop("fips"))

Expand Down
4 changes: 1 addition & 3 deletions us/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ def lookup(val, field: Optional[str] = None, use_cache: bool = True) -> Optional
return matched_state


def mapping(
from_field: str, to_field: str, states: Optional[Iterable[State]] = None
) -> Dict[Any, Any]:
def mapping(from_field: str, to_field: str, states: Optional[Iterable[State]] = None) -> Dict[Any, Any]:
if states is None:
states = STATES_AND_TERRITORIES
return {getattr(s, from_field): getattr(s, to_field) for s in states}
Expand Down
4 changes: 1 addition & 3 deletions us/tests/test_us.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ def test_jellyfish_metaphone():

def test_mapping():
states = us.STATES[:5]
assert us.states.mapping("abbr", "fips", states=states) == dict(
(s.abbr, s.fips) for s in states
)
assert us.states.mapping("abbr", "fips", states=states) == dict((s.abbr, s.fips) for s in states)


def test_obsolete_mapping():
Expand Down
1 change: 1 addition & 0 deletions us/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "3.1.2"

0 comments on commit 3abf967

Please sign in to comment.