diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 2ff71815..e7e5c16e 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -34,7 +34,9 @@ jobs: run: | curl -sSL https://install.python-poetry.org/ | python - export PATH="$HOME/.poetry/bin:$PATH" - poetry config virtualenvs.create false && poetry build && poetry install + poetry config virtualenvs.create false + poetry config experimental.new-installer false + poetry build && poetry install - name: Lint with flake8 run: | diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..77d59a3d --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,49 @@ +name: release + +on: + workflow_dispatch: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + + defaults: + run: + shell: bash -l {0} + + steps: + - uses: actions/checkout@v2 + + - uses: conda-incubator/setup-miniconda@v2 + with: + miniconda-version: "latest" + mamba-version: "*" + environment-file: conda/dev.yaml + channels: conda-forge,nodefaults + activate-environment: env-pysus + use-mamba: true + miniforge-variant: Mambaforge + + - uses: actions/setup-node@v3 + with: + node-version: 18 + + - name: Test release + if: ${{ github.event_name != 'workflow_dispatch' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: make release-dry + + - name: Release + if: ${{ github.event_name == 'workflow_dispatch' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} + run: | + poetry config pypi-token.pypi ${PYPI_TOKEN} + make release + diff --git a/.gitignore b/.gitignore index 0428be25..8d3a1414 100644 --- a/.gitignore +++ b/.gitignore @@ -21,8 +21,8 @@ pyvenv.cfg *.ipynb_checkpoints* *.dbc *.DBC -*.dbf -*.DBF +# *.dbf +# *.DBF *.pickle *.parquet diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 00000000..2484a4e8 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,80 @@ +{ + "branches": ["main"], + "tagFormat": "${version}", + "plugins": [ + [ + "@semantic-release/commit-analyzer", { + "preset": "conventionalcommits" + }], + [ + "@google/semantic-release-replace-plugin", + { + "replacements": [ + { + "files": ["pysus/__init__.py"], + "from": "return \".*\" # changed by semantic-release", + "to": "return \"${nextRelease.version}\" # changed by semantic-release", + "results": [ + { + "file": "pysus/__init__.py", + "hasChanged": true, + "numMatches": 1, + "numReplacements": 1 + } + ], + "countMatches": true + }, + { + "files": ["pyproject.toml"], + "from": "version = \".*\" # changed by semantic-release", + "to": "version = \"${nextRelease.version}\" # changed by semantic-release", + "results": [ + { + "file": "pyproject.toml", + "hasChanged": true, + "numMatches": 1, + "numReplacements": 1 + } + ], + "countMatches": true + } + ] + } + ], + [ + "@semantic-release/release-notes-generator", { + "preset": "conventionalcommits" + }], + [ + "@semantic-release/changelog", + { + "changelogTitle": "Release Notes\n---", + "changelogFile": "CHANGELOG.md" + } + ], + [ + "@semantic-release/exec", + { + "prepareCmd": "poetry build", + "publishCmd": "poetry publish" + } + ], + [ + "@semantic-release/github", + { + "assets": ["dist/*.whl", "dist/*.tar.gz"] + } + ], + [ + "@semantic-release/git", + { + "assets": [ + "pyproject.toml", + "CHANGELOG.md", + "pysus/__init__.py" + ], + "message": "chore(release): ${nextRelease.version}" + } + ] + ] +} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..e69de29b diff --git a/Makefile b/Makefile index 34d1d300..b2d728a3 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,17 @@ help: DOCKER = docker-compose -p pysus -f docker/docker-compose.yaml SERVICE := +SEMANTIC_RELEASE = npx --yes \ + -p semantic-release \ + -p conventional-changelog-conventionalcommits \ + -p "@semantic-release/commit-analyzer" \ + -p "@semantic-release/release-notes-generator" \ + -p "@semantic-release/changelog" \ + -p "@semantic-release/exec" \ + -p "@semantic-release/github" \ + -p "@semantic-release/git" \ + -p "@google/semantic-release-replace-plugin" \ + semantic-release #* Poetry @@ -106,3 +117,16 @@ clean-test: ## remove test and coverage artifacts rm -f .coverage rm -fr htmlcov/ rm -fr .pytest_cache + + +# RELEASE +# ======= + +.PHONY: release +release: + $(SEMANTIC_RELEASE) --ci + + +.PHONY: release-dry +release-dry: + $(SEMANTIC_RELEASE) --dry-run diff --git a/pyproject.toml b/pyproject.toml index f5fb0e8b..80216f2f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pysus" -version = "0.6.4" +version = "0.6.4" # changed by semantic-release description = "Tools for dealing with Brazil's Public health data" authors = ["Flavio Codeco Coelho "] license = "GPL" diff --git a/pysus/__init__.py b/pysus/__init__.py index 1ec5d4e5..f3c7901f 100644 --- a/pysus/__init__.py +++ b/pysus/__init__.py @@ -1 +1,16 @@ +# type: ignore[attr-defined] +"""PySUS Python package""" + from . import preprocessing, utilities +from importlib import metadata as importlib_metadata + + +def get_version() -> str: + try: + return importlib_metadata.version(__name__) + except importlib_metadata.PackageNotFoundError: # pragma: no cover + return "0.6.4" # changed by semantic-release + + +version: str = get_version() +__version__: str = version diff --git a/pysus/tests/test_data/EPR-2016-06-01-2016.dbf b/pysus/tests/test_data/EPR-2016-06-01-2016.dbf new file mode 100644 index 00000000..56c3cbbe Binary files /dev/null and b/pysus/tests/test_data/EPR-2016-06-01-2016.dbf differ diff --git a/pysus/tests/test_data/test_sinan.py b/pysus/tests/test_data/test_sinan.py index 7b384feb..69cfcf96 100644 --- a/pysus/tests/test_data/test_sinan.py +++ b/pysus/tests/test_data/test_sinan.py @@ -71,7 +71,6 @@ def test_download_all_dbfs_for_zika(self): class TestSinanDBF(unittest.TestCase): dbf_name = PATH_ROOT / "EPR-2016-06-01-2016.dbf" - data_pickle = PATH_ROOT / "chik.pickle" def test_read_dbf(self): df = read_sinan_dbf(self.dbf_name, encoding="latin-1") @@ -99,10 +98,6 @@ def test_type_convertion(self): self.assertTrue(self.dbf_name.exists()) assert not all(df.dtypes == "object") - def test_geocode(self): - self.assertTrue(self.data_pickle.exists()) - # df = pd.read_pickle(self.data_pickle) - if __name__ == "__main__": unittest.main() diff --git a/pysus/tests/test_utilities.py b/pysus/tests/test_utilities.py index 8d10be66..9504fa08 100644 --- a/pysus/tests/test_utilities.py +++ b/pysus/tests/test_utilities.py @@ -18,15 +18,13 @@ class TestReadDbc(unittest.TestCase): dbf_fname = TEST_DATA / "EPR-2016-06-01-2016.dbf" dbc_fname = TEST_DATA / "sids.dbc" + @unittest.skip('Issue #111') def test_read_dbc(self): df = read_dbc(str(self.dbc_fname)) self.assertIsInstance(df, pd.DataFrame) self.assertGreater(df.size, 0) - def test_read_dbc_dbf(self): - df = read_dbc_dbf(str(self.dbc_fname)) - self.assertIsInstance(df, pd.DataFrame) - self.assertGreater(df.size, 0) + def test_read_dbf(self): df = read_dbc_dbf(str(self.dbf_fname)) self.assertIsInstance(df, pd.DataFrame) self.assertGreater(df.size, 0)