-
Notifications
You must be signed in to change notification settings - Fork 7
Unique & named counters maintained across several pools #179
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [flake8] | ||
| max-line-length = 120 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| """ | ||
| pylint plugin doing resalloc-specific transformation to shut-down specific | ||
| errors which we can not easily ignore because the ignore mechanisms don't have | ||
| the needed granularity (copy-paste from Copr). | ||
| """ | ||
|
|
||
| import os | ||
| import subprocess | ||
| from astroid import MANAGER, scoped_nodes, nodes, extract_node | ||
|
|
||
|
|
||
| def register(_linter): | ||
| """ required pylint entrypoint """ | ||
|
|
||
|
|
||
| class Cache: | ||
| """ | ||
| Some rather expensive checks cached (as a class to avoid using globals). | ||
| """ | ||
| _gitroot = None | ||
| _test_files = { | ||
| # Some modules have None in the file argument: | ||
| # ipdb> function | ||
| # <FunctionDef.cmp_to_key l.None at 0x7febf4adcb20> | ||
| # ipdb> function.parent | ||
| # <Module._functools l.0 at 0x7febf4adcbb0> | ||
| # ipdb> function.parent.file is None | ||
| # True | ||
| None: False, | ||
| } | ||
| test_paths = { | ||
| "tests/", | ||
| } | ||
|
|
||
| @classmethod | ||
| def gitroot(cls): | ||
| """ Obtain the git-root of the current directory, and cache """ | ||
| if cls._gitroot: | ||
| return cls._gitroot | ||
| cls._gitroot = subprocess.check_output(["git", "rev-parse", | ||
| "--show-toplevel"]).decode("utf-8").strip() | ||
| return cls.gitroot() | ||
|
|
||
| @classmethod | ||
| def _slow_is_test_file(cls, test_file): | ||
| if not test_file.startswith(cls.gitroot() + os.sep): | ||
| return False | ||
| relpath = os.path.relpath(test_file, cls.gitroot()) | ||
| for test_path in cls.test_paths: | ||
| if relpath.startswith(test_path): | ||
| return True | ||
| return False | ||
|
|
||
| @classmethod | ||
| def is_test_file(cls, file_path): | ||
| """ | ||
| Check if file_path (path relative to the gitroot) is a test-file (per | ||
| cls.test_paths configuration). | ||
| """ | ||
| cached = cls._test_files.get(file_path) | ||
| if cached is None: | ||
| cls._test_files[file_path] = cls._slow_is_test_file(file_path) | ||
| return cls._test_files[file_path] | ||
|
|
||
|
|
||
| def module_path(node): | ||
| """ | ||
| Filename where the node (e.g. method) is defined. | ||
| """ | ||
| while node: | ||
| if isinstance(node, scoped_nodes.Module): | ||
| return node.file | ||
| node = node.parent | ||
| return None | ||
|
|
||
|
|
||
| def add_fake_docs(the_object): | ||
| """ | ||
| Add fake docs to the specified object so PyLint later doesn't complain about | ||
| missing docs. | ||
| """ | ||
| the_object.doc_node = nodes.Const("fake docs") | ||
| the_object.doc = "fake docs" | ||
|
|
||
|
|
||
| def transform_functions(function): | ||
| """ | ||
| Transformate some function definitions so pylint doesn't object. | ||
| """ | ||
|
|
||
| filename = module_path(function) | ||
|
|
||
| if function.name == 'logger': | ||
| for prop in ['debug', 'info', 'warning', 'error', 'exception']: | ||
| function.instance_attrs[prop] = extract_node('def {name}(arg): return'.format(name=prop)) | ||
|
|
||
| if function.name in ["upgrade", "downgrade"]: | ||
| # ignore missing-function-docstring in migrations | ||
| add_fake_docs(function) | ||
|
|
||
| if function.name == "step_impl": | ||
| # behave step definition | ||
| add_fake_docs(function) | ||
|
|
||
| if Cache.is_test_file(filename): | ||
| add_fake_docs(function) | ||
|
|
||
|
|
||
| def transform_classes(classdef): | ||
| """ | ||
| Transform Class definitions that don't need to have docstrings. | ||
| """ | ||
| filename = module_path(classdef) | ||
| if Cache.is_test_file(filename): | ||
| add_fake_docs(classdef) | ||
|
|
||
|
|
||
| def transform_modules(moduledef): | ||
| """ | ||
| Testing modules don't nave to have the doc-strings either. | ||
| """ | ||
| if Cache.is_test_file(moduledef.file): | ||
| add_fake_docs(moduledef) | ||
|
|
||
|
|
||
| MANAGER.register_transform(scoped_nodes.FunctionDef, transform_functions) | ||
| MANAGER.register_transform(scoped_nodes.ClassDef, transform_classes) | ||
| MANAGER.register_transform(scoped_nodes.Module, transform_modules) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
resallocserver/alembic/versions/d79239ae23a7_named_counters.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| """ | ||
| Named Counters added | ||
|
|
||
| Revision ID: d79239ae23a7 | ||
| Revises: b50e3f64fc2d | ||
| Create Date: 2026-03-04 10:52:27.756502 | ||
| """ | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
| revision = 'd79239ae23a7' | ||
| down_revision = 'b50e3f64fc2d' | ||
|
|
||
| branch_labels = None | ||
|
|
||
| depends_on = None | ||
|
|
||
|
|
||
|
|
||
| def upgrade(): | ||
|
|
||
| op.create_table( | ||
| 'named_counters', | ||
| sa.Column('resource_id', sa.Integer(), nullable=False), | ||
| sa.Column('value', sa.Integer(), nullable=True), | ||
| sa.Column('counter_name', sa.String(), nullable=True), | ||
| sa.ForeignKeyConstraint(['resource_id'], ['resources.id'], ), | ||
| sa.PrimaryKeyConstraint('counter_name', 'value'), | ||
| sa.UniqueConstraint('value', 'counter_name') | ||
| ) | ||
| with op.batch_alter_table('named_counters', schema=None) as batch_op: | ||
| batch_op.create_index(batch_op.f('ix_named_counters_counter_name'), | ||
| ['counter_name'], unique=False) | ||
| batch_op.create_index(batch_op.f('ix_named_counters_value'), ['value'], | ||
| unique=False) | ||
|
|
||
|
|
||
| def downgrade(): | ||
|
|
||
| with op.batch_alter_table('named_counters', schema=None) as batch_op: | ||
| batch_op.drop_index(batch_op.f('ix_named_counters_value')) | ||
| batch_op.drop_index(batch_op.f('ix_named_counters_counter_name')) | ||
| op.drop_table('named_counters') | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.