We compute the supersymmetric partition function of $mathcal{N}{=}1$ supersymmetric gauge theories with an $R$-symmetry on $mathcal{M}_4 cong mathcal{M}_{g,p}times S^1$, a principal elliptic fiber bundle of degree $p$ over a genus-$g$ Riemann surface, $Sigma_g$. Equivalently, we compute the generalized supersymmetric index $I_{mathcal{M}_{g,p}}$, with the supersymmetric three-manifold ${mathcal{M}_{g,p}}$ as the spatial slice. The ordinary $mathcal{N}{=}1$ supersymmetric index on the round three-sphere is recovered as a special case. We approach this computation from the point of view of a topological $A$-model for the abelianized gauge fields on the base $Sigma_g$. This $A$-model---or $A$-twisted two-dimensional $mathcal{N}{=}(2,2)$ gauge theory---encodes all the information about the generalized indices, which are viewed as expectations values of some canonically-defined surface defects wrapped on $T^2$ inside $Sigma_g times T^2$. Being defined by compactification on the torus, the $A$-model also enjoys natural modular properties, governed by the four-dimensional t Hooft anomalies. As an application of our results, we provide new tests of Seiberg duality. We also present a new evaluation formula for the three-sphere index as a sum over two-dimensional vacua.