question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add proper __all__ in all scripts

See original GitHub issue

We should add a proper __all__ definition in all scripts. This will prevent strange import behaviors.

I propose to use the following format:

# Example of the proposed __all__ format
__all__ = [
    'SupportedDataset',
    'TransformationDataset',
    'TransformationSubset',
    'TransformationConcatDataset',
    'TransformationTensorDataset',
    'concat_datasets_sequentially',
    'as_transformation_dataset',
    'train_test_transformation_datasets'
]

which means:

  • One definition per line, which will make it easier to analyze diff in commits in which something has been added/removed to/from __all__.
  • The first definition starts in the line after __all__ = [
  • Each definition is “tabbed” by just one level
  • The final ] should be in its on line
  • Order of elements should follow the order in which things are defined in the script (that is, the order obtained by looking at the “Structure” tab of PyCharm).

What do you think?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
lrzpellegrinicommented, Feb 20, 2021

I thinked about a possible organization of the whole import thing. As discussed before, the main problem with cascading __init__.py is that it every sub-package symbol may get into the root namespace of each major module if we don’t define a proper module structure. Having many symbols in the namespace may be an undesirable source of confusion and will also tamper with IDEs hinting capabilities.

We should focus on keeping self-explanatory import paths based on common usage patterns + the degree of “standalone”-ness of that particular sub-module.

This is my idea for the “import paths” of the benchmark module:

  • avalanche.benchmarks.classic: in this way users may import classic benchmarks the way Jeremy suggested.
  • avalanche.benchmarks.datasets: i think that avalanche.benchmarks.datasets.that_dataset may be a little too specific. Also, we shouln’t add symbols contained in thisdataset_data.py to the module’s __init__.py file.
  • avalanche.benchmarks.generators: it now has a single source file scenario_generators.py containing all the definitions. We should probably split it to keep source code files simpler to navigate.
  • avalanche.benchmarks.scenarios.new_classes (without elements from nc_utils.py)
  • avalanche.benchmarks.scenarios.new_instances (without elements from ni_utils.py)
  • avalanche.benchmarks.scenarios.generic (without elements from generic_definitions.py)
  • Do not let anything flow upward from utils (but still put all non-private elements in __all__, so that they can be used)

Which means making the following changes:

  • Creating the avalanche.benchmarks.scenarios.generic module containing generic_cl_scenario.py and generic_scenario_creation.py
  • Remove the imports from avalanche.benchmarks.__init__.py, which now imports * from “scenarios”, “classic” and “generators” (which is a little bit exaggerated).
  • Split scenario_generators.py (see above)
  • Maybe consider moving TransformationDataset-related elements to their own new package.
  • Remove any private symbol from __all__ (example: the _get_cifar10_dataset method Martin pointed out)!

This applies to the benchmarks module, but I feel we should define a structure also for other major modules, too.

What do you think? Does this make sense to you?

0reactions
jeremyforestcommented, Feb 18, 2021

I think making it so this from avalanche.benchmarks.classic import SplitCifar10 is the standard would be a good idea. IMO it is the cleanest and easiest way for people not familiar with the code base to know where is what and not spend 10min tracking the dependencies.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding arguments and options to your Bash scripts - Red Hat
The getops command reads any and all options specified at the command line and creates a list of those options. The while command...
Read more >
Add Right Click => Find All References option in Script Editor
Ctrl + Shift + F is OK, but is only doing a string find. In this case, it finds lots of other stuff...
Read more >
Adding Your Custom Scripts Using Script Manager
Adding Scripts · Click on Settings in the left menu. · Select Script Manager. · Click the Add a Script button at the...
Read more >
Introduction to Office Scripts in Excel - Microsoft Support
Run an Office Script · All the scripts you and your workbook have access to are found under Automate > All scripts. The...
Read more >
Where should I put <script> tags in HTML markup?
Any script can insert its own HTML via document.write() or other DOM ... After all, the script could have inserted its own HTML...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found