nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: svenstaro/miniserve
Pull request #1472 (2025-02-06 04:22:00)

move favicon and css to stable, non-random routes
Favicon and stylesheet are currently served at random paths in order to avoid collisions. However, this causes problems with [running multi-replica deployments](https://github.com/svenstaro/miniserve/issues/1424) as well as caching, because the path is not stable across multiple instances/restarts of miniserve.

In order to address this, this PR moves the paths to stable routes prefixed by "__miniserve_internal", which should provide enough protection from accidental collisions.


Patch:
diff --git a/src/config.rs b/src/config.rs
index 5d2d7e8..953bba1 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -196,13 +196,13 @@ impl MiniserveConfig {
         // Otherwise, we should apply route_prefix to static files.
         let (favicon_route, css_route) = if args.random_route {
             (
-                format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET)),
-                format!("/{}", nanoid::nanoid!(10, &ROUTE_ALPHABET)),
+                "/__miniserve_internal/favicon.svg".into(),
+                "/__miniserve_internal/style.css".into(),
             )
         } else {
             (
-                format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET)),
-                format!("{}/{}", route_prefix, nanoid::nanoid!(10, &ROUTE_ALPHABET)),
+                format!("{}/{}", route_prefix, "__miniserve_internal/favicon.ico"),
+                format!("{}/{}", route_prefix, "__miniserve_internal/style.css"),
             )
         };
 


Test patch:
diff --git a/tests/serve_request.rs b/tests/serve_request.rs
index a53abf9..f840efd 100644
--- a/tests/serve_request.rs
+++ b/tests/serve_request.rs
@@ -290,9 +290,9 @@ fn serves_requests_with_route_prefix(#[case] server: TestServer) -> Result<(), E
 }
 
 #[rstest]
-#[case(server(&[] as &[&str]), "/[a-f0-9]+")]
-#[case(server(&["--random-route"]), "/[a-f0-9]+")]
-#[case(server(&["--route-prefix", "foobar"]), "/foobar/[a-f0-9]+")]
+#[case(server(&[] as &[&str]), "/__miniserve_internal/[a-z.]+")]
+#[case(server(&["--random-route"]), "/__miniserve_internal/[a-z.]+")]
+#[case(server(&["--route-prefix", "foobar"]), "/foobar/__miniserve_internal/[a-z.]+")]
 fn serves_requests_static_file_check(
     #[case] server: TestServer,
     #[case] static_file_pattern: String,
Repository: CORE-GATECH-GROUP/serpent-tools
Pull request #145 (2018-05-16 15:51:49)

Add implicit truth methods for HomogUniv objects
HomogUniv method hasData returns True is some data is stored
on the instance. The method iterates over inf and b1 dictionaries,
expected and uncertainty, as well as metadata, and returns True
at the first instance of a non-empty dictionary.

This method is also shared with __bool__ and __nonzero__ so that
the universes can be compared implicitly, i.e. `if univ:`, without
having to call `hasData`.


Patch:
diff --git a/serpentTools/objects/containers.py b/serpentTools/objects/containers.py
index 9626270..567a7b4 100644
--- a/serpentTools/objects/containers.py
+++ b/serpentTools/objects/containers.py
@@ -259,6 +259,17 @@ class HomogUniv(NamedObject):
         else:
             return self.metadata
 
+    def __bool__(self):
+        """Return True if data is stored on the object."""
+        attrs = {"infExp", "infUnc", "b1Exp", "b1Unc", "metadata"}
+        for key in attrs:
+            if getattr(self, key):
+                return True
+        return False
+
+    __nonzero__ = __bool__
+
+    hasData = __bool__
 
 class DetectorBase(NamedObject):
     """


Test patch:
diff --git a/serpentTools/tests/test_container.py b/serpentTools/tests/test_container.py
index 25a1188..a2bded8 100644
--- a/serpentTools/tests/test_container.py
+++ b/serpentTools/tests/test_container.py
@@ -1,6 +1,7 @@
 """Test the container object. """
 
 import unittest
+from itertools import product
 
 from six import iteritems
 from numpy import array, arange
@@ -135,8 +136,35 @@ def compareDictOfArrays(expected, actualDict, dataType):
 
 del _HomogUnivTestHelper
 
+class UnivTruthTester(unittest.TestCase):
+    """Class that tests the various boolean evaluations for HomogUniv"""
+
+    def setUp(self):
+        """Verify that an empty universe evalutes to False."""
+        self.assertFalse(self.getUniv())
+
+    def test_loadedUnivTrue(self):
+        """Verify that universes with some data evalue to True."""
+        keys = {"INF_TOT", "B1_TOT", "CMM_TRANSP_X"}
+        data = arange(NUM_GROUPS)
+        for uflag, key in product((True, False), keys):
+            univ = self.getUniv()
+            univ.addData(key, data, uflag)
+            self.evalUniv(univ, msg="Key = {}, Uflag={}".format(key, uflag))
+        univ = self.getUniv()
+        univ.addData("MACRO_E", data)
+        self.evalUniv(univ, msg="Key = MACRO_E")
+
+    @staticmethod
+    def getUniv():
+        return HomogUniv('truth', 0, 0, 0)
+
+    def evalUniv(self, univ, msg):
+        """Shortcut for testing the truth of a universe."""
+        self.assertTrue(univ, msg=msg)
+        self.assertTrue(univ.hasData, msg=msg)
+
+
+
 if __name__ == '__main__':
-    from serpentTools import rc
-    with rc:
-        rc['verbosity'] = 'debug'
-        unittest.main()
+    unittest.main()
Repository: CORE-GATECH-GROUP/serpent-tools
Pull request #519 (2024-06-17 22:55:07)

ENH: Support providing detector names at construction
Names of detectors can be provided when building a `DetectorReader`

Related to #339


drewejohnson: Draft until numpy 2.0 support lands in #524 

Patch:
diff --git a/docs/changelog.rst b/docs/changelog.rst
index b013778..0d7c8db 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -13,6 +13,8 @@ Changelog
 
 * Depletion reader settings can be provided at construction - :pull:`516`
 * Support ``numpy`` 2.0 - :pull:`524`
+* Names of detectors to read can be provided at construction of the detector
+  reader - :pull:`519`
 
 .. _v0.10.1:
 
diff --git a/src/serpentTools/parsers/detector.py b/src/serpentTools/parsers/detector.py
index 627e24c..8b2e542 100644
--- a/src/serpentTools/parsers/detector.py
+++ b/src/serpentTools/parsers/detector.py
@@ -19,6 +19,9 @@ class DetectorReader(BaseReader):
     ----------
     filePath : str
         path to the depletion file
+    names : list of string, optional
+        Names of any detectors to process. If not given, fall back
+        to the ``detector.names``.
 
     Attributes
     ----------
@@ -31,9 +34,11 @@ class DetectorReader(BaseReader):
     # Update this if new detector grids are introduced
     _KNOWN_GRIDS = ("E", "X", "Y", "Z", "T", "COORD", "R", "PHI", "THETA")
 
-    def __init__(self, filePath):
-        BaseReader.__init__(self, filePath, 'detector')
+    def __init__(self, filePath, names=None):
+        BaseReader.__init__(self, filePath, "detector")
         self.detectors = {}
+        if names is not None:
+            self.settings["names"] = names
 
     def __getitem__(self, name):
         """Retrieve a detector from :attr:`detectors`"""


Test patch:
diff --git a/tests/test_detector.py b/tests/test_detector.py
index 5d55146..5f7ec21 100644
--- a/tests/test_detector.py
+++ b/tests/test_detector.py
@@ -7,7 +7,7 @@ from collections import OrderedDict
 
 from numpy import arange, array
 from numpy.testing import assert_equal
-from serpentTools.parsers import read
+from serpentTools.parsers import read, DetectorReader
 from serpentTools.data import getFile
 from serpentTools.detectors import (
     CartesianDetector, HexagonalDetector, CylindricalDetector)
@@ -336,3 +336,18 @@ class TimeBinnedDetectorTester(TestCase):
         assert_equal(self.timeDet.tallies, expTallies)
         assert_equal(self.timeDet.errors, expErrors)
         assert_equal(self.timeDet.grids['T'], expTimeGrid)
+
+
+def test_defaultSettings():
+     fp = getFile("ref_det0.m")
+     reader = DetectorReader(fp)
+     assert reader.settings["names"] == []
+
+
+def test_filteredInitSettings():
+    fp = getFile("bwr_det0.m")
+    reader = DetectorReader(fp, names=["spectrum"])
+    assert reader.settings["names"] == ["spectrum"]
+    reader.read()
+    assert len(reader) == 1
+    assert "spectrum" in reader
Repository: rust-phf/rust-phf
Pull request #280 (2023-02-21 04:35:50)

Allow using dereferenced bytestring literal keys in phf_map!
Hello, first I would like to say thank you for the crate, it is quite high quality. I noticed that `phf_map!` supports using `u8` array literals for keys. But in some cases I found it is easier to use byte strings of a fixed size, i.e. when keys may have a lot of ascii characters.

The problem is a byte string is of type `&[u8; N]` and has to be dereferenced to convert it to a value type. This PR makes it so a `*` operator can be put in front of a byte string literal so it works properly. And then things like this can be done:

```rust
static M: phf::Map<[u8; 8], u64> = phf::phf_map! {
    *b"qwertyiu" => 0u64,
    *b"abcdabcd" => 1u64,
};
```


Patch:
diff --git a/phf/src/lib.rs b/phf/src/lib.rs
index d79ab42..ab894b7 100644
--- a/phf/src/lib.rs
+++ b/phf/src/lib.rs
@@ -86,6 +86,7 @@ extern crate std as core;
 /// Supported key expressions are:
 /// - literals: bools, (byte) strings, bytes, chars, and integers (these must have a type suffix)
 /// - arrays of `u8` integers
+/// - dereferenced byte string literals
 /// - `UniCase::unicode(string)` or `UniCase::ascii(string)` if the `unicase` feature is enabled
 ///
 /// # Example
diff --git a/phf_macros/src/lib.rs b/phf_macros/src/lib.rs
index 22cad23..a033036 100644
--- a/phf_macros/src/lib.rs
+++ b/phf_macros/src/lib.rs
@@ -11,9 +11,7 @@ use std::collections::HashSet;
 use std::hash::Hasher;
 use syn::parse::{self, Parse, ParseStream};
 use syn::punctuated::Punctuated;
-#[cfg(feature = "unicase")]
-use syn::ExprLit;
-use syn::{parse_macro_input, Error, Expr, Lit, Token, UnOp};
+use syn::{parse_macro_input, Error, Expr, ExprLit, Lit, Token, UnOp};
 #[cfg(feature = "unicase")]
 use unicase_::UniCase;
 
@@ -123,6 +121,19 @@ impl ParsedKey {
                         ParsedKey::I128(v) => Some(ParsedKey::I128(try_negate!(v))),
                         _ => None,
                     },
+                    UnOp::Deref(_) => {
+                        let mut expr = &*unary.expr;
+                        while let Expr::Group(group) = expr {
+                            expr = &*group.expr;
+                        }
+                        match expr {
+                            Expr::Lit(ExprLit {
+                                lit: Lit::ByteStr(s),
+                                ..
+                            }) => Some(ParsedKey::Binary(s.value())),
+                            _ => None,
+                        }
+                    }
                     _ => None,
                 }
             }


Test patch:
diff --git a/phf_macros_tests/tests/test.rs b/phf_macros_tests/tests/test.rs
index f8113ef..7123753 100644
--- a/phf_macros_tests/tests/test.rs
+++ b/phf_macros_tests/tests/test.rs
@@ -17,6 +17,11 @@ mod map {
         b"camembert" => "delicious",
     );
 
+    #[allow(dead_code)]
+    static DEREF_BYTE_STRING_KEY: phf::Map<[u8; 9], &'static str> = phf_map!(
+        *b"camembert" => "delicious",
+    );
+
     #[test]
     fn test_two() {
         static MAP: phf::Map<&'static str, isize> = phf_map!(
Repository: rust-phf/rust-phf
Pull request #334 (2025-06-19 11:05:21)

chore: Fix test


Patch:
diff --git a/phf/examples/uncased-example/Cargo.toml b/phf/examples/uncased-example/Cargo.toml
index 606fabc..0a508a5 100644
--- a/phf/examples/uncased-example/Cargo.toml
+++ b/phf/examples/uncased-example/Cargo.toml
@@ -7,5 +7,5 @@ rust-version = "1.61"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-phf = { version = "^0.11.2", features = ["macros", "uncased"] }
+phf = { version = "^0.12", features = ["macros", "uncased"] }
 uncased = "0.9.7"
diff --git a/phf/examples/unicase-example/Cargo.toml b/phf/examples/unicase-example/Cargo.toml
index b38b2c8..3165bf9 100644
--- a/phf/examples/unicase-example/Cargo.toml
+++ b/phf/examples/unicase-example/Cargo.toml
@@ -7,5 +7,5 @@ rust-version = "1.61"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-phf = { version = "^0.11.2", features = ["macros", "unicase"] }
+phf = { version = "^0.12", features = ["macros", "unicase"] }
 unicase = "2"
diff --git a/phf_codegen/Cargo.toml b/phf_codegen/Cargo.toml
index 9294848..781c530 100644
--- a/phf_codegen/Cargo.toml
+++ b/phf_codegen/Cargo.toml
@@ -11,5 +11,5 @@ rust-version = "1.61"
 categories = ["data-structures"]
 
 [dependencies]
-phf_generator = "0.11.0"
-phf_shared = "0.11.0"
+phf_generator = "0.12.0"
+phf_shared = "0.12.0"
diff --git a/phf_generator/Cargo.toml b/phf_generator/Cargo.toml
index 69deed2..5dbb366 100644
--- a/phf_generator/Cargo.toml
+++ b/phf_generator/Cargo.toml
@@ -12,7 +12,7 @@ readme = "README.md"
 
 [dependencies]
 fastrand = { version = "2.1.0", default-features = false }
-phf_shared = { version = "^0.11.2", default-features = false }
+phf_shared = { version = "^0.12", default-features = false }
 # for stable black_box()
 criterion = { version = "0.3.6", optional = true }
 
diff --git a/phf_macros/Cargo.toml b/phf_macros/Cargo.toml
index 9a4279f..3415b53 100644
--- a/phf_macros/Cargo.toml
+++ b/phf_macros/Cargo.toml
@@ -24,5 +24,5 @@ proc-macro2 = "1"
 unicase_ = { package = "unicase", version = "2.4.0", optional = true }
 uncased_ = { package = "uncased", version = "0.9.7", optional = true }
 
-phf_generator = "0.11.1"
-phf_shared = { version = "^0.11.2", default-features = false }
+phf_generator = "0.12"
+phf_shared = { version = "^0.12", default-features = false }


Test patch:
diff --git a/phf_codegen/test/Cargo.toml b/phf_codegen/test/Cargo.toml
index bb524c8..86bf9dd 100644
--- a/phf_codegen/test/Cargo.toml
+++ b/phf_codegen/test/Cargo.toml
@@ -6,7 +6,7 @@ build = "build.rs"
 edition = "2021"
 
 [dependencies]
-phf = { version = "^0.11.2", features = ["uncased", "unicase"] }
+phf = { version = "^0.12", features = ["uncased", "unicase"] }
 uncased = { version = "0.9.7", default-features = false }
 unicase = "2.4.0"