Skip to content

Commit 88b277b

Browse files
authored
Merge pull request #115 from lsst/tickets/DM-38499
DM-38499: Clean up package and change to run flake8/ruff
2 parents cba24d1 + 06f6162 commit 88b277b

File tree

29 files changed

+947
-633
lines changed

29 files changed

+947
-633
lines changed

.github/workflows/build.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,38 @@ jobs:
1111
strategy:
1212
matrix:
1313
os: [ubuntu-latest, macos-latest]
14+
pyversion: ["3.10", "3.11"]
1415

1516
runs-on: ${{ matrix.os }}
1617
steps:
1718
- uses: actions/checkout@v3
1819

1920
- uses: conda-incubator/setup-miniconda@v2
2021
with:
21-
python-version: 3.8
22+
python-version: ${{ matrix.pyversion }}
23+
auto-update-conda: true
2224
channels: conda-forge,defaults
25+
miniforge-variant: Mambaforge
26+
use-mamba: true
2327
channel-priority: strict
2428
show-channel-urls: true
2529

2630
- name: Install conda packages used by this package
2731
shell: bash -l {0}
2832
run: |
29-
conda install mamba
30-
mamba install -y -q scons eups compilers
33+
mamba install -y -q scons eups compilers ruff flake8
3134
3235
# We have two cores so we can speed up the testing with xdist
3336
- name: Install pytest packages
3437
shell: bash -l {0}
3538
run: |
3639
mamba install -y -q \
37-
"flake8<5" \
38-
pytest pytest-flake8 pytest-xdist pytest-openfiles pytest-cov pytest-session2file
40+
pytest pytest-xdist pytest-openfiles pytest-cov pytest-session2file
3941
4042
- name: List installed packages
4143
shell: bash -l {0}
4244
run: |
43-
conda list
45+
mamba list
4446
pip list -v
4547
4648
- name: Build and test

.github/workflows/formatting.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Check Python formatting
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
call-workflow:
11+
uses: lsst/rubin_workflows/.github/workflows/formatting.yaml@main

.pre-commit-config.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: check-toml
6+
- id: check-yaml
7+
args:
8+
- "--unsafe"
9+
- id: end-of-file-fixer
10+
- id: trailing-whitespace
11+
- repo: https://github.com/psf/black
12+
rev: 23.1.0
13+
hooks:
14+
- id: black
15+
# It is recommended to specify the latest version of Python
16+
# supported by your project here, or alternatively use
17+
# pre-commit's default_language_version, see
18+
# https://pre-commit.com/#top_level-default_language_version
19+
language_version: python3.11
20+
- repo: https://github.com/pycqa/isort
21+
rev: 5.12.0
22+
hooks:
23+
- id: isort
24+
name: isort (python)
25+
- repo: https://github.com/astral-sh/ruff-pre-commit
26+
# Ruff version.
27+
rev: v0.0.275
28+
hooks:
29+
- id: ruff

SConstruct

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# Setup our environment
44
#
55
import sys
6-
sys.path = ["python"] + sys.path # ensure that we use our copy of sconsUtils
6+
7+
sys.path = ["python"] + sys.path # ensure that we use our copy of sconsUtils
78
from lsst.sconsUtils import scripts
89

910
scripts.BasicSConstruct.initialize(packageName="sconsUtils")

bin.src/SConscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# -*- python -*-
22
from lsst.sconsUtils import scripts
3+
34
scripts.BasicSConscript.shebang()

bin.src/makeLinkFarm

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
#!/usr/bin/env python
22

3-
from __future__ import print_function
3+
44
import argparse
55
import os
66
import sys
7+
78
import eups
89

910

1011
def linkFiles(dstDir, srcDir, verbose=0, force=False):
11-
"""Link all the regular files in srcDir into dstDir; mkdir all the directories in srcDir and
12-
descend recursively"""
12+
"""Link all the regular files in srcDir into dstDir; mkdir all the
13+
directories in srcDir and descend recursively"""
1314

1415
if not os.path.exists(dstDir):
1516
os.makedirs(dstDir)
@@ -22,40 +23,42 @@ def linkFiles(dstDir, srcDir, verbose=0, force=False):
2223
linkFiles(fullDst, fullSrc, verbose, force)
2324
else:
2425
if verbose > 1:
25-
print("%s -> %s" % (fullSrc, fullDst))
26+
print(f"{fullSrc} -> {fullDst}")
2627

2728
if os.path.exists(fullDst):
2829
if force:
2930
os.unlink(fullDst)
3031
else:
31-
print("%s already exists; use --force to overwrite" % fullDst, file=sys.stderr)
32+
print(f"{fullDst} already exists; use --force to overwrite", file=sys.stderr)
3233
sys.exit(1)
3334

3435
os.symlink(fullSrc, fullDst)
3536

3637

3738
def main():
38-
parser = argparse.ArgumentParser(description='''Build a link farm to replace long -I/-L argument lists.
39+
parser = argparse.ArgumentParser(
40+
description="""Build a link farm to replace long -I/-L argument lists.
3941
All the bin, include files, and libraries for all the dependencies of the specified product are linked into
4042
linkFarmDir/bin, linkFarmDir/include, or linkFarmDir/lib
4143
as appropriate. Note that the setup dependencies are used, so you can say e.g.
4244
$ setup pipe_tasks
4345
$ setup -r ~/LSST/afw
4446
$ makeLinkFarm /tmp/linkFarm pipe_tasks
4547
creates a link farm for your current selection of products.
46-
''')
47-
parser.add_argument('linkFarmDir', type=str, help='The directory to setup as a link farm')
48-
parser.add_argument('productName', type=str, help='The desired product (must be setup)')
48+
"""
49+
)
50+
parser.add_argument("linkFarmDir", type=str, help="The directory to setup as a link farm")
51+
parser.add_argument("productName", type=str, help="The desired product (must be setup)")
4952

50-
parser.add_argument('--force', '-f', action='store_true', help="Force creation of farm even if it exists")
51-
parser.add_argument('--verbose', '-v', action='count', help="Be chatty")
53+
parser.add_argument("--force", "-f", action="store_true", help="Force creation of farm even if it exists")
54+
parser.add_argument("--verbose", "-v", action="count", help="Be chatty")
5255

5356
args = parser.parse_args()
5457

5558
linkFarmDir = os.path.abspath(args.linkFarmDir)
5659

5760
if not args.force and os.path.exists(linkFarmDir):
58-
print("Path %s already exists; use --force to overwrite" % args.linkFarmDir, file=sys.stderr)
61+
print(f"Path {args.linkFarmDir} already exists; use --force to overwrite", file=sys.stderr)
5962
sys.exit(1)
6063

6164
#
@@ -67,25 +70,25 @@ creates a link farm for your current selection of products.
6770
os.makedirs(d)
6871

6972
products = {}
70-
for productName, versionName, optional, recursionDepth in \
71-
eups.getDependencies(args.productName, None, setup=True):
73+
for productName, versionName, optional, recursionDepth in eups.getDependencies(
74+
args.productName, None, setup=True
75+
):
7276
if productName in products:
7377
continue
7478

7579
products[productName] = 1
7680

7781
pd = eups.productDir(productName)
78-
if not pd: # no product
82+
if not pd: # no product
7983
continue
8084

8185
binDir = os.path.join(pd, "bin")
8286
incDir = os.path.join(pd, "include")
8387
libDir = os.path.join(pd, "lib")
8488

8589
if args.verbose:
86-
if args.verbose > 1 or \
87-
os.path.exists(binDir) or os.path.exists(incDir) or os.path.exists(libDir):
88-
print("%-15s %s" % (productName, pd))
90+
if args.verbose > 1 or os.path.exists(binDir) or os.path.exists(incDir) or os.path.exists(libDir):
91+
print(f"{productName:<15} {pd}")
8992

9093
if os.path.exists(binDir):
9194
fullDstDir = os.path.join(linkFarmDir, "bin")
@@ -108,7 +111,7 @@ creates a link farm for your current selection of products.
108111
if args.force:
109112
os.unlink(fullDst)
110113
else:
111-
print("%s already exists; use --force to overwrite" % fullDst, file=sys.stderr)
114+
print(f"{fullDst} already exists; use --force to overwrite", file=sys.stderr)
112115
sys.exit(1)
113116

114117
os.symlink(fullSrc, fullDst)

bin.src/sconsOpts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,20 @@
22
#
33
# Print the options last passed to scons
44
#
5-
from __future__ import print_function
5+
import argparse
6+
import configparser
67
import os
78
import sys
8-
import argparse
9-
try:
10-
import configparser
11-
except ImportError:
12-
import ConfigParser as configparser
139

1410
parser = argparse.ArgumentParser(description="Tell us how scons was invoked")
15-
parser.add_argument('configFile', type=str, nargs="?", default=None,
16-
help='The file with the information we need')
17-
parser.add_argument('--cc', type=str, default="gcc",
18-
help="Use this compiler if build.cfg is unavailable")
19-
parser.add_argument('--opt', type=int, default=0,
20-
help="Use this optimisation level if build.cfg is unavailable")
21-
parser.add_argument('--quiet', '-q', action="store_true", help="Don't generate any output")
11+
parser.add_argument(
12+
"configFile", type=str, nargs="?", default=None, help="The file with the information we need"
13+
)
14+
parser.add_argument("--cc", type=str, default="gcc", help="Use this compiler if build.cfg is unavailable")
15+
parser.add_argument(
16+
"--opt", type=int, default=0, help="Use this optimisation level if build.cfg is unavailable"
17+
)
18+
parser.add_argument("--quiet", "-q", action="store_true", help="Don't generate any output")
2219

2320
args = parser.parse_args()
2421
dirName = "."
@@ -36,14 +33,14 @@ if os.path.exists(args.configFile):
3633
try:
3734
config.read(args.configFile)
3835

39-
cc = config.get("Build", 'cc')
40-
opt = config.get("Build", 'opt')
36+
cc = config.get("Build", "cc")
37+
opt = config.get("Build", "opt")
4138
except Exception as e:
4239
if not args.quiet:
43-
print("File %s: error %s" % (args.configFile, e), file=sys.stderr)
40+
print(f"File {args.configFile}: error {e}", file=sys.stderr)
4441

4542
else:
4643
if not args.quiet:
47-
print("File %s doesn't exist" % args.configFile, file=sys.stderr)
44+
print(f"File {args.configFile} doesn't exist", file=sys.stderr)
4845

49-
print("cc=%s opt=%s" % (cc, opt))
46+
print(f"cc={cc} opt={opt}")

configs/boost_system.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ config = lsst.sconsUtils.ExternalConfiguration(
1212
libs=["boost_system"],
1313
eupsProduct="boost",
1414
)
15-

doc/conf.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@
2525
This configuration only affects single-package Sphinx documentation builds.
2626
"""
2727

28-
from documenteer.sphinxconfig.stackconf import build_package_configs
29-
import lsst.sconsUtils
30-
import lsst.sconsUtils.version
28+
from documenteer.conf.pipelinespkg import * # noqa: F403, import *
3129

32-
33-
_g = globals()
34-
_g.update(build_package_configs(
35-
project_name="sconsUtils",
36-
version=lsst.sconsUtils.version.__version__))
30+
project = "sconsUtils"
31+
html_theme_options["logotext"] = project # noqa: F405, unknown name
32+
html_title = project
33+
html_short_title = project
34+
doxylink = {}

doc/lsst.sconsUtils/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ Using ``sconsUtils`` without the ``conda`` Compilers
5151

5252
If you would like to use ``sconsUtils`` without the ``conda`` compilers, then put
5353
``SCONSUTILS_AVOID_CONDA_COMPILERS`` in your environment with a non-``None`` value.
54-
This environment variable will instruct ``sconsUtils`` to use the default system
54+
This environment variable will instruct ``sconsUtils`` to use the default system
5555
compilers and compiler flags.

0 commit comments

Comments
 (0)