diff --git a/.github/workflows/code_coverage.yml b/.github/workflows/code_coverage.yml index ffe6afb..296d3d1 100644 --- a/.github/workflows/code_coverage.yml +++ b/.github/workflows/code_coverage.yml @@ -1,26 +1,33 @@ name: "Code Coverage" -on: [push, pull_request] +on: [ push, pull_request ] jobs: - coverage: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - name: Install dependencies - run: | - pip install -r requirements.txt - - name: Run pytest with coverage - run: | - pytest --cov=./ --cov-report=xml - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v1 - with: - file: ./coverage.xml - flags: unittests - name: codecov-umbrella - fail_ci_if_error: false + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.11.3" ] + steps: + - uses: actions/checkout@v4 + - uses: eifinger/setup-rye@v3 + id: setup-rye + with: + cache-prefix: ${{ matrix.python-version }} + + - name: Pin python-version ${{ matrix.python-version }} + run: rye pin ${{ matrix.python-version }} + + - name: Install dependencies + run: rye sync --no-lock + + - name: Lint + run: rye lint -a + + - name: Test + run: rye run pytest + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + file: ./htmlcov/index.html diff --git a/.gitignore b/.gitignore index 5db624a..c38126e 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,7 @@ var/ pip-log.txt pip-delete-this-directory.txt -# Unit test / coverage reports +# Unit tests / coverage reports htmlcov/ .tox/ .coverage diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md index 81f49ae..93ab4ad 100644 --- a/CONTRIBUTION.md +++ b/CONTRIBUTION.md @@ -19,13 +19,13 @@ Thank you for considering contributing to our project! We welcome contributions 1. Fork and clone the Repository 2. Pull latest changes from the main repository if it has diverged -3. [Create a virtual environment for the project](https://docs.python.org/3/library/venv.html) -4. Install dependencies using `pip install -r requirements.txt` -5. Install pre-commit hook using `pre-commit install` -6. Run tests using `pytest tests/test_file_name.py ` or specific test name like `pytest tests/test_file_name.py::test_function_name` -7. Ensure the features is passing the acceptance criteria by `pytest test_results.py ` or `python test_results.py ` +3. Add Rye on your system if it is not installed already. [Source](https://rye-up.com/guide/installation/) +4. Install all the dependencies using `rye sync`. +5. Install pre-commit hook using `rye run pre-commit install` +6. Run `rye add package_name` (if you wish to add any packages as per your requirements.) and make sure to execute ```rye sync``` to add these dependencies in your working environment. +7. Run tests using `rye run pytest` or `rye run pytest -k test_function_name -v` to run specific file. 8. Do not push changes without the tests and coverage passing -9. Commit your changes with **proper** commit messages in imperative form like `Add my best feature`, `Fix issues casusing whatever`, `Update docs` etc: [Good reference here](https://cbea.ms/git-commit/) +9. Commit your changes with **proper** commit messages in imperative form like `Add my best feature`, `Fix issues causing whatever`, `Update docs` etc: [Good reference here](https://cbea.ms/git-commit/) 10. Make changes and push to your forked repository 11. Create PR to the forked repository as mentioned below diff --git a/README.md b/README.md index f2d5265..46a05a8 100644 --- a/README.md +++ b/README.md @@ -67,12 +67,14 @@ scode cscode pref reason ``` ## Command +You need to have [Rye](https://rye-up.com/guide/installation/) installed in your system to be able to run the project.Once you have it installed, run ```rye sync``` To run `school_center.py` use the command below: ```bash -python3 school_center.py sample_data/schools_grade12_2081.tsv sample_data/centers_grade12_2081.tsv sample_data/prefs.tsv +rye run dev ``` +If you change the location of your sample files, make sure to update the command(cmd) in ```[tool.rye.scripts]``` in the ```pyproject.toml``` file with your file path and execute ```rye sync``` . If you wish to run any other files than ```school_center.py```, you can simply do ```rye run python file_name.py``` ## Output diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7793803 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,38 @@ +[project] +name = "center-randomize" +version = "0.1.0" +description = "Exam Center Randomization Script" +authors = [ + { name = "moest-np" } +] +dependencies = [ + "streamlit-folium==0.19.1", + "folium==0.16.0", + "streamlit>=1.33.0", +] +readme = "README.md" +requires-python = ">= 3.9" + +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.rye] +managed = true +dev-dependencies = [ + "pytest==8.0.2", + "pytest-clarity==1.0.1", + "pytest-sugar==1.0.0", + "pytest-cov==5.0.0", + "ruff==0.4.1", + "pre-commit==3.6.0", +] + +[tool.rye.scripts] +dev = { cmd = "python -m school_center sample_data/schools_grade12_2081.tsv sample_data/centers_grade12_2081.tsv sample_data/prefs.tsv", env = {} } + +[tool.hatch.metadata] +allow-direct-references = true + +[tool.hatch.build.targets.wheel] +packages = ["src/center_randomize"] diff --git a/pytest.ini b/pytest.ini index 025b67b..bb20a82 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,2 @@ [pytest] -addopts = --cov=. --cov-fail-under 80 --cov-report term --cov-report html --maxfail 1 --force-sugar +addopts = --cov=. --cov-fail-under 70 --cov-report term --cov-report html --maxfail 1 --force-sugar diff --git a/requirements-dev.lock b/requirements-dev.lock new file mode 100644 index 0000000..63b3cbd --- /dev/null +++ b/requirements-dev.lock @@ -0,0 +1,165 @@ +# generated by rye +# use `rye lock` or `rye sync` to update this lockfile +# +# last locked with the following flags: +# pre: false +# features: [] +# all-features: false +# with-sources: false +# generate-hashes: false + +-e file:. +altair==5.3.0 + # via streamlit +attrs==23.2.0 + # via jsonschema + # via referencing +blinker==1.8.1 + # via streamlit +branca==0.7.2 + # via folium + # via streamlit-folium +cachetools==5.3.3 + # via streamlit +certifi==2024.2.2 + # via requests +cfgv==3.4.0 + # via pre-commit +charset-normalizer==3.3.2 + # via requests +click==8.1.7 + # via streamlit +coverage==7.5.0 + # via pytest-cov +distlib==0.3.8 + # via virtualenv +exceptiongroup==1.2.1 + # via pytest +filelock==3.14.0 + # via virtualenv +folium==0.16.0 + # via center-randomize + # via streamlit-folium +gitdb==4.0.11 + # via gitpython +gitpython==3.1.43 + # via streamlit +identify==2.5.36 + # via pre-commit +idna==3.7 + # via requests +iniconfig==2.0.0 + # via pytest +jinja2==3.1.3 + # via altair + # via branca + # via folium + # via pydeck + # via streamlit-folium +jsonschema==4.22.0 + # via altair +jsonschema-specifications==2023.12.1 + # via jsonschema +markdown-it-py==3.0.0 + # via rich +markupsafe==2.1.5 + # via jinja2 +mdurl==0.1.2 + # via markdown-it-py +nodeenv==1.8.0 + # via pre-commit +numpy==1.26.4 + # via altair + # via folium + # via pandas + # via pyarrow + # via pydeck + # via streamlit +packaging==24.0 + # via altair + # via pytest + # via pytest-sugar + # via streamlit +pandas==2.2.2 + # via altair + # via streamlit +pillow==10.3.0 + # via streamlit +platformdirs==4.2.1 + # via virtualenv +pluggy==1.5.0 + # via pytest +pprintpp==0.4.0 + # via pytest-clarity +pre-commit==3.6.0 +protobuf==4.25.3 + # via streamlit +pyarrow==16.0.0 + # via streamlit +pydeck==0.9.0 + # via streamlit +pygments==2.18.0 + # via rich +pytest==8.0.2 + # via pytest-clarity + # via pytest-cov + # via pytest-sugar +pytest-clarity==1.0.1 +pytest-cov==5.0.0 +pytest-sugar==1.0.0 +python-dateutil==2.9.0.post0 + # via pandas +pytz==2024.1 + # via pandas +pyyaml==6.0.1 + # via pre-commit +referencing==0.35.1 + # via jsonschema + # via jsonschema-specifications +requests==2.31.0 + # via folium + # via streamlit +rich==13.7.1 + # via pytest-clarity + # via streamlit +rpds-py==0.18.0 + # via jsonschema + # via referencing +ruff==0.4.1 +setuptools==69.5.1 + # via nodeenv +six==1.16.0 + # via python-dateutil +smmap==5.0.1 + # via gitdb +streamlit==1.34.0 + # via center-randomize + # via streamlit-folium +streamlit-folium==0.19.1 + # via center-randomize +tenacity==8.2.3 + # via streamlit +termcolor==2.4.0 + # via pytest-sugar +toml==0.10.2 + # via streamlit +tomli==2.0.1 + # via coverage + # via pytest +toolz==0.12.1 + # via altair +tornado==6.4 + # via streamlit +typing-extensions==4.11.0 + # via altair + # via streamlit +tzdata==2024.1 + # via pandas +urllib3==2.2.1 + # via requests +virtualenv==20.26.1 + # via pre-commit +watchdog==4.0.0 + # via streamlit +xyzservices==2024.4.0 + # via folium diff --git a/requirements.lock b/requirements.lock new file mode 100644 index 0000000..f13cfdb --- /dev/null +++ b/requirements.lock @@ -0,0 +1,120 @@ +# generated by rye +# use `rye lock` or `rye sync` to update this lockfile +# +# last locked with the following flags: +# pre: false +# features: [] +# all-features: false +# with-sources: false +# generate-hashes: false + +-e file:. +altair==5.3.0 + # via streamlit +attrs==23.2.0 + # via jsonschema + # via referencing +blinker==1.8.1 + # via streamlit +branca==0.7.2 + # via folium + # via streamlit-folium +cachetools==5.3.3 + # via streamlit +certifi==2024.2.2 + # via requests +charset-normalizer==3.3.2 + # via requests +click==8.1.7 + # via streamlit +folium==0.16.0 + # via center-randomize + # via streamlit-folium +gitdb==4.0.11 + # via gitpython +gitpython==3.1.43 + # via streamlit +idna==3.7 + # via requests +jinja2==3.1.3 + # via altair + # via branca + # via folium + # via pydeck + # via streamlit-folium +jsonschema==4.22.0 + # via altair +jsonschema-specifications==2023.12.1 + # via jsonschema +markdown-it-py==3.0.0 + # via rich +markupsafe==2.1.5 + # via jinja2 +mdurl==0.1.2 + # via markdown-it-py +numpy==1.24.4 + # via altair + # via folium + # via pandas + # via pyarrow + # via pydeck + # via streamlit +packaging==24.0 + # via altair + # via streamlit +pandas==2.0.3 + # via altair + # via streamlit +pillow==10.3.0 + # via streamlit +protobuf==4.25.3 + # via streamlit +pyarrow==16.0.0 + # via streamlit +pydeck==0.9.0 + # via streamlit +pygments==2.18.0 + # via rich +python-dateutil==2.9.0.post0 + # via pandas +pytz==2024.1 + # via pandas +referencing==0.35.1 + # via jsonschema + # via jsonschema-specifications +requests==2.31.0 + # via folium + # via streamlit +rich==13.7.1 + # via streamlit +rpds-py==0.18.0 + # via jsonschema + # via referencing +six==1.16.0 + # via python-dateutil +smmap==5.0.1 + # via gitdb +streamlit==1.34.0 + # via center-randomize + # via streamlit-folium +streamlit-folium==0.19.1 + # via center-randomize +tenacity==8.2.3 + # via streamlit +toml==0.10.2 + # via streamlit +toolz==0.12.1 + # via altair +tornado==6.4 + # via streamlit +typing-extensions==4.11.0 + # via altair + # via streamlit +tzdata==2024.1 + # via pandas +urllib3==2.2.1 + # via requests +watchdog==4.0.0 + # via streamlit +xyzservices==2024.4.0 + # via folium diff --git a/requirements.txt b/test_requirements.txt similarity index 100% rename from requirements.txt rename to test_requirements.txt diff --git a/test/__init__.py b/tests/__init__.py similarity index 100% rename from test/__init__.py rename to tests/__init__.py diff --git a/test/test_results.py b/tests/test_results.py similarity index 99% rename from test/test_results.py rename to tests/test_results.py index d855aa7..01e33d2 100644 --- a/test/test_results.py +++ b/tests/test_results.py @@ -7,7 +7,7 @@ # Add the parent directory to the Python path sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) -from test.utils.custom_tsv_parser import ParseTSVFile +from tests.utils.custom_tsv_parser import ParseTSVFile PREF_CUTOFF = -4 diff --git a/test/utils/__init__.py b/tests/utils/__init__.py similarity index 100% rename from test/utils/__init__.py rename to tests/utils/__init__.py diff --git a/test/utils/custom_tsv_parser.py b/tests/utils/custom_tsv_parser.py similarity index 100% rename from test/utils/custom_tsv_parser.py rename to tests/utils/custom_tsv_parser.py