Skip to content

Commit

Permalink
Revert "Merge branch 'master' into refactor/spreadsheet-open-metadata"
Browse files Browse the repository at this point in the history
This reverts commit ec91e3a, reversing
changes made to 0954e3b.
  • Loading branch information
alifeee committed Aug 16, 2023
1 parent ec91e3a commit e4b474a
Show file tree
Hide file tree
Showing 96 changed files with 12,652 additions and 37,494 deletions.
15 changes: 0 additions & 15 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,3 @@ This will mostly result in a lot of updated files in `tests/cassettes/`. Don't f
Please add them in a dedicated commit, in order to make the review process easier.

Afterwards, remember to [run the tests in offline mode](#run-tests-offline) to make sure you have recorded everything correctly.

## Release

Old release notes are [here](https://gist.github.com/burnash/335f977a74b8bfdc7968).

New release system:

- Update version number in [`gspread/__init__.py`](../gspread/__init__.py).
- Get changelog from drafting a new [GitHub release](https://github.com/burnash/gspread/releases/new) (do not publish, instead cancel.)
- Add changelog to [`HISTORY.rst`](../HISTORY.rst).
- Commit the changes as `Release vX.Y.Z` (do not push yet.)
- Run `tox -e lint,py,build,doc` to check build/etc.
- Push the commit. Wait for the CI to pass.
- Add a tag `vX.Y.Z` to the commit locally. This will trigger a new release on PyPi, and make a release on GitHub.
- View the release on [GitHub](https://github.com/burnash/gspread/releases) and [PyPi](https://pypi.org/project/gspread/)!
25 changes: 0 additions & 25 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
Release History
===============

5.10.0 (2023-06-29)
------------------

* Fix rows_auto_resize in worksheet.py by removing redundant self by @MagicMc23 in https://github.com/burnash/gspread/pull/1194
* Add deprecation warning for future release 6.0.x by @lavigne958 in https://github.com/burnash/gspread/pull/1195
* FEATURE: show/hide gridlines (#1197) by @alifeee in https://github.com/burnash/gspread/pull/1202
* CLEANUP: cleanup tox.ini, and ignore ./env by @alifeee in https://github.com/burnash/gspread/pull/1200
* Refactor/update-contributing-guide by @alifeee in https://github.com/burnash/gspread/pull/1206
* Spelling fix (with legacy option) by @alifeee in https://github.com/burnash/gspread/pull/1210
* 457-fetch-without-hidden-worksheets by @alifeee in https://github.com/burnash/gspread/pull/1207
* Add_deprecated_warning_sort_method by @lavigne958 in https://github.com/burnash/gspread/pull/1198
* Update (and test for) internal properties on change by @alifeee in https://github.com/burnash/gspread/pull/1211
* Feature: Add "Remove tab colour" method by @alifeee in https://github.com/burnash/gspread/pull/1199
* Refresh-test-cassettes by @alifeee in https://github.com/burnash/gspread/pull/1217
* update self._properties after batch_update by @alifeee in https://github.com/burnash/gspread/pull/1221
* 700-fill-merged-cells by @alifeee in https://github.com/burnash/gspread/pull/1215
* Fix/update-internal-properties by @alifeee in https://github.com/burnash/gspread/pull/1225
* Add breaking change warning in Worksheet.update() by @lavigne958 in https://github.com/burnash/gspread/pull/1226
* Bump codespell from 2.2.4 to 2.2.5 by @dependabot in https://github.com/burnash/gspread/pull/1232
* Add/refresh last update time by @alifeee in https://github.com/burnash/gspread/pull/1233
* Update-build-tools by @alifeee in https://github.com/burnash/gspread/pull/1231
* add read the doc configuration file by @lavigne958 in https://github.com/burnash/gspread/pull/1235
* update licence year by @alifeee in https://github.com/burnash/gspread/pull/1237
* remove deprecated methods from tests by @alifeee in https://github.com/burnash/gspread/pull/1238

5.9.0 (2023-05-11)
------------------

Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Google Spreadsheets Python API v4

![main workflow](https://img.shields.io/github/actions/workflow/status/burnash/gspread/main.yaml?logo=github)
![github license](https://img.shields.io/pypi/l/gspread?logo=github)
![latest download](https://img.shields.io/github/downloads-pre/burnash/gspread/latest/total?logo=github)
![documentation](https://img.shields.io/readthedocs/gspread?logo=readthedocs)
![pypi download](https://img.shields.io/pypi/dm/gspread?logo=pypi)
![pypi version](https://img.shields.io/pypi/v/gspread?logo=pypi)
![python version](https://img.shields.io/pypi/pyversions/gspread?style=pypi)
![latest workflow](https://github.com/burnash/gspread/actions/workflows/main.yaml/badge.svg?branch=master)
[![GitHub version](https://badge.fury.io/gh/burnash%2Fgspread.svg)](https://badge.fury.io/gh/burnash%2Fgspread)
![PyPi]( https://badge.fury.io/py/gspread.svg)
![downloads](https://img.shields.io/pypi/dm/gspread.svg)
![doc](https://readthedocs.org/projects/gspread/badge/?version=latest)

Simple interface for working with Google Sheets.

Expand Down
2 changes: 1 addition & 1 deletion gspread/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Google Spreadsheets Python API"""

__version__ = "5.10.0"
__version__ = "6.0.0"
__author__ = "Anton Burnashev"


Expand Down
61 changes: 0 additions & 61 deletions gspread/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,67 +39,6 @@ def __init__(
) -> None:
self.http_client = http_client(auth)

self.timeout = None

def login(self):
from google.auth.transport.requests import Request

self.auth.refresh(Request(self.session))

self.session.headers.update({"Authorization": "Bearer %s" % self.auth.token})

def set_timeout(self, timeout):
"""How long to wait for the server to send
data before giving up, as a float, or a ``(connect timeout,
read timeout)`` tuple.
Value for ``timeout`` is in seconds (s).
"""
self.timeout = timeout

def request(
self,
method,
endpoint,
params=None,
data=None,
json=None,
files=None,
headers=None,
):
response = getattr(self.session, method)(
endpoint,
json=json,
params=params,
data=data,
files=files,
headers=headers,
timeout=self.timeout,
)

if response.ok:
return response
else:
raise APIError(response)

def get_file_drive_metadata(self, id):
"""Get the metadata from the Drive API for a specific file
This method is mainly here to retrieve the create/update time
of a file (these metadata are only accessible from the Drive API).
"""

url = DRIVE_FILES_API_V3_URL + "/{}".format(id)

params = {
"supportsAllDrives": True,
"includeItemsFromAllDrives": True,
"fields": "id,name,createdTime,modifiedTime",
}

res = self.request("get", url, params=params)

return res.json()

def list_spreadsheet_files(
self, title: Optional[str] = None, folder_id: Optional[str] = None
) -> Tuple[List[Dict[str, Any]], Response]:
Expand Down
65 changes: 21 additions & 44 deletions gspread/spreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
"""

import warnings
from typing import Union

from .exceptions import WorksheetNotFound
from .urls import DRIVE_FILES_API_V3_URL, SPREADSHEET_DRIVE_URL
from .utils import ExportFormat, finditem
Expand All @@ -25,9 +22,6 @@ def __init__(self, http_client, properties):
metadata = self.fetch_sheet_metadata()
self._properties.update(metadata["properties"])

drive_metadata = self.client.get_file_drive_metadata(self._properties["id"])
self._properties.update(drive_metadata)

@property
def id(self):
"""Spreadsheet ID."""
Expand All @@ -46,20 +40,21 @@ def url(self):
@property
def creationTime(self):
"""Spreadsheet Creation time."""
return self._properties["createdTime"]
try:
return self._properties["createdTime"]
except KeyError:
metadata = self.client._get_file_drive_metadata(self.id)
self._properties.update(metadata)
return self._properties["createdTime"]

@property
def lastUpdateTime(self):
"""Spreadsheet last updated time.
Only updated on initialisation.
For actual last updated time, use get_lastUpdateTime()."""
warnings.warn(
"""
This is only updated on initialisation and is probably outdated by the time you use it.
For an up to date last updated time, use get_lastUpdateTime().
"""
)
return self._properties["modifiedTime"]
"""Spreadsheet last updated time."""
try:
return self._properties["modifiedTime"]
except KeyError:
self.refresh_lastUpdateTime()
return self._properties["modifiedTime"]

@property
def timezone(self):
Expand Down Expand Up @@ -233,11 +228,11 @@ def get_worksheet(self, index):
except (KeyError, IndexError):
raise WorksheetNotFound("index {} not found".format(index))

def get_worksheet_by_id(self, id: Union[str, int]):
def get_worksheet_by_id(self, id):
"""Returns a worksheet with specified `worksheet id`.
:param id: The id of a worksheet. it can be seen in the url as the value of the parameter 'gid'.
:type id: str | int
:type id: int
:returns: an instance of :class:`gspread.worksheet.Worksheet`.
:raises:
Expand All @@ -250,19 +245,14 @@ def get_worksheet_by_id(self, id: Union[str, int]):
"""
sheet_data = self.fetch_sheet_metadata()

try:
worksheet_id_int = int(id)
except ValueError as ex:
raise ValueError("id should be int") from ex

try:
item = finditem(
lambda x: x["properties"]["sheetId"] == worksheet_id_int,
lambda x: x["properties"]["sheetId"] == id,
sheet_data["sheets"],
)
return Worksheet(self.id, self.client, item["properties"])
except (StopIteration, KeyError):
raise WorksheetNotFound("id {} not found".format(worksheet_id_int))
raise WorksheetNotFound("id {} not found".format(id))

def worksheets(self, exclude_hidden: bool = False):
"""Returns a list of all :class:`worksheets <gspread.worksheet.Worksheet>`
Expand Down Expand Up @@ -399,16 +389,12 @@ def del_worksheet(self, worksheet):

return self.client.batch_update(self.id, body)

def del_worksheet_by_id(self, worksheet_id: Union[str, int]):
def del_worksheet_by_id(self, worksheet_id: str):
"""
Deletes a Worksheet by id
"""
try:
worksheet_id_int = int(worksheet_id)
except ValueError as ex:
raise ValueError("id should be int") from ex

body = {"requests": [{"deleteSheet": {"sheetId": worksheet_id_int}}]}
body = {"requests": [{"deleteSheet": {"sheetId": worksheet_id}}]}

return self.client.batch_update(self.id, body)

Expand Down Expand Up @@ -709,16 +695,7 @@ def list_protected_ranges(self, sheetid):

return sheet.get("protectedRanges", [])

def refresh_lastUpdateTime(self) -> None:
"""Updates the cached value of lastUpdateTime."""
# remove this and the below upon deprecation of lastUpdateTime @property
self._properties["modifiedTime"] = self.get_lastUpdateTime()

def get_lastUpdateTime(self) -> str:
"""Get the lastUpdateTime metadata from the Drive API.
Also updates the cached value in the _properties dict.
"""
metadata = self.client.get_file_drive_metadata(self.id)
# remove next line and the above upon deprecation of lastUpdateTime @property
def refresh_lastUpdateTime(self):
"""Refresh the lastUpdateTime property of the spreadsheet."""
metadata = self.client._get_file_drive_metadata(self.id)
self._properties["modifiedTime"] = metadata["modifiedTime"]
return metadata["modifiedTime"]
23 changes: 0 additions & 23 deletions gspread/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,29 +560,6 @@ def rightpad(row: List[Any], max_len: int) -> List[Any]:
def fill_gaps(
L: List[List[Any]], rows: Optional[int] = None, cols: Optional[int] = None
) -> List[List[Any]]:
"""Fill gaps in a list of lists.
e.g.,::
>>> L = [
... [1, 2, 3],
... ]
>>> fill_gaps(L, 2, 4)
[
[1, 2, 3, ""],
["", "", "", ""]
]
:param L: List of lists to fill gaps in.
:param rows: Number of rows to fill.
:param cols: Number of columns to fill.
:type L: list[list[T]]
:type rows: int
:type cols: int
:return: List of lists with gaps filled.
:rtype: list[list[T]]:
"""
try:
max_cols = max(len(row) for row in L) if cols is None else cols
max_rows = len(L) if rows is None else rows
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ classifiers = [
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Development Status :: 5 - Production/Stable",
Expand Down
Loading

0 comments on commit e4b474a

Please sign in to comment.