Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add poetry and fix problem from #23 #25

Merged
merged 44 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c9c3efa
Add poetry, all configs and dependences now are in pyproject.toml, pc…
Jun 5, 2022
cc394fb
Fix: Dependencies versions
Jun 5, 2022
3dabd25
Feature: Scratch files to document the project
Jun 5, 2022
697ade8
Feature: Improve CI/CD with poetry and removing pyright workaround
Jun 5, 2022
1a2c94f
Fix: Add black and isort in dependencies
Jun 5, 2022
7176fd0
Feature: Add a script to run all tests, just type "poetry run all_test"
Jun 5, 2022
13b1b19
Feature: Add something in documentations
Jun 6, 2022
ea7e6c4
Merge branch 'main' into feature/poetry
Jun 8, 2022
2de548e
Fix: Project version, Author, Python versions, Pandas version
Jun 8, 2022
8bcb394
Fix: Remove old test file documentation
Jun 8, 2022
cf96463
Fix: Remove old pyright configs
Jun 8, 2022
ec78fab
Fix: Documentation in README.md with links
Jun 8, 2022
9f44c9b
Fix: pyproject.toml python compatibility
Jun 8, 2022
34ec92a
Fix: Add tests with wheel
Jun 8, 2022
728e449
Fix: Remove pytests from tests against dist
Jun 8, 2022
7871b94
Fix: Remove Source code distribution on tests after install wheel
Jun 8, 2022
e5040a4
Fix: Using shutil to remove dir
Jun 8, 2022
9259b96
Fix: Improve local tests and fix CI tests
Jun 8, 2022
8d05d17
Fix: Add metadata to pyproject.toml when build a wheel
Jun 8, 2022
34c8305
Fix: Replace default "poetry.scripts" equivalent to console_scripts f…
Jun 8, 2022
b9677bd
Fix: Improving docs with instructions to update dependencies "poetry …
Jun 9, 2022
13d738d
Fix: Split Dev from Dist Dependencies
Jun 10, 2022
b646c9a
Refactor: Util test scripts
Jun 10, 2022
0e3ea0a
CI: All tests call poe to run
Jun 10, 2022
fbff5dc
Docs: Improving setup and test documentation
Jun 10, 2022
ce3a4f5
Refactor: Improving test_src (I still think it could be better)
Jun 10, 2022
b398255
Docs: Improving poe tests documentation
Jun 10, 2022
40836f2
Style: Apply black and isort to new scripts code
Jun 10, 2022
3cf7947
Fix: Bug when test_src code fails, test_dist continues to test
Jun 10, 2022
38a64d6
Fix: Error in test documentation
Jun 10, 2022
54a846a
Docs: Improving CLI help documentation to run tests
Jun 10, 2022
36fc564
Docs: Improving CLI help documentation to run tests
Jun 10, 2022
0f73192
CI: Runs CI only when change code or dependencies
Jun 10, 2022
1d73e23
Docs: Fix Mc Donald's english errors
Jun 10, 2022
fe21dd2
Fix: Package test
Jun 12, 2022
bc550a6
Fix: Package Test
Jun 12, 2022
d4467e0
CI: Fix package test
Jun 12, 2022
0f4eb0b
Fix: add project to sys path
Jun 12, 2022
5a17251
Refactor: Folder Hierarquie, Rollback job, refresh setup docs
Jun 14, 2022
5667178
Fix: Add rollback to test_dist
Jun 14, 2022
4c6d838
Feature: Add code style check
Jun 14, 2022
ba94941
Refactor: Improving rollback
Jun 14, 2022
3abae80
Feature: add clean cache option in local tests
Jun 14, 2022
0aaeadb
Fix: code style check
Jun 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
name: 'Test'

on: [push, pull_request, workflow_dispatch]

on:
push:
paths:
- /**/*.py
- /**/*.pyi
- pyproject.toml
- .github/workflows/test.yml
pull_request:
workflow_dispatch:

jobs:
test:
Expand All @@ -22,31 +29,34 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Upgrade pip
run: |
python -m pip install --upgrade pip
run: python -m pip install --upgrade pip

- name: Install Poetry
run: pip install poetry

- name: Install project dependencies
run: poetry install -vvv

- name: Install Poetry and project dependencies
run: |
pip install poetry
poetry install
- name: Run MyPy Against Source Code
run: poetry run poe run_mypy_src

- name: Run Pyright
run: poetry run pyright
- name: Run Pyright Against Source Code
run: poetry run poe run_pyright_src

- name: Run Pytest
run: poetry run pytest
- name: Run Pytest Against Source Code
run: poetry run poe run_pytest_src

- name: Run MyPy
run: poetry run mypy pandas-stubs tests
- name: Build Distribution
run: poetry run poe build_dist

- name: Install wheel
run: poetry run install_wheel
- name: Install Distribution
run: poetry run poe install_dist

- name: Remove Source Code
run: poetry run rm_src_code
run: poetry run poe remove_src

- name: Run Pyright against dist
run: poetry run pyright
- name: Run Pyright Against Distribution
run: poetry run poe run_pyright_dist

- name: Run MyPy against dist
run: poetry run mypy tests
- name: Run MyPy Against Distribution
run: poetry run poe run_mypy_dist
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To contribute changes to the stubs, you must include an appropriate test. See `

## Documentation

- [How to setup the enviroment](docs/1%20-%20setup.md)
- [How to set up the environment](docs/1%20-%20setup.md)
- [How to test the project](docs/2%20-%20tests.md)
- [How to follow the code style](docs/3%20-%20style.md)
- [Security stuffs](docs/4%20-%20security.md)
Expand Down
14 changes: 8 additions & 6 deletions docs/1 - setup.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
## Setup Environment

- Make sure you have python >= 3.8 installed
- Install poetry if you still don't have: pip install poetry
- Install the project dependencies with: poetry install -vvv
- Run all tests to make sure the project is ok: poetry run all_tests
## Set Up Environment

- Make sure you have `python >= 3.8` installed. </br></br>
- Install poetry if you still don't have: </br> `pip install poetry`</br> </br>
- Install the project dependencies with: </br> `poetry install -vvv` </br></br>
- Update if you already have the project and someone added new dependencies: </br> `poetry update -vvv`</br></br>
- Enter the virtual environment: </br> `poetry shell`</br></br>
- Run all tests to make sure the project is ok: </br> `poe test_all` </br></br>
- Do you want to add a new dependency? </br> `poetry add --dev foo-pkg ` </br></br>
12 changes: 11 additions & 1 deletion docs/2 - tests.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
## Test

- These tests originally came from https://github.com/VirtusLab/pandas-stubs.
- Run local tests against source code. </br> `poe test_src` </br> </br>
- Profiles: </br>
- Default: Runs only mypy and pyright tests </br> `poe test_src --profile=default` </br>
- Pytest: Runs only pytest </br> `poe test_src --profile=pytest` </br>
- Full: Run all tests (mypy, pyright and pytests) </br> `poe test_src --profiel=full` </br> </br>

- Run local tests against distribution: </br> `poe test_dist` </br> </br>

- Run all local tests: </br> `poe test_all` </br> </br>

- Forgot some command? </br>`poe --help` </br> </br>

- These tests originally came from https://github.com/VirtusLab/pandas-stubs.
90 changes: 80 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,103 @@
[tool.poetry]
name = "pandas-stubs"
version = "1.4.2.20220608"
description = "Stubs for pandas"
authors = ["The Pandas Development Team"]
version = "1.4.2.220608"
description = "Type annotations for pandas"
authors = ["The Pandas Development Team <pandas-dev@python.org>"]
license = "BSD-3-Clause"
readme = "README.md"
homepage = "https://pandas.pydata.org"
repository = "https://github.com/pandas-dev/pandas-stubs"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Scientific/Engineering"
]
packages = [
{ "include" = "pandas-stubs"}
]

[tool.poetry.urls]
"Bug Tracker" = "https://github.com/pandas-dev/pandas-stubs/issues"
"Documentation" = "https://pandas.pydata.org/pandas-docs/stable"
"Source Code" = "https://github.com/pandas-dev/pandas-stubs"

[tool.poetry.dependencies]
python = ">=3.8,<3.11"

[tool.poetry.dev-dependencies]
pandas = "1.4.*"
mypy = ">=0.960"
typing-extensions = ">=4.2.0"
matplotlib = ">=3.3.2"

[tool.poetry.dev-dependencies]
mypy = ">=0.960"
pytest = ">=7.1.2"
pyright = ">=1.1.251"
black = ">=22.3.0"
isort = ">=5.10.1"
poethepoet = ">=0.13.1"
loguru = ">=0.6.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
all_tests = "scripts.tests:run_all"
install_wheel = "scripts.tests:install_wheel"
rm_src_code = "scripts.tests:remove_src_code"
[tool.poe.tasks.test_src]
help = "LOCAL TEST | Run tests against source code version: \"poe test_src -p=<profile>\""
script = "scripts.test:test_src(profile)"

[[tool.poe.tasks.test_src.args]]
help = "\"default\" (mypy + pyright) or \"pytest\" (pytest only) or \"full\" (mypy + pyright + pytest)"
name = "profile"
options = ["-p", "--profile"]
default = "default"

[tool.poe.tasks.test_dist]
help = "Local Test | Run tests against distribuition version: \"poe test_dist\""
script = "scripts.test:test_dist"

[tool.poe.tasks.test_all]
help = "Local Test | Run tests against source code and distribuition version: \"poe test_all\""
script = "scripts.test:test_all"

[tool.poe.tasks.run_mypy_src]
help = "CI Test | Run mypy against source code"
script = "scripts.test:run_mypy_src"

[tool.poe.tasks.run_pyright_src]
help = "CI Test | Run pyright against source code"
script = "scripts.test:run_pyright_src"

[tool.poe.tasks.run_pytest_src]
help = "CI Test | Run pytest against source code"
script = "scripts.test:run_pytest_src"

[tool.poe.tasks.build_dist]
help = "CI Test | Build distribuition"
script = "scripts.test:build_dist"

[tool.poe.tasks.install_dist]
help = "CI Test | Install distribuition"
script = "scripts.test:install_dist"

[tool.poe.tasks.remove_src]
help = "CI Test | Remove source code"
script = "scripts.test:remove_src"

[tool.poe.tasks.run_mypy_dist]
help = "CI Test | Run mypy against distribuition"
script = "scripts.test:run_mypy_dist"

[tool.poe.tasks.run_pyright_dist]
help = "CI Test | Run pyright against distribuition"
script = "scripts.test:run_pyright_dist"

[tool.black]
line_length = 88
Expand Down
18 changes: 18 additions & 0 deletions scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys

from loguru import logger

config = {
"handlers": [
{
"sink": sys.stderr,
"format": (
"\n<level>===========================================</level>\n"
"<level>{message}</level>\n"
"<level>===========================================</level>\n"
),
}
]
}

logger.configure(**config)
31 changes: 31 additions & 0 deletions scripts/_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import time
from dataclasses import dataclass
from subprocess import CalledProcessError
from typing import Callable, List

from loguru import logger


@dataclass
class Step:
name: str
run: Callable[[], None]


def run_job(steps: List[Step]) -> None:
"""
Responsible to run procedures with logs
"""

for step in steps:
start = time.perf_counter()
logger.info(f"Beginning to run: '{step.name}'")

try:
step.run()
except CalledProcessError:
logger.error(f"'{step.name}' failed!")
break

end = time.perf_counter()
logger.success(f"End '{step.name}', runtime: {end - start:.3f} seconds.")
117 changes: 117 additions & 0 deletions scripts/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import shutil
import subprocess
from pathlib import Path

from scripts._job import Step, run_job


def run_mypy_src():
cmd = ["mypy", "pandas-stubs", "tests"]
subprocess.run(cmd, check=True)


def run_pyright_src():
cmd = ["pyright"]
subprocess.run(cmd, check=True)


def run_pytest_src():
cmd = ["pytest"]
subprocess.run(cmd, check=True)


def test_src(profile):
steps = []

# Possible steps
mypy_step = Step(name="Run Mypy Against Source Code", run=run_mypy_src)
pyright_step = Step(name="Run Pyright Against Source Code", run=run_pyright_src)
pytest_step = Step(name="Run Pytest Against Source Code", run=run_pytest_src)

# Defining which test is going to run according to a profile
if profile in (None, "", "default"):
steps.append(mypy_step)
steps.append(pyright_step)
elif profile == "pytest":
steps.append(Step(name="Run Pytest Against Source Code", run=run_pytest_src))
elif profile == "full":
steps.append(mypy_step)
steps.append(pyright_step)
steps.append(pytest_step)
else:
raise Exception("Profile not found!")

run_job(steps)


def build_dist():
cmd = ["poetry", "build", "-f", "wheel"]
subprocess.run(cmd, check=True)


def install_dist():
path = next(Path("dist/").glob("*.whl"))
cmd = ["pip", "install", str(path), "--force-reinstall"]
subprocess.run(cmd, check=True)


def remove_src():
shutil.rmtree(r"pandas-stubs")


def run_mypy_dist():
cmd = ["mypy", "tests"]
subprocess.run(cmd, check=True)


def run_pyright_dist():
cmd = ["pyright", "tests"]
subprocess.run(cmd, check=True)


def uninstall_dist():
cmd = ["pip", "uninstall", "-y", "pandas-stubs"]
subprocess.run(cmd, check=True)


def restore_src():
cmd = ["git", "checkout", "HEAD", "pandas-stubs"]
subprocess.run(cmd, check=True)


def install_poetry():
cmd = ["poetry", "update", "-vvv"]
subprocess.run(cmd, check=True)


def test_dist():
steps = [
Step(name="Build Dist", run=build_dist),
Step(name="Install Dist", run=install_dist),
Step(name="Remove Source Code", run=remove_src),
Step(name="Run MyPy Against Dist", run=run_mypy_dist),
Step(name="Run Pyright Against Dist", run=run_pyright_dist),
Step(name="Uninstall Dist", run=uninstall_dist),
Step(name="Restore Source Code", run=restore_src),
Step(name="Install Poetry", run=install_poetry),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need to install poetry when it is already installed?

]

run_job(steps)


def test_all():
steps = [
Step(name="Run Mypy Against Source Code", run=run_mypy_src),
Step(name="Run Pyright Against Source Code", run=run_pyright_src),
Step(name="Run Pytest Against Source Code", run=run_pytest_src),
Step(name="Build Dist", run=build_dist),
Step(name="Install Dist", run=install_dist),
Step(name="Remove Source Code", run=remove_src),
Step(name="Run MyPy Against Dist", run=run_mypy_dist),
Step(name="Run Pyright Against Dist", run=run_pyright_dist),
Step(name="Uninstall Dist", run=uninstall_dist),
Step(name="Restore Source Code", run=restore_src),
Step(name="Install Poetry", run=install_poetry),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above about installing poetry

]

run_job(steps)
Loading