Skip to content

Commit

Permalink
Add poetry and fix problem from #23 (#25)
Browse files Browse the repository at this point in the history
* Add poetry, all configs and dependences now are in pyproject.toml, pckg structure now follows pep 561

* Fix: Dependencies versions

* Feature: Scratch files to document the project

* Feature: Improve CI/CD with poetry and removing pyright workaround

* Fix: Add black and isort in dependencies

* Feature: Add a script to run all tests, just type "poetry run all_test"

* Feature: Add something in documentations

* Fix: Project version, Author, Python versions, Pandas version

* Fix: Remove old test file documentation

* Fix: Remove old pyright configs

* Fix: Documentation in README.md with links

* Fix: pyproject.toml python compatibility

* Fix: Add tests with wheel

* Fix: Remove pytests from tests against dist

* Fix: Remove Source code distribution on tests after install wheel

* Fix: Using shutil to remove dir

* Fix: Improve local tests and fix CI tests

* Fix: Add metadata to pyproject.toml when build a wheel

* Fix: Replace default "poetry.scripts" equivalent to console_scripts from setuptools to "poe" a poetry plugin to run util scripts.

* Fix: Improving docs with instructions to update dependencies "poetry update".

* Fix: Split Dev from Dist Dependencies

* Refactor: Util test scripts

* CI: All tests call poe to run

* Docs: Improving setup and test documentation

* Refactor: Improving test_src (I still think it could be better)

* Docs: Improving poe tests documentation

* Style: Apply black and isort to new scripts code

* Fix: Bug when test_src code fails, test_dist continues to test

* Fix: Error in test documentation

* Docs: Improving CLI help documentation to run tests

* Docs: Improving CLI help documentation to run tests

* CI: Runs CI only when change code or dependencies

* Docs: Fix Mc Donald's english errors

* Fix: Package test

* Fix: Package Test

* CI: Fix package test

* Fix: add project to sys path

* Refactor: Folder Hierarquie, Rollback job, refresh setup docs

* Fix: Add rollback to test_dist

* Feature: Add code style check

* Refactor: Improving rollback

* Feature: add clean cache option in local tests

* Fix: code style check

Co-authored-by: Breno Fernandes <brenojesusfernandes@pm.com>
  • Loading branch information
breno-jesus-fernandes and Breno Fernandes authored Jun 15, 2022
1 parent 2eba4d4 commit f2b783c
Show file tree
Hide file tree
Showing 199 changed files with 477 additions and 187 deletions.
106 changes: 54 additions & 52 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,62 @@
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:
runs-on: ubuntu-18.04
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.8', '3.9', '3.10']

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.9"

- name: Cache pip
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run:
python -m pip install -r tests/requirements.txt

- name: Run pyright tests
uses: gramster/pyright-action@main
with:
project: pyrighttestconfig.json
warn-partial: true

- name: Run pytest
run:
pytest tests/pandas

- name: Run mypy
run:
mypy tests/pandas typings/pandas

- name: Build wheel and install and remove typings
run: |
python setup.py build bdist_wheel
find ./dist/*.whl | xargs pip install
rm -rf typings
pip install pyright
- name: Run pyright against dist
uses: gramster/pyright-action@main
with:
project: pyrightdistconfig.json
warn-partial: true

- name: Run mypy against dist
run:
mypy tests/pandas

- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

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

- name: Install Poetry
run: pip install poetry

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

- name: Run MyPy Against Source Code
run: poetry run poe run_mypy_src

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

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

- name: Build Distribution
run: poetry run poe build_dist

- name: Install Distribution
run: poetry run poe install_dist

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

- name: Run Pyright Against Distribution
run: poetry run poe run_pyright_dist

- name: Run MyPy Against Distribution
run: poetry run poe run_mypy_dist
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ dmypy.json

# Pyre type checker
.pyre/
/poetry.lock
.ideia
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ This is the home for pandas typing stubs supported by the pandas core team. The

To contribute changes to the stubs, you must include an appropriate test. See `pandas-stubs/tests` for examples.

## Build instructions
## Documentation

Use `python setup.py build bdist_wheel` to build the wheel. NOTE: `setuptools 62.3.2` is required!
- [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)
- [How to publish](docs/5%20-%20publish.md)

## Evolution

Expand Down
8 changes: 8 additions & 0 deletions docs/1 - setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## 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 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>
15 changes: 15 additions & 0 deletions docs/2 - tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Test

- 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.
5 changes: 5 additions & 0 deletions docs/3 - style.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Code style

- It's important to follow the code style from the project:
- poetry run black pandas-stubs tests scripts
- poetry run isort pandas-stubs tests scripts
3 changes: 3 additions & 0 deletions docs/4 - security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Security

-
3 changes: 3 additions & 0 deletions docs/5 - publish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Publish

You know ... just type "poetry publish pandas-stubs"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
130 changes: 129 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,126 @@
[tool.poetry]
name = "pandas-stubs"
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"
pandas = "1.4.2"
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.poe.tasks.check_style]
help = "Local Code Style Check"
script = "scripts.style:check_style"

[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, clean_cache)"

[[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_src.args]]
help = "remove mypy and pytest cache folders"
name = "clean-cache"
options = ["-c", "--clean_cache"]
default = false

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

[[tool.poe.tasks.test_dist.args]]
help = "remove mypy and pytest cache folders"
name = "clean-cache"
options = ["-c", "--clean_cache"]
default = false

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

[[tool.poe.tasks.test_all.args]]
help = "remove mypy and pytest cache folders"
name = "clean-cache"
options = ["-c", "--clean_cache"]
default = false

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

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

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

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

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

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

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

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

[tool.black]
line_length = 88
target_version = ["py39"]
Expand Down Expand Up @@ -41,7 +164,6 @@ extra_standard_library = [

[tool.mypy]
# Import discovery
mypy_path = "typings"
namespace_packages = false
explicit_package_bases = false
ignore_missing_imports = true
Expand Down Expand Up @@ -86,3 +208,9 @@ strict_equality = true
show_error_context = false
show_column_numbers = false
show_error_codes = true

[tool.pyright]
typeCheckingMode = "basic"
stubPath = "."
include = ["tests", "pandas-stubs"]
useLibraryCodeForTypes = true
4 changes: 0 additions & 4 deletions pyrightdistconfig.json

This file was deleted.

8 changes: 0 additions & 8 deletions pyrighttestconfig.json

This file was deleted.

5 changes: 0 additions & 5 deletions runtests.bat

This file was deleted.

5 changes: 0 additions & 5 deletions runtests.sh

This file was deleted.

28 changes: 28 additions & 0 deletions scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys

from loguru import logger
from pathlib import Path

pkg_path = [x for x in sys.path if x.endswith('site-packages')]

if not Path(fr'{pkg_path[0]}/my_paths.pth').exists():
with open(fr'{pkg_path[0]}/my_paths.pth', 'w') as file:
file.write(str(Path.cwd()))


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

logger.configure(**config)
Loading

0 comments on commit f2b783c

Please sign in to comment.