Skip to content

Commit

Permalink
[path] change most uses of Path.name to Path.base_stem
Browse files Browse the repository at this point in the history
  • Loading branch information
saulpw committed Dec 24, 2023
1 parent 4dc5a94 commit 17fa0b4
Show file tree
Hide file tree
Showing 67 changed files with 101 additions and 103 deletions.
2 changes: 1 addition & 1 deletion bin/viewtsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@VisiData.api
def open_tsv(vd, p):
return MinimalTsvSheet(p.name, source=p)
return MinimalTsvSheet(p.base_stem, source=p)


class MinimalTsvSheet(Sheet):
Expand Down
4 changes: 1 addition & 3 deletions dev/design/path.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ Additions to pathlib.Path:
- adds 'b' to the mode before passing to _open()
- vd.Path.__iter__()
- incorporates Progress() tracking into file reading
- `.base_stem`: filename *without* any extensions

Differences from pathlib.Path:
- `.name`: filename *without* extension
- TODO: change uses of Path.name to Path.stem
- visidata.Path.iterdir returns a list and pathlib.Path.iterdir returns a generator
- `visidata.Path._open()`
- handles uncompressing before passing to pathlib.Path.open()

TODO:
- pathlib.Path has a property suffixes which has a list of the path's file extensions
- change DirSheet owner/group to Path.owner()/group()
- move __iter__ off visidata.Path into global function
4 changes: 2 additions & 2 deletions docs/api/loaders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Step 1. ``open_<filetype>`` boilerplate

@VisiData.api
def open_readme(vd, p):
return ReadmeSheet(p.name, source=p)
return ReadmeSheet(p.base_stem, source=p)

This is used for filetype ``readme``, which is used for files with extension ``.readme``, or when specified manually with the ``filetype`` option like ``--filetype=readme`` or ``-f readme`` on the command line.

Expand Down Expand Up @@ -244,7 +244,7 @@ This is a completely functional loader for the ``sas7bdat`` (SAS dataset file) f

@VisiData.api
def open_sas7bdat(vd, p):
return SasSheet(p.name, source=p)
return SasSheet(p.base_stem, source=p)

class SasSheet(Sheet):
def iterload(self):
Expand Down
6 changes: 3 additions & 3 deletions visidata/_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def openPath(vd, p, filetype=None, create=False):
newfunc = getattr(vd, 'new_' + filetype, vd.getGlobals().get('new_' + filetype))
if not newfunc:
vd.warning('%s does not exist, creating new sheet' % p)
return vd.newSheet(p.name, 1, source=p)
return vd.newSheet(p.base_stem, 1, source=p)

vd.status('creating blank %s' % (p.given))
return newfunc(p)
Expand Down Expand Up @@ -177,8 +177,8 @@ def open_txt(vd, p):
if delimiter and delimiter in next(fp): # peek at the first line
return vd.open_tsv(p) # TSV often have .txt extension
except StopIteration:
return TableSheet(p.name, columns=[SettableColumn()], source=p)
return TextSheet(p.name, source=p)
return TableSheet(p.base_stem, columns=[SettableColumn()], source=p)
return TextSheet(p.base_stem, source=p)


BaseSheet.addCommand('o', 'open-file', 'vd.push(openSource(inputFilename("open: "), create=True))', 'Open file or URL')
Expand Down
2 changes: 1 addition & 1 deletion visidata/apps/vdsql/_ibis.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def open_vdsql(vd, p, filetype=None):
if p.ext in ext_aliases:
setattr(ibis, p.ext, ext_aliases.get(p.ext))

return IbisTableIndexSheet(p.name, source=p, filetype=None, database_name=None,
return IbisTableIndexSheet(p.base_stem, source=p, filetype=None, database_name=None,
ibis_conpool=IbisConnectionPool(p), sheet_type=IbisTableSheet)

vd.open_ibis = vd.open_vdsql
Expand Down
2 changes: 1 addition & 1 deletion visidata/apps/vdsql/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def openurl_bigquery(vd, p, filetype=None):
vd.configure_ibis()
vd.configure_bigquery()
return BigqueryDatabaseIndexSheet(p.name, source=p, ibis_con=None)
return BigqueryDatabaseIndexSheet(p.base_stem, source=p, ibis_con=None)

vd.openurl_bq = vd.openurl_bigquery

Expand Down
2 changes: 1 addition & 1 deletion visidata/apps/vdsql/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@VisiData.api
def openurl_clickhouse(vd, p, filetype=None):
vd.configure_ibis()
return IbisTableIndexSheet(p.name, source=p, filetype=None, database_name=None,
return IbisTableIndexSheet(p.base_stem, source=p, filetype=None, database_name=None,
ibis_conpool=IbisConnectionPool(p), sheet_type=ClickhouseSheet)

vd.openurl_clickhouses = vd.openurl_clickhouse
Expand Down
2 changes: 1 addition & 1 deletion visidata/apps/vdsql/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@VisiData.api
def openurl_snowflake(vd, p, filetype=None):
return IbisTableIndexSheet(p.name, source=p, filetype=None, database_name=None,
return IbisTableIndexSheet(p.base_stem, source=p, filetype=None, database_name=None,
ibis_conpool=IbisConnectionPool(p),
sheet_type=SnowflakeSheet)

Expand Down
2 changes: 1 addition & 1 deletion visidata/apps/vgit/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def open_git(vd, p):

@VisiData.api
def git_repos(vd, p, args):
return GitRepos(p.name, source=p)
return GitRepos(p.base_stem, source=p)


class GitLinesColumn(Column):
Expand Down
2 changes: 1 addition & 1 deletion visidata/apps/vgit/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def remotediff(self):
return self.gitBranchStatuses.get(self.branch, 'no branch')

def iterload(self):
files = [GitFile(p, self.source) for p in self.source.iterdir() if p.name not in ('.git')] # files in working dir
files = [GitFile(p, self.source) for p in self.source.iterdir() if p.base_stem not in ('.git')] # files in working dir

filenames = dict((gf.filename, gf) for gf in files)

Expand Down
4 changes: 2 additions & 2 deletions visidata/cmdlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def queueCommand(vd, longname, input=None, sheet=None, col=None, row=None):

@VisiData.api
def open_vd(vd, p):
return CommandLog(p.name, source=p, precious=True)
return CommandLog(p.base_stem, source=p, precious=True)

@VisiData.api
def open_vdj(vd, p):
return CommandLogJsonl(p.name, source=p, precious=True)
return CommandLogJsonl(p.base_stem, source=p, precious=True)

VisiData.save_vd = VisiData.save_tsv

Expand Down
2 changes: 1 addition & 1 deletion visidata/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def exec_keystrokes(self, keystrokes, vdglobals=None):
@VisiData.api
def filetype(vd, ext, constructor):
'Add constructor to handle the given file type/extension.'
globals().setdefault('open_'+ext, lambda p,ext=ext: constructor(p.name, source=p, filetype=ext))
globals().setdefault('open_'+ext, lambda p,ext=ext: constructor(p.base_stem, source=p, filetype=ext))

@deprecated('2.0', 'Sheet(namepart1, namepart2, ...)')
@VisiData.global_api
Expand Down
2 changes: 1 addition & 1 deletion visidata/experimental/gdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@VisiData.api
def open_gdrive(vd, p):
return GDriveSheet(p.name)
return GDriveSheet(p.base_stem)


FILES_FIELDS_VISIBLE='''name size modifiedTime mimeType description'''.split()
Expand Down
4 changes: 2 additions & 2 deletions visidata/experimental/gsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def open_gsheets(vd, p):
m = re.search(r'([A-z0-9_]{44})', p.given)
if m:
return GSheetsIndex(p.name, source=m.groups()[0])
return GSheetsIndex(p.base_stem, source=m.groups()[0])

vd.open_g = vd.open_gsheets

Expand Down Expand Up @@ -57,7 +57,7 @@ def iterload(self):
@VisiData.api
def save_gsheets(vd, p, *sheets):
gsheet = vd._gsheets_rw.create(body={
'properties': { 'title': p.name },
'properties': { 'title': p.base_stem },
'sheets': list({'properties': { 'title': vs.name }} for vs in sheets),
}, fields='spreadsheetId').execute()

Expand Down
2 changes: 1 addition & 1 deletion visidata/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@VisiData.api
def open_mnu(vd, p):
return FormSheet(p.name, source=p)
return FormSheet(p.base_stem, source=p)


vd.save_mnu=vd.save_tsv
Expand Down
6 changes: 3 additions & 3 deletions visidata/loaders/_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

@VisiData.api
def open_pandas(vd, p):
return PandasSheet(p.name, source=p)
return PandasSheet(p.base_stem, source=p)

@VisiData.api
def open_dta(vd, p):
return PandasSheet(p.name, source=p, filetype='stata')
return PandasSheet(p.base_stem, source=p, filetype='stata')

VisiData.open_stata = VisiData.open_pandas

for ft in 'feather gbq orc pickle sas stata'.split():
funcname ='open_'+ft
if not getattr(VisiData, funcname, None):
setattr(VisiData, funcname, lambda vd,p,ft=ft: PandasSheet(p.name, source=p, filetype=ft))
setattr(VisiData, funcname, lambda vd,p,ft=ft: PandasSheet(p.base_stem, source=p, filetype=ft))

@VisiData.api
@asyncthread
Expand Down
2 changes: 1 addition & 1 deletion visidata/loaders/api_bitio.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def new_bitio(vd, p):
vd.importExternal('bitdotio')
vd.requireOptions('bitio_api_key', help='https://docs.bit.io/docs/connecting-via-the-api')
return BitioReposSheet(p.name, source=p)
return BitioReposSheet(p.base_stem, source=p)

vd.openhttp_bitio = vd.new_bitio

Expand Down
2 changes: 1 addition & 1 deletion visidata/loaders/api_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def openhttp_matrix(vd, p):
vd.setPersistentOptions(matrix_user_id=username, matrix_token=matrix_token)

vd.timeouts_before_idle = -1
return MatrixSheet(p.name, source=p)
return MatrixSheet(p.base_stem, source=p)

vd.open_matrix = vd.openhttp_matrix

Expand Down
6 changes: 3 additions & 3 deletions visidata/loaders/api_reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def open_reddit(vd, p):
return RedditGuide('reddit_guide')

if p.given.startswith('r/') or p.given.startswith('/r/'):
return SubredditSheet(p.name, source=p.name.split('+'), search=(p.given[0]=='/'))
return SubredditSheet(p.base_stem, source=p.base_stem.split('+'), search=(p.given[0]=='/'))

if p.given.startswith('u/') or p.given.startswith('/u/'):
return RedditorsSheet(p.name, source=p.name.split('+'), search=(p.given[0]=='/'))
return RedditorsSheet(p.base_stem, source=p.base_stem.split('+'), search=(p.given[0]=='/'))

return SubredditSheet(p.name, source=p)
return SubredditSheet(p.base_stem, source=p)

vd.new_reddit = vd.open_reddit

Expand Down
4 changes: 2 additions & 2 deletions visidata/loaders/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def guess_tar(vd, p):

@VisiData.api
def open_zip(vd, p):
return vd.ZipSheet(p.name, source=p)
return vd.ZipSheet(p.base_stem, source=p)

@VisiData.api
def open_tar(vd, p):
return TarSheet(p.name, source=p)
return TarSheet(p.base_stem, source=p)

VisiData.open_tgz = VisiData.open_tar
VisiData.open_txz = VisiData.open_tar
Expand Down
4 changes: 2 additions & 2 deletions visidata/loaders/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
@VisiData.api
def open_arrow(vd, p):
'Apache Arrow IPC file format'
return ArrowSheet(p.name, source=p)
return ArrowSheet(p.base_stem, source=p)


@VisiData.api
def open_arrows(vd, p):
'Apache Arrow IPC streaming format'
return ArrowSheet(p.name, source=p)
return ArrowSheet(p.base_stem, source=p)


def arrow_to_vdtype(t):
Expand Down
4 changes: 2 additions & 2 deletions visidata/loaders/conll.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

@VisiData.api
def open_conll(vd, p):
return ConllSheet(p.name, source=p)
return ConllSheet(p.base_stem, source=p)


@VisiData.api
def open_conllu(vd, p):
return ConllSheet(p.name, source=p)
return ConllSheet(p.base_stem, source=p)


class ConllSheet(TableSheet):
Expand Down
2 changes: 1 addition & 1 deletion visidata/loaders/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def guess_csv(vd, p):

@VisiData.api
def open_csv(vd, p):
return CsvSheet(p.name, source=p)
return CsvSheet(p.base_stem, source=p)

def removeNulls(fp):
for line in fp:
Expand Down
2 changes: 1 addition & 1 deletion visidata/loaders/eml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@VisiData.api
def open_eml(vd, p):
return EmailSheet(p.name, source=p)
return EmailSheet(p.base_stem, source=p)

class EmailSheet(TableSheet):
rowtype = 'parts' # rowdef: sub-Messages
Expand Down
2 changes: 1 addition & 1 deletion visidata/loaders/f5log.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,6 @@ def iterload(self):

@VisiData.api
def open_f5log(vd: VisiData, p: Path) -> Sheet:
sheet = F5LogSheet(p.name, source=p)
sheet = F5LogSheet(p.base_stem, source=p)
sheet.options["disp_date_fmt"] = "%Y-%m-%d %H:%M:%S"
return sheet
2 changes: 1 addition & 1 deletion visidata/loaders/fec.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def addSheetRow(component_name):
)

def open_fec(p):
return FECFiling(p.name, source=p)
return FECFiling(p.base_stem, source=p)

addGlobals({
"open_fec": open_fec,
Expand Down
2 changes: 1 addition & 1 deletion visidata/loaders/fixed_width.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@VisiData.api
def open_fixed(vd, p):
return FixedWidthColumnsSheet(p.name, source=p, headerlines=[])
return FixedWidthColumnsSheet(p.base_stem, source=p, headerlines=[])

class FixedWidthColumn(Column):
def __init__(self, name, i, j, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion visidata/loaders/frictionless.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@VisiData.api
def open_frictionless(vd, p):
return FrictionlessIndexSheet(p.name, source=p)
return FrictionlessIndexSheet(p.base_stem, source=p)

class FrictionlessIndexSheet(IndexSheet):
def iterload(self):
Expand Down
2 changes: 1 addition & 1 deletion visidata/loaders/geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@VisiData.api
def open_geojson(vd, p):
return GeoJSONSheet(p.name, source=p)
return GeoJSONSheet(p.base_stem, source=p)

class GeoJSONColumn(Column):
def calcValue(self, row):
Expand Down
2 changes: 1 addition & 1 deletion visidata/loaders/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@VisiData.api
def open_h5(vd, p):
return Hdf5ObjSheet(p.name, source=p)
return Hdf5ObjSheet(p.base_stem, source=p)

VisiData.open_hdf5 = VisiData.open_h5

Expand Down
2 changes: 1 addition & 1 deletion visidata/loaders/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def guess_html(vd, p):

@VisiData.api
def open_html(vd, p):
return HtmlTablesSheet(p.name, source=p)
return HtmlTablesSheet(p.base_stem, source=p)

VisiData.open_htm = VisiData.open_html

Expand Down
2 changes: 1 addition & 1 deletion visidata/loaders/jrnl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@VisiData.api
def open_jrnl(vd, p):
return JrnlSheet(p.name, source=p)
return JrnlSheet(p.base_stem, source=p)


class JrnlSheet(TableSheet):
Expand Down
4 changes: 2 additions & 2 deletions visidata/loaders/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def guess_json(vd, p):

@VisiData.api
def open_jsonobj(vd, p):
return JsonSheet(p.name, source=p)
return JsonSheet(p.base_stem, source=p)

@VisiData.api
def open_jsonl(vd, p):
return JsonSheet(p.name, source=p)
return JsonSheet(p.base_stem, source=p)

VisiData.open_ndjson = VisiData.open_ldjson = VisiData.open_json = VisiData.open_jsonl

Expand Down
2 changes: 1 addition & 1 deletion visidata/loaders/jsonla.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def guess_jsonla(vd, p):

@VisiData.api
def open_jsonla(vd, p):
return JsonlArraySheet(p.name, source=p)
return JsonlArraySheet(p.base_stem, source=p)


class JsonlArraySheet(SequenceSheet):
Expand Down
2 changes: 1 addition & 1 deletion visidata/loaders/lsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@VisiData.api
def open_lsv(vd, p):
return LsvSheet(p.name, source=p)
return LsvSheet(p.base_stem, source=p)


@VisiData.api
Expand Down
Loading

0 comments on commit 17fa0b4

Please sign in to comment.