Repository: EL-BID/idbsocialdatapy (language: python)

Issue:
Development framework and iadburls



Discussion / hints:

Fix patch:
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100644
index 0000000..7929ba9
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -0,0 +1,87 @@
+name: CI/CD
+
+on:
+  push:
+    branches:
+      - main
+  pull_request:
+    types: [opened, synchronize]
+
+jobs:
+  CI:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
+      fail-fast: false
+    steps:
+        - uses: actions/checkout@v3
+        - name: Set up Python
+          uses: actions/setup-python@v4
+          with:
+            python-version: ${{ matrix.python-version }}
+        - uses: actions/cache@v3
+          id: cache
+          with:
+            path: ${{ env.pythonLocation }}
+            key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-test-v02
+        - name: Install Dependencies
+          if: steps.cache.outputs.cache-hit != 'true'
+          run: pip install -e .[dev,test]
+        - name: Lint with flake8
+          run: |
+            # stop the build if there are Python syntax errors or undefined names
+            flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
+            # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
+            flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
+        - name: Test with pytest
+          run: pytest tests/
+        - name: Check black formatting
+          uses: psf/black@stable
+          with:
+            options: "--check --verbose"
+        - name: Check isort
+          uses: isort/isort-action@master
+  CD:
+    needs: CI
+    # Only run this job if new work is pushed to "main"
+    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
+    # Step 1. Set up operating system
+    runs-on: ubuntu-latest
+    steps:
+    # Step 2. Set up Python 3.9
+    - uses: actions/setup-python@v4
+      with:
+        python-version: 3.9
+    # Step 3. Check-out repository so we can access its contents
+    - uses: actions/checkout@v3
+      with:
+        fetch-depth: 0
+    # Step 4. Use PSR to make release
+    - name: Python Semantic Release
+      env:
+          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+      run: |
+          pip install python-semantic-release
+          git config user.name github-actions
+          git config user.email github-actions@github.com
+          semantic-release publish
+#     - name: Publish to TestPyPI
+#       uses: pypa/gh-action-pypi-publish@release/v1
+#       with:
+#         user: __token__
+#         password: ${{ secrets.TEST_PYPI_API_TOKEN }}
+#         repository_url: https://test.pypi.org/legacy/
+
+#     - name: Test install from TestPyPI
+#       run: |
+#           pip install \
+#           --index-url https://test.pypi.org/simple/ \
+#           --extra-index-url https://pypi.org/simple \
+#           pycounts
+
+#     - name: Publish to PyPI
+#       uses: pypa/gh-action-pypi-publish@release/v1
+#       with:
+#         user: __token__
+#         password: ${{ secrets.PYPI_API_TOKEN }}
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ddf0d47
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+__pycache__
+.vscode
+dist/
+*.ipynb
+env
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 0000000..578ad78
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,35 @@
+# See https://pre-commit.com for more information
+# See https://pre-commit.com/hooks.html for more hooks
+repos:
+- repo: https://github.com/pre-commit/pre-commit-hooks
+  rev: v4.3.0
+  hooks:
+    - id: trailing-whitespace
+    - id: end-of-file-fixer
+    - id: check-yaml
+    - id: debug-statements
+    - id: mixed-line-ending
+- repo: https://github.com/PyCQA/autoflake
+  rev: v1.7.7
+  hooks:
+  -   id: autoflake
+      args:
+      - --recursive
+      - --in-place
+      - --remove-all-unused-imports
+      - --remove-unused-variables
+      - --expand-star-imports
+      - --ignore-init-module-imports
+- repo: https://github.com/PyCQA/isort
+  rev: 5.10.1
+  hooks:
+    - id: isort
+- repo: https://github.com/psf/black
+  rev: 22.10.0
+  hooks:
+    - id: black
+    - id: black-jupyter
+- repo: https://github.com/PyCQA/flake8
+  rev: 5.0.4
+  hooks:
+    - id: flake8
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..e69de29
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..5a077c2
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,59 @@
+### To effectively contribute to this package code base, below are some guidelines to help you set up your development enviroment:
+
+The first step will be to clone this repository, and after that, follow the steps below in order.
+
+
+1. Create a new virtual environment with `venv`
+```bash
+python -m venv env
+```
+
+2. Then, activate it.
+
+**On Linux:**
+```bash
+source ./env/bin/activate
+```
+**On Windows Powershell:**
+```powershell
+.\env\Scripts\Activate.ps1
+```
+3. Make sure you have the latest pip version on your virtual environment to avoid errors on the next steps.
+```bash
+python -m pip install --upgrade pip
+```
+4. Install the required packages.
+```bash
+pip install -e ."[dev,test]"
+```
+5. This library uses several tools to ensure a consistent code format throughout the project, to automatically run all these tests we make use of `pre-commit`,
+which you can install running the following command
+```bash
+pre-commit install
+```
+
+### Commit Guidelines
+To maintain a proper documentation of how the project is evolving and to help the automatic versioning of this package,
+commit messages must have the following structure:
+```
+<type>(optional scope): short summary in present tense
+
+(optional body: explains motivation for the change)
+
+(optional footer: note BREAKING CHANGES here, and issues to be closed)
+```
+`<type>` refers to the kind of change made and is usually one of:
+
+* `feat`: A new feature.
+* `fix`: A bug fix.
+* `docs`: Documentation changes.
+* `style`: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc).
+* `refactor`: A code change that neither fixes a bug nor adds a feature.
+* `perf`: A code change that improves performance.
+* `test`: Changes to the test framework.
+* `build`: Changes to the build process or tools.
+
+`scope` is an optional keyword that provides context for where the change was made. It can be anything relevant to your package or development workflow
+(e.g., it could be the module or function name affected by the change).
+
+You can find further information about this type of commit message formatting [here.](https://github.com/angular/angular/blob/main/CONTRIBUTING.md#-commit-message-format)
diff --git a/README.md b/README.md
index 0923bbc..09903f3 100644
--- a/README.md
+++ b/README.md
@@ -52,10 +52,10 @@ The functions are ordered by importance, thus we will start working from the top
 
 | Function | Objective | Status | Developer |
 | :---: | :--- | :--- | :--- | 
-| iadburls | Function to get urls of the API | To do | Not assigned |
+| iadburls | Function to get urls of the API | Done | Genrry|
 | query_indicator | Main function, query indicators | To do | Not assigned |
 | query_dictionary | See available indicators | To do | Not assigned |
-| get_countries | Search available countries | To do | Not assigned |
+| get_countries | Search available countries | To do | Elena, Juan Pablo |
 | get_themes | Search available topics | To do | Not assigned |
 | search_indicator | Give string to search within the dictionary for an indicator | To do | Not assigned |
 | get_sources | Get available sources | To do | Not assigned |
diff --git a/idbsocialdatapy/__init__.py b/idbsocialdatapy/__init__.py
new file mode 100644
index 0000000..1ca00c7
--- /dev/null
+++ b/idbsocialdatapy/__init__.py
@@ -0,0 +1,3 @@
+__version__ = "0.0.0"
+
+from .utils import iadburls  # noqa
diff --git a/idbsocialdatapy/utils.py b/idbsocialdatapy/utils.py
new file mode 100644
index 0000000..1c97836
--- /dev/null
+++ b/idbsocialdatapy/utils.py
@@ -0,0 +1,19 @@
+import os
+
+base_url = "https://scl.datamig.org/"
+
+
+def iadburls() -> dict:
+    "Returns dictionary with different url strings as values"
+
+    matedata_url = os.path.join(base_url, "metadata/")
+    geojson_url = os.path.join(base_url, "geojson/?")
+    utils_url = "&format=csv"
+
+    url_dict = dict(
+        base_url=base_url,
+        utils_url=utils_url,
+        matedata_url=matedata_url,
+        geojson_url=geojson_url,
+    )
+    return url_dict
diff --git a/pyproject.toml b/pyproject.toml
new file mode 100644
index 0000000..af8de85
--- /dev/null
+++ b/pyproject.toml
@@ -0,0 +1,38 @@
+[build-system]
+requires = ["hatchling"]
+build-backend = "hatchling.build"
+
+[project]
+name = "idbsocialdatapy"
+readme = "README.md"
+requires-python = ">=3.7"
+
+dynamic = ["version"]
+
+[project.optional-dependencies]
+test = [
+  "pytest>=7.2.0"
+]
+dev = [
+    "autoflake >=1.7.7",
+    "flake8 >=5.0.4",
+    "pre-commit >=2.20.0",
+    "python-semantic-release >= 7.32.2"
+]
+
+[project.urls]
+Homepage = "https://github.com/EL-BID/idbsocialdatapy"
+
+[tool.hatch.version]
+path = "idbsocialdatapy/__init__.py"
+
+[tool.semantic_release]
+version_variable = [
+    'idbsocialdatapy/__init__.py:__version__'
+]
+branch = "main"
+changelog_file = "CHANGELOG.md"
+build_command = "python -m pip install --upgrade build && python -m build"
+dist_path = "dist/"
+upload_to_pypi = false
+remove_dist = false


Test patch:
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/test_utils.py b/tests/test_utils.py
new file mode 100644
index 0000000..3ef0ab7
--- /dev/null
+++ b/tests/test_utils.py
@@ -0,0 +1,33 @@
+import pytest
+
+from idbsocialdatapy.utils import iadburls
+
+
+@pytest.fixture
+def example_iadburls():
+    return iadburls()
+
+
+def test_iadburls_len(example_iadburls):
+    assert len(example_iadburls) == 4
+
+
+def test_iadburls_type(example_iadburls):
+    assert isinstance(example_iadburls, dict)
+
+
+def test_iadburls_keys(example_iadburls):
+    keys = example_iadburls.keys()
+    for key in keys:
+        assert key in ("base_url", "utils_url", "matedata_url", "geojson_url")
+
+
+def test_iadburls_values(example_iadburls):
+    values = example_iadburls.values()
+    for value in values:
+        assert value in (
+            "https://scl.datamig.org/",
+            "https://scl.datamig.org/metadata/",
+            "&format=csv",
+            "https://scl.datamig.org/geojson/?",
+        )