Stop using global state to store configuration options
Dieses Issue hat noch niemand übernommen.
- #309 von @rudi193-cmd — ohne Merge geschlossen
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
Lies zunächst codejail.jail_code.COMMANDS und configure, und untersuche dann die codejail.django_integration-Middleware, die die Konfiguration befüllt. Entscheide dich für ein nicht-globales Konfigurationsdesign und implementiere es, sodass wiederholte Konfiguration unabhängig von der Reihenfolge der Unit-Tests ist und sich über Python-Prozesse hinweg konsistent verhält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Codejail has a global variable at codejail.jail_code.COMMANDS. It's a dictionary that maps command names (like "python") to safe shell commands. An example value is:
{'python': {'cmdline_start': ['/edx/app/edxapp/venvs/edxapp-sandbox/bin/python', '-E', '-B'], 'user': 'sandbox'}}
The dictionary is populated by calling codejail.jail_code.configure, which is generally done via the codejail.django_integration middleware.
This all works fine, but the fact that COMMANDS is a global variable is not idiomatic Python. More concretely, it's a pain in the neck for unit tests: the order and timing with which unit tests are run will affect whether .configure has been called or not. This could also cause problems across Python processes in production, leading to situations where codejail is configured in one process but effectively disabled in another process without anyone knowing. Not good.
This stateful system also forces us to use a middleware in order to configure codejail in Django--that's another layer where something could go wrong.
I recommend replacing COMMANDS with either:
- a stateless function named
load_commands(), which is safe to call over and over again, which does something like this:try: from django.conf import settings except ImportError, AttributeError settings = {} if settings.get('CODE_JAIL'): return _load_command_from_django_settings(settings) else: # .... load alternative/fallback configuration options, if we're not using Django - putting the entire Codejail interface behind a class, so clients would need to pass the settings into it, like this:
from django.conf import settings codejail = CodeJail(some_setting=settings.CODEJAIL[...], etc..) codejail.safe_exec(...)
- Vorherrschende Sprache
- Python
- Sterne
- 477
- Forks
- 83
- Ø Merge
- 1 T. 8 Std.
- Gemergte PRs (30 T.)
- 6
Entwicklungsumgebung
- Enthält ein Dockerfile oder eine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus openedx/codejail
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 50/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 30/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
Alle Issues in openedx/codejail
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
btclib-org/btclib-wallet#1045 ·
Maintainer antworten meist innerhalb von 1 Tag
-
area-templates triage:bot-seen triage:needs-human
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
microsoft/aspire#22356 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
[Train] An elastic ScalingConfig(num_workers=(0, 0)) is accepted and the run waits foreverEvtl. vergeben @wguo7 hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
ray-project/ray#68217 ·
Maintainer antworten meist innerhalb von 2 Tagen