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

refactor: Use pathlib in tools/ #14218

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions tools/release
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@ from __future__ import print_function

import os
from glob import glob
from pathlib import Path
from subprocess import call
import sys

from toollib import (get_ipdir, pjoin, cd, execfile, sh, archive,
from toollib import (get_ipdir, cd, execfile, sh, archive,
archive_user, archive_dir)

# Get main ipython dir, this will raise if it doesn't pass some checks
ipdir = get_ipdir()
tooldir = pjoin(ipdir, 'tools')
distdir = pjoin(ipdir, 'dist')
tooldir = ipdir / 'tools'
distdir = ipdir / 'dist'

# Where I keep static backups of each release
ipbackupdir = os.path.expanduser('~/ipython/backup')
if not os.path.exists(ipbackupdir):
os.makedirs(ipbackupdir)
ipbackupdir = Path('~/ipython/backup').expanduser()
if not ipbackupdir.exists():
ipbackupdir.mkdir(parents=True, exist_ok=True)

# Start in main IPython dir
cd(ipdir)

# Load release info
version = None
execfile(pjoin('IPython','core','release.py'), globals())
execfile(Path('IPython','core','release.py'), globals())

# Build site addresses for file uploads
release_site = '%s/release/%s' % (archive, version)
Expand Down
12 changes: 6 additions & 6 deletions tools/toollib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import os
import sys

from pathlib import Path

# Useful shorthands
pjoin = os.path.join
cd = os.chdir

# Constants
Expand Down Expand Up @@ -34,13 +35,12 @@ def get_ipdir():
"""Get IPython directory from command line, or assume it's the one above."""

# Initialize arguments and check location
ipdir = pjoin(os.path.dirname(__file__), os.pardir)

ipdir = os.path.abspath(ipdir)
ipdir = Path(__file__).parent / os.pardir
ipdir = ipdir.resolve()

cd(ipdir)
if not os.path.isdir('IPython') and os.path.isfile('setup.py'):
raise SystemExit('Invalid ipython directory: %s' % ipdir)
if not Path("IPython").is_dir() and Path("setup.py").is_file():
raise SystemExit("Invalid ipython directory: %s" % ipdir)
return ipdir

def execfile(fname, globs, locs=None):
Expand Down