pyflyby 1.10.1__cp311-cp311-manylinux_2_24_x86_64.whl → 1.10.2__cp311-cp311-manylinux_2_24_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pyflyby might be problematic. Click here for more details.

pyflyby/_cmdline.py CHANGED
@@ -27,6 +27,10 @@ else:
27
27
  from tomllib import loads
28
28
 
29
29
 
30
+ class ConfigurationError(Exception):
31
+ """Exception class indicating a configuration error."""
32
+
33
+
30
34
  def hfmt(s):
31
35
  return dedent(s).strip()
32
36
 
@@ -232,26 +236,17 @@ def parse_args(addopts=None, import_format_params=False, modify_action_params=Fa
232
236
  only if it is necessary to prevent exceeding the
233
237
  width (by default 79).
234
238
  '''))
235
- def uniform_callback(option, opt_str, value, parser):
236
- parser.values.separate_from_imports = False
237
- parser.values.from_spaces = 3
238
- parser.values.align_imports = '32'
239
- group.add_option('--uniform', '-u', action="callback",
240
- callback=uniform_callback,
239
+ group.add_option('--uniform', '-u', action="store_true",
241
240
  help=hfmt('''
242
241
  (Default) Shortcut for --no-separate-from-imports
243
242
  --from-spaces=3 --align-imports=32.'''))
244
- def unaligned_callback(option, opt_str, value, parser):
245
- parser.values.separate_from_imports = True
246
- parser.values.from_spaces = 1
247
- parser.values.align_imports = '0'
248
- group.add_option('--unaligned', '-n', action="callback",
249
- callback=unaligned_callback,
243
+ group.add_option('--unaligned', '-n', action="store_true",
250
244
  help=hfmt('''
251
245
  Shortcut for --separate-from-imports
252
246
  --from-spaces=1 --align-imports=0.'''))
253
247
 
254
248
  parser.add_option_group(group)
249
+
255
250
  if addopts is not None:
256
251
  addopts(parser)
257
252
  # This is the only way to provide a default value for an option with a
@@ -260,7 +255,22 @@ def parse_args(addopts=None, import_format_params=False, modify_action_params=Fa
260
255
  args = ["--symlinks=error"] + sys.argv[1:]
261
256
  else:
262
257
  args = None
258
+
263
259
  options, args = parser.parse_args(args=args)
260
+
261
+ # Set these manually rather than in a callback option because callback
262
+ # options don't get triggered by OptionParser.set_default (which is
263
+ # used when setting values via pyproject.toml)
264
+ if getattr(options, "unaligned", False):
265
+ parser.values.separate_from_imports = True
266
+ parser.values.from_spaces = 1
267
+ parser.values.align_imports = '0'
268
+
269
+ if getattr(options, "uniform", False):
270
+ parser.values.separate_from_imports = False
271
+ parser.values.from_spaces = 3
272
+ parser.values.align_imports = '32'
273
+
264
274
  if import_format_params:
265
275
  align_imports_args = [int(x.strip())
266
276
  for x in options.align_imports.split(",")]
@@ -380,14 +390,35 @@ class Modifier(object):
380
390
 
381
391
 
382
392
  def process_actions(filenames:List[str], actions, modify_function,
383
- reraise_exceptions=()):
393
+ reraise_exceptions=(), exclude=()):
394
+
395
+ if not isinstance(exclude, (list, tuple)):
396
+ raise ConfigurationError(
397
+ "Exclusions must be a list of filenames/patterns to exclude."
398
+ )
399
+
384
400
  errors = []
385
401
  def on_error_filename_arg(arg):
386
402
  print("%s: bad filename %s" % (sys.argv[0], arg), file=sys.stderr)
387
403
  errors.append("%s: bad filename" % (arg,))
388
- filenames = filename_args(filenames, on_error=on_error_filename_arg)
404
+ filename_objs = filename_args(filenames, on_error=on_error_filename_arg)
389
405
  exit_code = 0
390
- for filename in filenames:
406
+ for filename in filename_objs:
407
+
408
+ # Log any matching exclusion patterns before ignoring, if applicable
409
+ matching_excludes = []
410
+ for pattern in exclude:
411
+ if Path(str(filename)).match(str(pattern)):
412
+ matching_excludes.append(pattern)
413
+ if any(matching_excludes):
414
+ msg = f"{filename} matches exclusion pattern"
415
+ if len(matching_excludes) == 1:
416
+ msg += f": {matching_excludes[0]}"
417
+ else:
418
+ msg += f"s: {matching_excludes}"
419
+ logger.info(msg)
420
+ continue
421
+
391
422
  try:
392
423
  m = Modifier(modify_function, filename)
393
424
  for action in actions:
@@ -533,16 +564,28 @@ symlink_callbacks = {
533
564
  'replace': symlink_replace,
534
565
  }
535
566
 
536
- def _get_pyproj_toml_config():
537
- """
538
- Try to find current project pyproject.toml
567
+ def _get_pyproj_toml_file():
568
+ """Try to find the location of the current project pyproject.toml
539
569
  in cwd or parents directories.
570
+
571
+ If no pyproject.toml can be found, None is returned.
540
572
  """
541
573
  cwd = Path(os.getcwd())
542
574
 
543
575
  for pth in [cwd] + list(cwd.parents):
544
576
  pyproj_toml = pth /'pyproject.toml'
545
577
  if pyproj_toml.exists() and pyproj_toml.is_file():
546
- return loads(pyproj_toml.read_text())
578
+ return pyproj_toml
547
579
 
548
580
  return None
581
+
582
+ def _get_pyproj_toml_config():
583
+ """Return the toml contents of the current pyproject.toml.
584
+
585
+ If no pyproject.toml can be found in cwd or parent directories,
586
+ None is returned.
587
+ """
588
+ pyproject_toml = _get_pyproj_toml_file()
589
+ if pyproject_toml is not None:
590
+ return loads(pyproject_toml.read_text())
591
+ return None
pyflyby/_modules.py CHANGED
@@ -595,6 +595,12 @@ def _cached_module_finder(
595
595
  Tuples containing (prefix+module name, a bool indicating whether the module is a
596
596
  package or not)
597
597
  """
598
+ if os.environ.get("PYFLYBY_DISABLE_CACHE", "0") == "1":
599
+ modules = _iter_file_finder_modules(importer, SUFFIXES)
600
+ for module, ispkg in modules:
601
+ yield prefix + module, ispkg
602
+ return
603
+
598
604
  cache_dir = pathlib.Path(
599
605
  platformdirs.user_cache_dir(appname='pyflyby', appauthor=False)
600
606
  ) / hashlib.sha256(str(importer.path).encode()).hexdigest()
@@ -610,7 +616,7 @@ def _cached_module_finder(
610
616
  for path in cache_dir.iterdir():
611
617
  _remove_import_cache_dir(path)
612
618
 
613
- if os.environ.get("PYFLYBY_SUPPRESS_CACHE_REBUILD_LOGS", 0) != "1":
619
+ if os.environ.get("PYFLYBY_SUPPRESS_CACHE_REBUILD_LOGS", "1") != "1":
614
620
  logger.info(f"Rebuilding cache for {_format_path(importer.path)}...")
615
621
 
616
622
  modules = _iter_file_finder_modules(importer, SUFFIXES)
pyflyby/_version.py CHANGED
@@ -4,4 +4,4 @@
4
4
  # http://creativecommons.org/publicdomain/zero/1.0/
5
5
 
6
6
 
7
- __version__ = "1.10.1"
7
+ __version__ = "1.10.2"
@@ -85,6 +85,8 @@ def _addopts(parser):
85
85
  default=True, action='store_false',
86
86
  help=hfmt('''
87
87
  Don't canonicalize imports.'''))
88
+ parser.add_option('--exclude', type='string', dest='exclude',
89
+ action='append', help=hfmt('Files to exclude from formatting.'))
88
90
 
89
91
 
90
92
  def transform_callback(option, opt_str, value, group):
@@ -156,7 +158,12 @@ def main() -> None:
156
158
  cannonical_imports = sorted_imports
157
159
  return cannonical_imports
158
160
 
159
- process_actions(args, options.actions, modify)
161
+ cmdline_exclude = getattr(options, "exclude")
162
+ process_actions(
163
+ args,
164
+ options.actions, modify,
165
+ exclude=default_config.get('tidy-imports', {}).get('exclude', []) + (cmdline_exclude if cmdline_exclude else [])
166
+ )
160
167
 
161
168
 
162
169
  if __name__ == '__main__':
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyflyby
3
- Version: 1.10.1
3
+ Version: 1.10.2
4
4
  Summary: pyflyby - Python development productivity tools, in particular automatic import management
5
5
  Author-Email: Karl Chen <quarl@8166.clguba.z.quarl.org>
6
6
  License-Expression: MIT
@@ -210,6 +210,7 @@ For example:
210
210
 
211
211
  Replace /tmp/foo.py? [y/N]
212
212
 
213
+ To exclude a file, use `--exclude <pattern>`.
213
214
 
214
215
  Quick start: import libraries
215
216
  =============================
@@ -481,21 +482,37 @@ Per-Project configuration of tidy-imports
481
482
  =========================================
482
483
 
483
484
  You can configure Pyflyby on a per-repository basis by using the
484
- `[tool.pyflyby]` section of `pyproject.toml` files. Pyflyby will look in current
485
- working directory and all it's parent until it find a `pyproject.toml` file from
485
+ ``[tool.pyflyby]`` section of ``pyproject.toml`` files. Pyflyby will look in current
486
+ working directory and all it's parent until it find a ``pyproject.toml`` file from
486
487
  which it will load the defaults.
487
488
 
488
489
 
489
490
  Most of the long command line flags default values can be configured in this
490
- section. Simply use the long form option name by replacing dashes `-` by
491
- underscore `_`. For long option that have the form `--xxx` and `--no-xxx`, you
492
- can assign a boolean to `xxx`. For example::
491
+ section. Simply use the long form option name by replacing dashes ``-`` by
492
+ underscore ``_``. For long option that have the form ``--xxx`` and ``--no-xxx``, you
493
+ can assign a boolean to ``xxx``. For example::
494
+
495
+ .. code:: toml
493
496
 
494
497
  [tool.pyflyby]
495
498
  add_missing=true
496
499
  from_spaces=7
497
500
  remove_unused=false
498
501
 
502
+ To exclude files from ``tidy-imports``, add an exclusion pattern to
503
+ ``tool.pyflyby.tidy-imports.exclude``:
504
+
505
+ .. code:: toml
506
+
507
+ [tool.pyflyby.tidy-imports]
508
+ exclude = [
509
+ "foo.py",
510
+ "baz/*.py"
511
+ ]
512
+
513
+ Exclusions are assumed to be relative to the project root if a ``pyproject.toml`` exists, unless an
514
+ absolute path is specified. Consult the documentation for ``pathlib.Path.match`` for information about
515
+ valid exclusion patterns.
499
516
 
500
517
  Emacs support
501
518
  =============
@@ -1,12 +1,12 @@
1
1
  pyflyby/__init__.py,sha256=sfTZU9wfNQPpgciMJg8lgtu_YagJflnoB-kjnI33css,2918
2
2
  pyflyby/__main__.py,sha256=F_so6X2LPdGUrTWjYvRaTOHHXxCmTGPsp5KcX-Vl6Eo,190
3
3
  pyflyby/_autoimp.py,sha256=X_4H74AzGM3gQdYoJ2yCu2p56jfWg15NeAQmF6xIu3c,87748
4
- pyflyby/_cmdline.py,sha256=a8gNW8M2Pd60UVQcXeb9xyBDB8bM0sq5DFYYzXuzCHk,20890
4
+ pyflyby/_cmdline.py,sha256=r4zoGCu9jPE-ZaHmi5PZZiHWR5W7nwEfWSnH0IzpvDo,22123
5
5
  pyflyby/_comms.py,sha256=Q3JTbNqkHUw49laMQkFbqCs0FxDy6mi9V2glwdbwfEI,8249
6
6
  pyflyby/_dbg.py,sha256=JIyRXYctfmRIqkuBX6Q247q7abWllTeh5i7SxDF_9lc,47023
7
7
  pyflyby/_docxref.py,sha256=teYGqDJauLrw6g5mVyXRIl9-q6WuyGjjEj4M8RIkTCU,14117
8
8
  pyflyby/_dynimp.py,sha256=y0_RFYAAXOEr8-DYkGfYyFF6z_jkyHZYQXTm40Z54_s,4319
9
- pyflyby/_fast_iter_modules.cpython-311-x86_64-linux-gnu.so,sha256=XDzuglLvJfVsvvmWAxb6gmsAnGwhSKjDj_QnCjVupDQ,410776
9
+ pyflyby/_fast_iter_modules.cpython-311-x86_64-linux-gnu.so,sha256=z8OxuTFgo4xI9g6BX2FEcFAw8OfRbF3G4NAcItDatV8,410816
10
10
  pyflyby/_file.py,sha256=ooM0StVzbhcpcvJGcsx-asXfe7QG0xfs_N-xUpTaqrQ,24449
11
11
  pyflyby/_flags.py,sha256=ln-jkzTAiImrC6VB9ENlfjtlIAJp-b50wgWexfFAURw,7201
12
12
  pyflyby/_format.py,sha256=GQu6QwFnVJkqEUlru6eZUpEq8Ym14vcwT7KfUrTdXx4,7038
@@ -19,13 +19,13 @@ pyflyby/_importstmt.py,sha256=GM4TDdgzuikvtOjGeJ8F7cVI-noTjRjbqj0REt642t4,23794
19
19
  pyflyby/_interactive.py,sha256=nyjsM6QaTqhXJDZ153JoQANmAS2hE5bwMbkrOTFFmg8,83743
20
20
  pyflyby/_livepatch.py,sha256=4PRwpGwYEKqrwsON-ko7H_skZjcZhHCzepsjjfyOots,29450
21
21
  pyflyby/_log.py,sha256=1OcdfahDeT8zP55ZuFE60VreYubTw9VGS2xHUXrZbhg,2860
22
- pyflyby/_modules.py,sha256=A27seV6hvDOFyL1vGJH_urnPY9Z6qgrp1RE-hk8mFLw,22893
22
+ pyflyby/_modules.py,sha256=NApMrLgZy_c0dW_tBhTFgx6Fck8-Efnv84WHp07xxUs,23114
23
23
  pyflyby/_parse.py,sha256=UI_PrzegGblOtgGuqZqZ1mYaABSTeVCKrUAaEnPYcEc,49300
24
24
  pyflyby/_py.py,sha256=gJ8gngAy0u1yfV8bgey4qsMV8-ZOr_wzCOaGVIUvEQk,80264
25
25
  pyflyby/_saveframe.py,sha256=pqWvgAYjIxotNvNxIlSS3hrOOITWkfoz6rifnHUgSUA,45992
26
26
  pyflyby/_saveframe_reader.py,sha256=8VDN3W13Tb2D_L7QFdR7u9VwPuNxA8AeRsgzajY-dWI,18548
27
27
  pyflyby/_util.py,sha256=I_sYNeJ7buzCAYXTef4nmQ_lWZR5EXZOL3bJoeY6QuQ,13840
28
- pyflyby/_version.py,sha256=8LHnQQli2xOE9W-IPROE_wivflxsgdYdIhZ3N_Se6ng,160
28
+ pyflyby/_version.py,sha256=6beMANZvsfS6NqU1ICCKtP2LOFrEV_zWKmcHNPW36L0,160
29
29
  pyflyby/autoimport.py,sha256=GsdvaAmsVepkrR9vHtRkdXVrAqQoCG1OrOxUVOkuFc0,487
30
30
  pyflyby/importdb.py,sha256=ClY6LeBuWcPGuia3S05JDlbQQyl79D3QoGy_ciUWSDk,494
31
31
  pyflyby/etc/pyflyby/canonical.py,sha256=AEkiB4K19Pw4eKCns5dhnFXMmOJnRuwmly9RYihUwXM,270
@@ -37,19 +37,19 @@ pyflyby/etc/pyflyby/std.py,sha256=pDFU6DDwZZLYD4itkimTI0fljsp4C4EO8fj5_wW21Vo,17
37
37
  pyflyby/libexec/pyflyby/colordiff,sha256=TqnG5jATcv9qU2HTuq2mQmb9m_jAjUfNQ4VIUnu5cK8,949
38
38
  pyflyby/libexec/pyflyby/diff-colorize,sha256=S6wfKHEafQ9DFqiDvnnd70lrS71n1r1Tm9o2-FwxFgQ,5578
39
39
  pyflyby/share/emacs/site-lisp/pyflyby.el,sha256=iKXqFc7kAweJ_TwQUhV3G-SxABme_Idk-iCwzLTmbbY,4122
40
- pyflyby-1.10.1.data/scripts/collect-exports,sha256=AqGNj2BuIK8RpqLCZJ5Rokqj1Kk4nJYcw9aKFkb96OI,2863
41
- pyflyby-1.10.1.data/scripts/collect-imports,sha256=8is1rLKRq-1mnyx3pDD7uBKEZt9C1sE1kWlyqpm2YaA,2141
42
- pyflyby-1.10.1.data/scripts/find-import,sha256=_EmUDFQXCv_2tx79OyWBzdTKm_d8umVW7RY06jspYCE,932
43
- pyflyby-1.10.1.data/scripts/list-bad-xrefs,sha256=57krqCqA63LIt6C0YGbE_F4eZYYr5F8qE-eg_DNMgRc,1027
44
- pyflyby-1.10.1.data/scripts/prune-broken-imports,sha256=Wt2G8jTrVQKexUjqblrL5TXQfgRH3edctYukIBNZUVU,861
45
- pyflyby-1.10.1.data/scripts/pyflyby-diff,sha256=TqnG5jATcv9qU2HTuq2mQmb9m_jAjUfNQ4VIUnu5cK8,949
46
- pyflyby-1.10.1.data/scripts/reformat-imports,sha256=PIT4kqE_1HenKvtDSpmyH386Ht5HvT1JlWjSb5mja8w,690
47
- pyflyby-1.10.1.data/scripts/replace-star-imports,sha256=7P8KbCX4K5cc6F-TT4KfGVeWkI0KWK38be8IRRyZfU8,913
48
- pyflyby-1.10.1.data/scripts/saveframe,sha256=bqU58kNDConm51zTpM3J37c-uhlDo-Uj8fOQ-rnYhwM,12074
49
- pyflyby-1.10.1.data/scripts/tidy-imports,sha256=OcI1ghA0hn6JPkL7U-8I57db5HvP2P0jsmNsMZhHr_A,6686
50
- pyflyby-1.10.1.data/scripts/transform-imports,sha256=IAMZTrHsZO5aRwF1exXGPhfL6UawUzJZmSl87K65elY,1450
51
- pyflyby-1.10.1.dist-info/METADATA,sha256=U67-2QqjcCEeXYsoBGwD50HDIArLDwjIPKFoOUtNZag,17628
52
- pyflyby-1.10.1.dist-info/WHEEL,sha256=e-oFlY3eLJQVVkSrz9ixwUyvzXafqjrUD6YYCD18aKo,99
53
- pyflyby-1.10.1.dist-info/entry_points.txt,sha256=aGXu4O2RcVf2hy1daq-edciSegKffMs7GDat7G-2p3k,70
54
- pyflyby-1.10.1.dist-info/RECORD,,
55
- pyflyby-1.10.1.dist-info/licenses/LICENSE.txt,sha256=cSDlWua5QEFNdBRChGEKcS_5ABQ2220A3OkP10Q9RA0,1188
40
+ pyflyby-1.10.2.data/scripts/collect-exports,sha256=AqGNj2BuIK8RpqLCZJ5Rokqj1Kk4nJYcw9aKFkb96OI,2863
41
+ pyflyby-1.10.2.data/scripts/collect-imports,sha256=8is1rLKRq-1mnyx3pDD7uBKEZt9C1sE1kWlyqpm2YaA,2141
42
+ pyflyby-1.10.2.data/scripts/find-import,sha256=_EmUDFQXCv_2tx79OyWBzdTKm_d8umVW7RY06jspYCE,932
43
+ pyflyby-1.10.2.data/scripts/list-bad-xrefs,sha256=57krqCqA63LIt6C0YGbE_F4eZYYr5F8qE-eg_DNMgRc,1027
44
+ pyflyby-1.10.2.data/scripts/prune-broken-imports,sha256=Wt2G8jTrVQKexUjqblrL5TXQfgRH3edctYukIBNZUVU,861
45
+ pyflyby-1.10.2.data/scripts/pyflyby-diff,sha256=TqnG5jATcv9qU2HTuq2mQmb9m_jAjUfNQ4VIUnu5cK8,949
46
+ pyflyby-1.10.2.data/scripts/reformat-imports,sha256=PIT4kqE_1HenKvtDSpmyH386Ht5HvT1JlWjSb5mja8w,690
47
+ pyflyby-1.10.2.data/scripts/replace-star-imports,sha256=7P8KbCX4K5cc6F-TT4KfGVeWkI0KWK38be8IRRyZfU8,913
48
+ pyflyby-1.10.2.data/scripts/saveframe,sha256=bqU58kNDConm51zTpM3J37c-uhlDo-Uj8fOQ-rnYhwM,12074
49
+ pyflyby-1.10.2.data/scripts/tidy-imports,sha256=HmODd58QhWn6fap6-S5ohBy-qsLbnDnQa0uyYg5fNws,7035
50
+ pyflyby-1.10.2.data/scripts/transform-imports,sha256=IAMZTrHsZO5aRwF1exXGPhfL6UawUzJZmSl87K65elY,1450
51
+ pyflyby-1.10.2.dist-info/METADATA,sha256=eAR1Ak0wg2qWvezeEcq4SD4_DpAz4yBurG5nWZDT5iE,18151
52
+ pyflyby-1.10.2.dist-info/WHEEL,sha256=e-oFlY3eLJQVVkSrz9ixwUyvzXafqjrUD6YYCD18aKo,99
53
+ pyflyby-1.10.2.dist-info/entry_points.txt,sha256=aGXu4O2RcVf2hy1daq-edciSegKffMs7GDat7G-2p3k,70
54
+ pyflyby-1.10.2.dist-info/RECORD,,
55
+ pyflyby-1.10.2.dist-info/licenses/LICENSE.txt,sha256=cSDlWua5QEFNdBRChGEKcS_5ABQ2220A3OkP10Q9RA0,1188