Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore(Python): Centralize Python dependencies in pyproject.toml #9535

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
fa78cd7
Store deps inside pyproject.toml
zundertj Jun 19, 2023
5db77c5
Add option to specify tags + update GH workflows
zundertj Jun 24, 2023
e9acf10
Fix typo in script name
zundertj Jun 24, 2023
4c299b1
Fix formatting
zundertj Jun 24, 2023
302b719
Move tomllib import behind Python version clause
zundertj Jun 24, 2023
9a57b55
Resolve polars tags properly
zundertj Jun 24, 2023
e4bdbbe
Fix python 3.7 type annotations
zundertj Jun 24, 2023
6a1a8bb
Fix various errors
zundertj Jun 24, 2023
e24c9d5
Fix Python 3.7 type annotations
zundertj Jun 24, 2023
9f825ce
Fix tomli package name
zundertj Jun 24, 2023
ab0e672
Add adbc dependency
zundertj Jun 24, 2023
2bd2c7f
Fix connectorx version
zundertj Jun 24, 2023
e9aeacc
Fix SQLAlchemy typing bug
zundertj Jun 24, 2023
4724c0a
Move docs requirements to pyproject.toml
zundertj Jun 24, 2023
a3287d0
Fix connectorx python version
zundertj Jun 24, 2023
28755be
Fix pyproject.toml formatting
zundertj Jun 24, 2023
b3a0471
Add hypothesis to doc deps
zundertj Jun 24, 2023
5a42edc
Add missing dependencies to doc tag
zundertj Jun 24, 2023
cb5713e
Improve doc tags
zundertj Jun 24, 2023
b8c41a0
DRY hypothesis
zundertj Jun 24, 2023
c15e9f1
Rename tag dev to dev-test
zundertj Jun 24, 2023
b6194d1
Clean up parser
zundertj Jun 24, 2023
ac59a26
Simplify code in script
zundertj Jun 24, 2023
ef10a2a
Use maturin develop extras flag
zundertj Jun 25, 2023
1b1738b
Fix
zundertj Jun 25, 2023
ee2d68e
Remove custom script
zundertj Jun 25, 2023
83314bf
Install maturin with pip
zundertj Jun 26, 2023
f616736
Fix pip install command
zundertj Jun 26, 2023
c738a61
Fix yaml
zundertj Jun 26, 2023
1f10618
Avoid polars all tag.
zundertj Jul 1, 2023
f053d1c
Activate .venv, otherwise maturin fails
zundertj Jul 1, 2023
3934dfe
Update
zundertj Jul 1, 2023
1715549
Update
zundertj Jul 1, 2023
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
14 changes: 13 additions & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,21 @@ jobs:
python -m venv .venv
echo "$GITHUB_WORKSPACE/py-polars/.venv/bin" >> $GITHUB_PATH

- name: Set up Rust
run: rustup show

- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: py-polars
save-if: ${{ github.ref_name == 'main' }}

- name: Install Python dependencies
working-directory: py-polars
run: pip install -r requirements-dev.txt
run: |
source activate
pip install maturin==1.0.1
maturin develop --extras dev-test,pyarrow,pandas,fsspec,timezone,connectorx,adbc,numpy,hypothesis,xlsxwriter,xlsx2csv,deltalake,pydantic

- name: Load benchmark data from cache
id: cache-data
Expand Down
23 changes: 20 additions & 3 deletions .github/workflows/docs-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,28 @@ jobs:
with:
python-version: '3.11'
cache: pip
cache-dependency-path: py-polars/docs/requirements-docs.txt
cache-dependency-path: py-polars/pyproject.toml

- name: Create virtual environment
run: |
python -m venv .venv
echo "$GITHUB_WORKSPACE/py-polars/.venv/bin" >> $GITHUB_PATH

- name: Set up Rust
run: rustup show

- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: py-polars
save-if: ${{ github.ref_name == 'main' }}

- name: Install Python dependencies
working-directory: py-polars/docs
run: pip install -r requirements-docs.txt
working-directory: py-polars
run: |
source $GITHUB_WORKSPACE/py-polars/.venv/Scripts/activate
pip install maturin==1.0.1
maturin develop --extras dev-docs

- name: Build Python documentation
working-directory: py-polars/docs
Expand Down
38 changes: 35 additions & 3 deletions .github/workflows/lint-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,25 @@ jobs:
with:
python-version: '3.11'

- name: Create virtual environment
run: |
python -m venv .venv
echo "$GITHUB_WORKSPACE/py-polars/.venv/bin" >> $GITHUB_PATH

- name: Set up Rust
run: rustup show

- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: py-polars
save-if: ${{ github.ref_name == 'main' }}

- name: Install Python dependencies
run: pip install -r requirements-lint.txt
run: |
source activate
pip install maturin==1.0.1
maturin develop --extras dev-lint

- name: Lint Python
run: |
Expand All @@ -52,10 +69,25 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Create virtual environment
run: |
python -m venv .venv
echo "$GITHUB_WORKSPACE/py-polars/.venv/bin" >> $GITHUB_PATH

- name: Set up Rust
run: rustup show

- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: py-polars
save-if: ${{ github.ref_name == 'main' }}

- name: Install dependencies
run: |
pip install -r requirements-dev.txt
pip install -r requirements-lint.txt
source activate
pip install maturin==1.0.1
maturin develop --extras dev-test,dev-lint,pyarrow,pandas,fsspec,timezone,connectorx,adbc,numpy,hypothesis,xlsxwriter,xlsx2csv,deltalake,pydantic

# Allow untyped calls for older Python versions
- name: Run mypy
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ jobs:
python -m venv .venv
echo "$GITHUB_WORKSPACE/py-polars/.venv/bin" >> $GITHUB_PATH

- name: Install dependencies
run: pip install -r requirements-dev.txt

- name: Set up Rust
run: rustup show

Expand All @@ -61,7 +58,9 @@ jobs:
- name: Install Polars
run: |
source activate
maturin develop
pip install maturin==1.0.1
# the list of tags should be in sync with the Makefile
maturin develop --extras dev-test,pyarrow,pandas,fsspec,timezone,connectorx,adbc,numpy,hypothesis,xlsxwriter,xlsx2csv,deltalake,pydantic

- name: Run tests and report coverage
if: github.ref_name != 'main'
Expand Down Expand Up @@ -105,9 +104,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
run: pip install -r requirements-dev.txt

- name: Set up Rust
run: rustup show

Expand All @@ -120,8 +116,9 @@ jobs:
- name: Install Polars
shell: bash
run: |
maturin build
pip install target/wheels/polars-*.whl
source activate
pip install maturin==1.0.1
maturin develop --extras dev-test,pyarrow,pandas,fsspec,timezone,connectorx,adbc,numpy,hypothesis,xlsxwriter,xlsx2csv,deltalake,pydantic

- name: Run tests
if: github.ref_name != 'main'
Expand Down
13 changes: 8 additions & 5 deletions py-polars/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@ endif
.PHONY: requirements
requirements: .venv ## Install/refresh all project requirements
$(VENV_BIN)/python -m pip install --upgrade pip
$(VENV_BIN)/pip install -r requirements-dev.txt
$(VENV_BIN)/pip install -r requirements-lint.txt
$(VENV_BIN)/pip install -r docs/requirements-docs.txt
$(VENV_BIN)/python -m pip install maturin==1.0.1

.PHONY: build
build: .venv ## Compile and install Polars for development
@unset CONDA_PREFIX && source $(VENV_BIN)/activate && maturin develop
# NOTE: ideally, we can use the all tag available in pyproject.toml, but that has
# the form of "polars[pandas,...]". Pip incorrectly parses that as using the released
# polars version, rather than self referencing. So we avoid the all tag here.
# @unset CONDA_PREFIX && source $(VENV_BIN)/activate && maturin develop --extras all,dev-test,dev-lint,dev-docs
@unset CONDA_PREFIX && source $(VENV_BIN)/activate && maturin develop --extras pyarrow,pandas,fsspec,timezone,connectorx,adbc,numpy,hypothesis,xlsxwriter,xlsx2csv,deltalake,pydantic,dev-test,dev-lint,dev-docs


.PHONY: build-release
build-release: .venv ## Compile and install a faster Polars binary
@unset CONDA_PREFIX && source $(VENV_BIN)/activate && maturin develop --release

.PHONY: fmt
fmt: .venv ## Run autoformatting and linting
fmt: .venv build ## Run autoformatting and linting
$(VENV_BIN)/ruff .
$(VENV_BIN)/black .
$(VENV_BIN)/blackdoc .
Expand Down
1 change: 1 addition & 0 deletions py-polars/bla.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world, oh no, polars
26 changes: 0 additions & 26 deletions py-polars/docs/requirements-docs.txt

This file was deleted.

4 changes: 2 additions & 2 deletions py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3167,12 +3167,12 @@ def write_database(
"'sqlalchemy' not found. Install polars with 'pip install polars[sqlalchemy]'."
) from exc

engine = create_engine(connection_uri)
engine_sa = create_engine(connection_uri)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mypy complians (rightly so) when SQL Alchemy is installed.


# this conversion to pandas as zero-copy
# so we can utilize their sql utils for free
self.to_pandas(use_pyarrow_extension_array=True).to_sql(
name=table_name, con=engine, if_exists=if_exists, index=False
name=table_name, con=engine_sa, if_exists=if_exists, index=False
)

else:
Expand Down
3 changes: 3 additions & 0 deletions py-polars/polars/utils/show_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ def _get_dependency_info() -> dict[str, str]:
"matplotlib",
"xlsx2csv",
"xlsxwriter",
"sqlalchemy",
"pydantic",
]

return {f"{name}:": _get_dependency_version(name) for name in opt_deps}


Expand Down
45 changes: 42 additions & 3 deletions py-polars/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,54 @@ pyarrow = ["pyarrow>=7.0.0"]
pandas = ["pyarrow>=7.0.0", "pandas"]
numpy = ["numpy >= 1.16.0"]
fsspec = ["fsspec"]
connectorx = ["connectorx"]
connectorx = [
"connectorx >= 0.3.2a5; python_version >= '3.8'",
] # Latest full release is broken - unpin when 0.3.2 released
xlsx2csv = ["xlsx2csv >= 0.8.0"]
deltalake = ["deltalake >= 0.8.0"]
deltalake = ["deltalake >= 0.10.0"]
timezone = ["backports.zoneinfo; python_version < '3.9'", "tzdata; platform_system == 'Windows'"]
matplotlib = ["matplotlib"]
sqlalchemy = ["sqlalchemy", "pandas"]
xlsxwriter = ["xlsxwriter"]
pydantic = ["pydantic"]
hypothesis = ["hypothesis==6.75.1"]
adbc = ["adbc_driver_sqlite; python_version >= '3.9' and platform_system != 'Windows'"]
all = [
"polars[pyarrow,pandas,numpy,fsspec,connectorx,xlsx2csv,deltalake,timezone,matplotlib,sqlalchemy,xlsxwriter]",
"polars[pyarrow,pandas,numpy,fsspec,connectorx,xlsx2csv,deltalake,timezone,matplotlib,sqlalchemy,adbc,xlsxwriter,pydantic]",
]

# The tags below are for development of Polars. We pin precise versions here, as we have full control on this
dev-test = [
"pytest==7.3.0",
"pytest-cov==4.1.0",
"pytest-xdist==3.3.1",
]
dev-lint = [
"black==23.3.0",
"blackdoc==0.3.8",
"mypy==1.3.0",
"ruff==0.0.270",
"typos==1.15",
"pandas-stubs==1.2.0.62",
]
dev-docs = [
"autodocsumm==0.2.10",
"commonmark==0.9.1",
"livereload==2.6.3",
"numpydoc==1.5.0",
"pydata-sphinx-theme==0.13.3",
"sphinx==6.2.1",
"sphinx-autosummary-accessors==2023.4.0",
"sphinx-copybutton==0.5.1",
"sphinx-design==0.4.1",
"sphinx-favicon==1.0.1",
"sphinxcontrib-applehelp==1.0.4",
"sphinxcontrib-devhelp==1.0.2",
"sphinxcontrib-htmlhelp==2.0.1",
"sphinxcontrib-jsmath==1.0.1",
"sphinxcontrib-napoleon==0.7",
"sphinxcontrib-qthelp==1.0.3",
"sphinxcontrib-serializinghtml==1.1.5",
]

[tool.mypy]
Expand Down
29 changes: 0 additions & 29 deletions py-polars/requirements-dev.txt

This file was deleted.

5 changes: 0 additions & 5 deletions py-polars/requirements-lint.txt

This file was deleted.